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();
}
}
}
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]));
}
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();
}
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;
}
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);
}
}
Aggregations