public static boolean hasTag(OsmEntity entity, String key, String value) { for (int i = 0; i < entity.getNumberOfTags(); i++) { OsmTag tag = entity.getTag(i); if (tag.getKey().equals(key) && tag.getValue().equals(value)) { return true; } } return false; }
@Override public void handle(OsmWay way) { this.entities.add(new EntityContainer(EntityType.Way, way)); }
private boolean isWayInBounds(OsmWay way, double minLatitude, double minLongitude, double maxLatitude, double maxLongitude) { double wayMinLatitude = Double.MAX_VALUE; double wayMinLongitude = Double.MAX_VALUE; double wayMaxLatitude = -Double.MAX_VALUE; double wayMaxLongitude = -Double.MAX_VALUE; for (int i = 0; i < way.getNumberOfNodes(); i++) { try { OsmNode node = this.getNode(way.getNodeId(i)); double latitude = node.getLatitude(); if (latitude < wayMinLatitude) { wayMinLatitude = latitude; } if (latitude > wayMaxLatitude) { wayMaxLatitude = latitude; } double longitude = node.getLongitude(); if (longitude < wayMinLongitude) { wayMinLongitude = longitude; } if (longitude > wayMaxLongitude) { wayMaxLongitude = longitude; } } catch (EntityNotFoundException e) { } } return minLatitude < wayMaxLatitude && maxLatitude > wayMinLatitude && minLongitude < wayMaxLongitude && maxLongitude > wayMinLongitude; } }
writer.addUserMetadata("bounds", ByteBuffer.wrap((bounds.getLeft() + ", " + bounds.getBottom() + ", " + bounds.getRight() + ", " + bounds.getTop()).getBytes())); OsmEntity entity = container.getEntity(); OsmMetadata metadata = entity.getMetadata(); id.vector[row] = entity.getId(); changeset.vector[row] = metadata.getChangeset(); tags.lengths[row] = entity.getNumberOfTags(); // number of key/value pairings tags.childCount += tags.lengths[row]; tags.keys.ensureSize(tags.childCount, tags.offsets[row] != 0); timestamp.time[row] = metadata.getTimestamp(); timestamp.nanos[row] = 0; uid.vector[row] = metadata.getUid(); byte[] userBytes = metadata.getUser().getBytes(); user.setRef(row, userBytes, 0, userBytes.length); version.vector[row] = metadata.getVersion(); if (!metadata.isVisible()) { visible.vector[row] = 0; } else { switch (container.getType()) { default: break;
public static List<Point> createPoints(OsmEntityProvider data, OsmWay way) { List<Point> points = new ArrayList<>(); try { for (int i = 0; i < way.getNumberOfNodes(); i++) { points.add(NODE_BUILDER.build(data.getNode(way.getNodeId(i)))); } } catch (EntityNotFoundException e) { Terrarium.LOGGER.warn("Unable to find node", e); } return points; } }
private void persistEntity(OsmEntity entity, Geometry geometry, Map<String, String> tags) { log.warn("Could not build {}: {} (geometry not valid or empty): {}", entity.getClass(), entity.getId(), geometry); return; if (chosenGeo.isEmpty()) { log.warn("Could not build {}: {} (geometry collection contains only empty geometries): {}", entity.getClass(), entity.getId(), geometry); return; "osm" + entity.getId(), tags.get("name"), geometry
@Override public void handle(OsmNode node) throws IOException { // We are not interested in the node tags, but just the coordinates to create a geometry for the ways nodes.put(node.getId(), node); handleEntity(node, builder.build(node)); }
@Override public void handle(OsmWay way) throws IOException { Geometry osmGeometry = null; try { osmGeometry = builder.build(way, dataSet); if (osmGeometry instanceof LinearRing) { osmGeometry = new Polygon((LinearRing) osmGeometry, null, GEOMETRY_FACTORY); } } catch (IllegalArgumentException e) { log.warn("Could not build way (illegal argument): {}", e.getMessage()); } catch (EntityNotFoundException e) { // Nothing to do, continue... log.warn("Could not build way (entity not found): {}", e.getMessage()); } ways.put(way.getId(), way); handleEntity(way, osmGeometry); }
@Override public void handle(OsmRelation relation) { this.entities.add(new EntityContainer(EntityType.Relation, relation)); }
@Override public void handle(OsmNode node) { this.entities.add(new EntityContainer(EntityType.Node, node)); }