Search in sources :

Example 1 with WayNode

use of org.openstreetmap.osmosis.core.domain.v0_6.WayNode in project voltdb by VoltDB.

the class VoltDBOsmSink method process.

public void process(WayContainer wayContainer) {
    Way way;
    List<Long> nodeIds;
    way = wayContainer.getEntity();
    nodeIds = new ArrayList<Long>(way.getWayNodes().size());
    for (WayNode wayNode : way.getWayNodes()) {
        nodeIds.add(wayNode.getNodeId());
    }
    // Keep invalid ways out of the database if desired by the user
    if (way.getWayNodes().size() > 1 || keepInvalidWays) {
        for (Tag tag : way.getTags()) {
            try {
                client.callProcedure(new InsertCallback(), INS_WAY_TAGS_PROC, way.getId(), tag.getKey(), tag.getValue());
            } catch (NoConnectionsException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // Add these to the ways_nodes_table;
        int sequence = 0;
        for (Long nodeId : nodeIds) {
            try {
                client.callProcedure(new InsertCallback(), INS_WAYS_NODES_PROC, way.getId(), nodeId, sequence);
            } catch (NoConnectionsException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            sequence++;
        }
        StringBuffer sb = new StringBuffer();
        // if the first node id == the last nodeId, we know that this is a
        // closed loop.
        long n0 = nodeIds.get(0);
        long nn = nodeIds.get(nodeIds.size() - 1);
        if (n0 == nn) {
            if (enableBboxBuilder) {
                Polygon pg = wayGeometryBuilder.createPolygon(way);
                pg.outerWKT(sb);
            }
        } else {
            // it's a lineString, but we don't support it yet.
            if (enableLinestringBuilder) {
                LineString lineString = wayGeometryBuilder.createWayLinestring(way);
                lineString.outerWKT(sb);
            } else {
                return;
            }
        }
        String bbox = sb.toString();
        try {
            client.callProcedure(new InsertCallback(), INS_WAYS_PROC, way.getId(), way.getVersion(), way.getUser().getId(), way.getTimestamp(), way.getChangesetId(), bbox);
        } catch (NoConnectionsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) IOException(java.io.IOException) LineString(org.postgis.LineString) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) NoConnectionsException(org.voltdb.client.NoConnectionsException) LineString(org.postgis.LineString) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Polygon(org.postgis.Polygon)

Example 2 with WayNode

use of org.openstreetmap.osmosis.core.domain.v0_6.WayNode in project voltdb by VoltDB.

the class WayPolygonGeometryBuilder method createRing.

public LinearRing createRing(Way way) {
    List<Point> points = new ArrayList<Point>();
    for (WayNode wayNode : way.getWayNodes()) {
        NodeLocation nodeLocation;
        double longitude;
        double latitude;
        nodeLocation = locationStore.getNodeLocation(wayNode.getNodeId());
        longitude = nodeLocation.getLongitude();
        latitude = nodeLocation.getLatitude();
        if (nodeLocation.isValid()) {
            Point point = new Point(longitude, latitude);
            points.add(point);
        }
    }
    return new LinearRing(points.toArray(new Point[0]));
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) NodeLocation(org.openstreetmap.osmosis.pgsimple.common.NodeLocation) ArrayList(java.util.ArrayList) Point(org.postgis.Point) LinearRing(org.postgis.LinearRing)

Example 3 with WayNode

use of org.openstreetmap.osmosis.core.domain.v0_6.WayNode in project GeoGig by boundlessgeo.

the class EntityConverter method buildNodesString.

protected String buildNodesString(List<WayNode> wayNodes) {
    StringBuilder sb = new StringBuilder();
    for (Iterator<WayNode> it = wayNodes.iterator(); it.hasNext(); ) {
        WayNode node = it.next();
        sb.append(Long.toString(node.getNodeId()));
        if (it.hasNext()) {
            sb.append(";");
        }
    }
    return sb.toString();
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode)

Example 4 with WayNode

use of org.openstreetmap.osmosis.core.domain.v0_6.WayNode in project GeoGig by boundlessgeo.

the class EntityConverter method toEntity.

/**
     * Converts a Feature to a OSM Entity
     * 
     * @param feature the feature to convert
     * @param replaceId. The changesetId to use in case the feature has a negative one indicating a
     *        temporary value
     * @return
     */
public Entity toEntity(SimpleFeature feature, Long changesetId) {
    Entity entity;
    SimpleFeatureType type = feature.getFeatureType();
    long id = Long.parseLong(feature.getID());
    int version = ((Integer) feature.getAttribute("version")).intValue();
    Long changeset = (Long) feature.getAttribute("changeset");
    if (changesetId != null && changeset < 0) {
        changeset = changesetId;
    }
    Long milis = (Long) feature.getAttribute("timestamp");
    Date timestamp = new Date(milis);
    String user = (String) feature.getAttribute("user");
    String[] userTokens = user.split(":");
    OsmUser osmuser;
    try {
        osmuser = new OsmUser(Integer.parseInt(userTokens[1]), userTokens[0]);
    } catch (Exception e) {
        osmuser = OsmUser.NONE;
    }
    String tagsString = (String) feature.getAttribute("tags");
    Collection<Tag> tags = OSMUtils.buildTagsCollectionFromString(tagsString);
    CommonEntityData entityData = new CommonEntityData(id, version, timestamp, osmuser, changeset, tags);
    if (type.equals(OSMUtils.nodeType())) {
        Point pt = (Point) feature.getDefaultGeometryProperty().getValue();
        entity = new Node(entityData, pt.getY(), pt.getX());
    } else {
        List<WayNode> nodes = Lists.newArrayList();
        String nodesString = (String) feature.getAttribute("nodes");
        for (String s : nodesString.split(";")) {
            nodes.add(new WayNode(Long.parseLong(s)));
        }
        entity = new Way(entityData, nodes);
    }
    return entity;
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) CommonEntityData(org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) OsmUser(org.openstreetmap.osmosis.core.domain.v0_6.OsmUser) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 5 with WayNode

use of org.openstreetmap.osmosis.core.domain.v0_6.WayNode in project bboxdb by jnidzwetzki.

the class OSMDataConverter method handleWay.

/**
 * Handle a way
 * @param entityContainer
 */
protected void handleWay(final Way way) {
    try {
        for (final OSMType osmType : filter.keySet()) {
            final OSMTagEntityFilter entityFilter = filter.get(osmType);
            if (entityFilter.match(way.getTags())) {
                final Polygon geometricalStructure = new Polygon(way.getId());
                for (final Tag tag : way.getTags()) {
                    geometricalStructure.addProperty(tag.getKey(), tag.getValue());
                }
                // Perform search async
                for (final WayNode wayNode : way.getWayNodes()) {
                    final SerializableNode node = osmNodeStore.getNodeForId(wayNode.getNodeId());
                    geometricalStructure.addPoint(node.getLatitude(), node.getLongitude());
                }
                writePolygonToOutput(osmType, geometricalStructure);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OSMTagEntityFilter(org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) SerializableNode(org.bboxdb.tools.converter.osm.util.SerializableNode) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) Polygon(org.bboxdb.tools.converter.osm.util.Polygon) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)5 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)3 IOException (java.io.IOException)2 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)2 Point (com.vividsolutions.jts.geom.Point)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ParseException (org.apache.commons.cli.ParseException)1 OSMTagEntityFilter (org.bboxdb.tools.converter.osm.filter.OSMTagEntityFilter)1 Polygon (org.bboxdb.tools.converter.osm.util.Polygon)1 SerializableNode (org.bboxdb.tools.converter.osm.util.SerializableNode)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)1 Entity (org.openstreetmap.osmosis.core.domain.v0_6.Entity)1 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)1 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)1 NodeLocation (org.openstreetmap.osmosis.pgsimple.common.NodeLocation)1 LineString (org.postgis.LineString)1 LinearRing (org.postgis.LinearRing)1 Point (org.postgis.Point)1