@Test public void testWayGetGeometryIncomplete() { OSMEntity entity = testData.ways().get(3L).get(0); OSHDBTimestamp timestamp = TimestampParser.toOSHDBTimestamp("2001-01-01"); TagInterpreter areaDecider = new FakeTagInterpreterAreaNever(); Geometry result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertEquals("LineString", result.getGeometryType()); assertEquals(2, result.getNumPoints()); entity = testData.ways().get(4L).get(0); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertEquals("Point", result.getGeometryType()); assertEquals(false, result.isEmpty()); entity = testData.ways().get(5L).get(0); result = OSHDBGeometryBuilder.getGeometry(entity, timestamp, areaDecider); assertEquals(true, result.isEmpty()); }
@Nonnull public static Geometry getGeometry( OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider ) { GeometryFactory geometryFactory = new GeometryFactory(); if (timestamp.compareTo(entity.getTimestamp()) < 0) { throw new AssertionError( "cannot produce geometry of entity for timestamp before this entity's version's timestamp" ); } if (entity instanceof OSMNode) { OSMNode node = (OSMNode) entity; if (node.isVisible()) { return geometryFactory.createPoint(new Coordinate(node.getLongitude(), node.getLatitude())); } else { return geometryFactory.createPoint((Coordinate) null); } } else if (entity instanceof OSMWay) { OSMWay way = (OSMWay) entity; if (!way.isVisible()) { LOG.info("way/{} is deleted - falling back to empty (line) geometry", way.getId()); return geometryFactory.createLineString((CoordinateSequence) null); } Coordinate[] coords = way.getRefEntities(timestamp) .filter(Objects::nonNull) .filter(OSMEntity::isVisible) .map(nd -> new Coordinate(nd.getLongitude(), nd.getLatitude())) .toArray(Coordinate[]::new); if (areaDecider.isArea(entity)) { if (coords.length >= 4 && coords[0].equals2D(coords[coords.length - 1])) { return geometryFactory.createPolygon(coords); } else { LOG.warn("way/{} doesn't form a linear ring - falling back to linestring", way.getId()); } } if (coords.length >= 2) { return geometryFactory.createLineString(coords); } if (coords.length == 1) { LOG.info("way/{} is single-noded - falling back to point geometry", way.getId()); return geometryFactory.createPoint(coords[0]); } else { LOG.warn("way/{} with no nodes - falling back to empty (point) geometry", way.getId()); return geometryFactory.createPoint((Coordinate) null); } } else { OSMRelation relation = (OSMRelation) entity; if (!relation.isVisible()) { LOG.info( "relation/{} is deleted - falling back to empty geometry (collection)", relation.getId() ); return geometryFactory.createGeometryCollection(null); } if (areaDecider.isArea(entity)) { try { Geometry multipolygon = OSHDBGeometryBuilder.getMultiPolygonGeometry( relation, timestamp, areaDecider, geometryFactory ); if (!multipolygon.isEmpty()) { return multipolygon; } } catch (IllegalArgumentException e) { } } return getGeometryCollectionGeometry(relation, timestamp, areaDecider, geometryFactory); } }
OSHDBGeometryBuilder { @Nonnull public static Geometry getGeometry( OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider ) { GeometryFactory geometryFactory = new GeometryFactory(); if (timestamp.compareTo(entity.getTimestamp()) < 0) { throw new AssertionError( "cannot produce geometry of entity for timestamp before this entity's version's timestamp" ); } if (entity instanceof OSMNode) { OSMNode node = (OSMNode) entity; if (node.isVisible()) { return geometryFactory.createPoint(new Coordinate(node.getLongitude(), node.getLatitude())); } else { return geometryFactory.createPoint((Coordinate) null); } } else if (entity instanceof OSMWay) { OSMWay way = (OSMWay) entity; if (!way.isVisible()) { LOG.info("way/{} is deleted - falling back to empty (line) geometry", way.getId()); return geometryFactory.createLineString((CoordinateSequence) null); } Coordinate[] coords = way.getRefEntities(timestamp) .filter(Objects::nonNull) .filter(OSMEntity::isVisible) .map(nd -> new Coordinate(nd.getLongitude(), nd.getLatitude())) .toArray(Coordinate[]::new); if (areaDecider.isArea(entity)) { if (coords.length >= 4 && coords[0].equals2D(coords[coords.length - 1])) { return geometryFactory.createPolygon(coords); } else { LOG.warn("way/{} doesn't form a linear ring - falling back to linestring", way.getId()); } } if (coords.length >= 2) { return geometryFactory.createLineString(coords); } if (coords.length == 1) { LOG.info("way/{} is single-noded - falling back to point geometry", way.getId()); return geometryFactory.createPoint(coords[0]); } else { LOG.warn("way/{} with no nodes - falling back to empty (point) geometry", way.getId()); return geometryFactory.createPoint((Coordinate) null); } } else { OSMRelation relation = (OSMRelation) entity; if (!relation.isVisible()) { LOG.info( "relation/{} is deleted - falling back to empty geometry (collection)", relation.getId() ); return geometryFactory.createGeometryCollection(null); } if (areaDecider.isArea(entity)) { try { Geometry multipolygon = OSHDBGeometryBuilder.getMultiPolygonGeometry( relation, timestamp, areaDecider, geometryFactory ); if (!multipolygon.isEmpty()) { return multipolygon; } } catch (IllegalArgumentException e) { } } return getGeometryCollectionGeometry(relation, timestamp, areaDecider, geometryFactory); } } }
OSHDBGeometryBuilder { @Nonnull public static Geometry getGeometry( OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider ) { GeometryFactory geometryFactory = new GeometryFactory(); if (timestamp.compareTo(entity.getTimestamp()) < 0) { throw new AssertionError( "cannot produce geometry of entity for timestamp before this entity's version's timestamp" ); } if (entity instanceof OSMNode) { OSMNode node = (OSMNode) entity; if (node.isVisible()) { return geometryFactory.createPoint(new Coordinate(node.getLongitude(), node.getLatitude())); } else { return geometryFactory.createPoint((Coordinate) null); } } else if (entity instanceof OSMWay) { OSMWay way = (OSMWay) entity; if (!way.isVisible()) { LOG.info("way/{} is deleted - falling back to empty (line) geometry", way.getId()); return geometryFactory.createLineString((CoordinateSequence) null); } Coordinate[] coords = way.getRefEntities(timestamp) .filter(Objects::nonNull) .filter(OSMEntity::isVisible) .map(nd -> new Coordinate(nd.getLongitude(), nd.getLatitude())) .toArray(Coordinate[]::new); if (areaDecider.isArea(entity)) { if (coords.length >= 4 && coords[0].equals2D(coords[coords.length - 1])) { return geometryFactory.createPolygon(coords); } else { LOG.warn("way/{} doesn't form a linear ring - falling back to linestring", way.getId()); } } if (coords.length >= 2) { return geometryFactory.createLineString(coords); } if (coords.length == 1) { LOG.info("way/{} is single-noded - falling back to point geometry", way.getId()); return geometryFactory.createPoint(coords[0]); } else { LOG.warn("way/{} with no nodes - falling back to empty (point) geometry", way.getId()); return geometryFactory.createPoint((Coordinate) null); } } else { OSMRelation relation = (OSMRelation) entity; if (!relation.isVisible()) { LOG.info( "relation/{} is deleted - falling back to empty geometry (collection)", relation.getId() ); return geometryFactory.createGeometryCollection(null); } if (areaDecider.isArea(entity)) { try { Geometry multipolygon = OSHDBGeometryBuilder.getMultiPolygonGeometry( relation, timestamp, areaDecider, geometryFactory ); if (!multipolygon.isEmpty()) { return multipolygon; } } catch (IllegalArgumentException e) { } } return getGeometryCollectionGeometry(relation, timestamp, areaDecider, geometryFactory); } }  }
OSHDBGeometryBuilder { @Nonnull public static Geometry getGeometry( OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider ) { GeometryFactory geometryFactory = new GeometryFactory(); if (timestamp.compareTo(entity.getTimestamp()) < 0) { throw new AssertionError( "cannot produce geometry of entity for timestamp before this entity's version's timestamp" ); } if (entity instanceof OSMNode) { OSMNode node = (OSMNode) entity; if (node.isVisible()) { return geometryFactory.createPoint(new Coordinate(node.getLongitude(), node.getLatitude())); } else { return geometryFactory.createPoint((Coordinate) null); } } else if (entity instanceof OSMWay) { OSMWay way = (OSMWay) entity; if (!way.isVisible()) { LOG.info("way/{} is deleted - falling back to empty (line) geometry", way.getId()); return geometryFactory.createLineString((CoordinateSequence) null); } Coordinate[] coords = way.getRefEntities(timestamp) .filter(Objects::nonNull) .filter(OSMEntity::isVisible) .map(nd -> new Coordinate(nd.getLongitude(), nd.getLatitude())) .toArray(Coordinate[]::new); if (areaDecider.isArea(entity)) { if (coords.length >= 4 && coords[0].equals2D(coords[coords.length - 1])) { return geometryFactory.createPolygon(coords); } else { LOG.warn("way/{} doesn't form a linear ring - falling back to linestring", way.getId()); } } if (coords.length >= 2) { return geometryFactory.createLineString(coords); } if (coords.length == 1) { LOG.info("way/{} is single-noded - falling back to point geometry", way.getId()); return geometryFactory.createPoint(coords[0]); } else { LOG.warn("way/{} with no nodes - falling back to empty (point) geometry", way.getId()); return geometryFactory.createPoint((Coordinate) null); } } else { OSMRelation relation = (OSMRelation) entity; if (!relation.isVisible()) { LOG.info( "relation/{} is deleted - falling back to empty geometry (collection)", relation.getId() ); return geometryFactory.createGeometryCollection(null); } if (areaDecider.isArea(entity)) { try { Geometry multipolygon = OSHDBGeometryBuilder.getMultiPolygonGeometry( relation, timestamp, areaDecider, geometryFactory ); if (!multipolygon.isEmpty()) { return multipolygon; } } catch (IllegalArgumentException e) { } } return getGeometryCollectionGeometry(relation, timestamp, areaDecider, geometryFactory); } }  @Nonnull static Geometry getGeometry(
      OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider
  ); static Geometry getGeometryClipped(T entity, OSHDBTimestamp timestamp,
      TagInterpreter areaDecider, OSHDBBoundingBox clipBbox); static Geometry getGeometryClipped(
      T entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider, P clipPoly); static Polygon getGeometry(OSHDBBoundingBox bbox); static OSHDBBoundingBox boundingBoxOf(Envelope envelope); }
OSHDBGeometryBuilder { @Nonnull public static Geometry getGeometry( OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider ) { GeometryFactory geometryFactory = new GeometryFactory(); if (timestamp.compareTo(entity.getTimestamp()) < 0) { throw new AssertionError( "cannot produce geometry of entity for timestamp before this entity's version's timestamp" ); } if (entity instanceof OSMNode) { OSMNode node = (OSMNode) entity; if (node.isVisible()) { return geometryFactory.createPoint(new Coordinate(node.getLongitude(), node.getLatitude())); } else { return geometryFactory.createPoint((Coordinate) null); } } else if (entity instanceof OSMWay) { OSMWay way = (OSMWay) entity; if (!way.isVisible()) { LOG.info("way/{} is deleted - falling back to empty (line) geometry", way.getId()); return geometryFactory.createLineString((CoordinateSequence) null); } Coordinate[] coords = way.getRefEntities(timestamp) .filter(Objects::nonNull) .filter(OSMEntity::isVisible) .map(nd -> new Coordinate(nd.getLongitude(), nd.getLatitude())) .toArray(Coordinate[]::new); if (areaDecider.isArea(entity)) { if (coords.length >= 4 && coords[0].equals2D(coords[coords.length - 1])) { return geometryFactory.createPolygon(coords); } else { LOG.warn("way/{} doesn't form a linear ring - falling back to linestring", way.getId()); } } if (coords.length >= 2) { return geometryFactory.createLineString(coords); } if (coords.length == 1) { LOG.info("way/{} is single-noded - falling back to point geometry", way.getId()); return geometryFactory.createPoint(coords[0]); } else { LOG.warn("way/{} with no nodes - falling back to empty (point) geometry", way.getId()); return geometryFactory.createPoint((Coordinate) null); } } else { OSMRelation relation = (OSMRelation) entity; if (!relation.isVisible()) { LOG.info( "relation/{} is deleted - falling back to empty geometry (collection)", relation.getId() ); return geometryFactory.createGeometryCollection(null); } if (areaDecider.isArea(entity)) { try { Geometry multipolygon = OSHDBGeometryBuilder.getMultiPolygonGeometry( relation, timestamp, areaDecider, geometryFactory ); if (!multipolygon.isEmpty()) { return multipolygon; } } catch (IllegalArgumentException e) { } } return getGeometryCollectionGeometry(relation, timestamp, areaDecider, geometryFactory); } }  @Nonnull static Geometry getGeometry(
      OSMEntity entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider
  ); static Geometry getGeometryClipped(T entity, OSHDBTimestamp timestamp,
      TagInterpreter areaDecider, OSHDBBoundingBox clipBbox); static Geometry getGeometryClipped(
      T entity, OSHDBTimestamp timestamp, TagInterpreter areaDecider, P clipPoly); static Polygon getGeometry(OSHDBBoundingBox bbox); static OSHDBBoundingBox boundingBoxOf(Envelope envelope);  }