diff --git a/src/main/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessor.java b/src/main/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessor.java index 955d6cc643..fe88710a46 100644 --- a/src/main/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessor.java +++ b/src/main/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessor.java @@ -729,17 +729,17 @@ private void keepOutsideWaysThatAreConnected() this.nodeIdentifiersAtNetworkBoundary.remove(new Long(identifier)); for (final WayNode subWayNode : wayNodes) { - this.store.addNodeInEdge(subWayNode.getNodeId()); - if (!this.store.containsNode(subWayNode.getNodeId())) + final long subWayNodeIdentifier = subWayNode.getNodeId(); + this.store.addNodeInEdge(subWayNodeIdentifier); + if (!this.store.containsNode(subWayNodeIdentifier)) { - final long subWayNodeIdentifier = subWayNode.getNodeId(); if (subWayNodeIdentifier != identifier) { // The node is a new node outside of the network this.nodeIdentifiersAtNetworkBoundary .add(subWayNodeIdentifier); } - this.nodesOutsideOfPolygon.add(subWayNode.getNodeId()); + this.nodesOutsideOfPolygon.add(subWayNodeIdentifier); } } break; diff --git a/src/test/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessorTest.java b/src/test/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessorTest.java index b1129c3d6e..3817dc2078 100644 --- a/src/test/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessorTest.java +++ b/src/test/java/org/openstreetmap/atlas/geography/atlas/pbf/OsmPbfProcessorTest.java @@ -17,12 +17,48 @@ import org.slf4j.LoggerFactory; /** + * {@link OsmPbfProcessor} tests + * * @author matthieun + * @author mgostintsev */ public class OsmPbfProcessorTest { private static final Logger logger = LoggerFactory.getLogger(OsmPbfProcessorTest.class); + @Test + public void testBringInConnectedBridgeNodesOutsideCountryBoundaries() + { + final Resource osmFromJosm = new InputStreamResource(() -> OsmPbfProcessorTest.class + .getResourceAsStream("outsideConnectedOneWayWays.osm")); + final WritableResource osmFile = new StringResource(); + final WritableResource pbfFile = new StringResource(); + final Resource boundaries = new InputStreamResource( + () -> OsmPbfProcessorTest.class.getResourceAsStream("DNK_SWE_boundary.txt")); + new OsmFileParser().update(osmFromJosm, osmFile); + new OsmFileToPbf().update(osmFile, pbfFile); + final CountryBoundaryMap countryBoundaryMap = CountryBoundaryMap.fromPlainText(boundaries); + final MultiPolygon boundary = countryBoundaryMap.countryBoundary("DNK").get(0) + .getBoundary(); + logger.debug("Boundary: {}", boundary.toWkt()); + final AtlasLoadingOption option = AtlasLoadingOption + .createOptionWithAllEnabled(countryBoundaryMap); + final OsmPbfLoader loader = new OsmPbfLoader(pbfFile, boundary, option); + final Atlas atlas = loader.read(); + logger.info("Atlas: {}", atlas.toString()); + + // Check top bridge node has proper tag + Assert.assertEquals(SyntheticNearestNeighborCountryCodeTag.YES.name(), + atlas.node(3089123457000000L).tag(SyntheticNearestNeighborCountryCodeTag.KEY)); + Assert.assertEquals(SyntheticBoundaryNodeTag.EXISTING.name().toLowerCase(), + atlas.node(3089123457000000L).tag(SyntheticBoundaryNodeTag.KEY)); + + // Check bottom bridge node has invalid tagging + Assert.assertEquals(SyntheticNearestNeighborCountryCodeTag.YES.name(), + atlas.node(3089123458000000L).tag(SyntheticNearestNeighborCountryCodeTag.KEY)); + Assert.assertNull(atlas.node(3089123458000000L).tag(SyntheticBoundaryNodeTag.KEY)); + } + @Test public void testKeepOutsideWaysThatAreConnected() { diff --git a/src/test/java/org/openstreetmap/atlas/geography/atlas/raw/RawAtlasTest.java b/src/test/java/org/openstreetmap/atlas/geography/atlas/raw/RawAtlasTest.java index 1b53a89412..e5d95513b3 100644 --- a/src/test/java/org/openstreetmap/atlas/geography/atlas/raw/RawAtlasTest.java +++ b/src/test/java/org/openstreetmap/atlas/geography/atlas/raw/RawAtlasTest.java @@ -12,6 +12,7 @@ import org.openstreetmap.atlas.streaming.resource.Resource; import org.openstreetmap.atlas.streaming.resource.StringResource; import org.openstreetmap.atlas.streaming.resource.WritableResource; +import org.openstreetmap.atlas.tags.SyntheticBoundaryNodeTag; import org.openstreetmap.atlas.tags.SyntheticNearestNeighborCountryCodeTag; import org.openstreetmap.atlas.utilities.testing.OsmFileParser; import org.openstreetmap.atlas.utilities.testing.OsmFileToPbf; @@ -20,6 +21,7 @@ /** * @author matthieun + * @author mgostintsev */ public class RawAtlasTest { @@ -81,4 +83,44 @@ public void testBringInConnectedOutsideWays() Assert.assertEquals(SyntheticNearestNeighborCountryCodeTag.YES.name(), slicedAtlas.point(39000000000L).tag(SyntheticNearestNeighborCountryCodeTag.KEY)); } + + @Test + public void testBringInConnectedBridgeNodesOutsideCountryBoundaries() + { + final Resource osmFromJosm = new InputStreamResource( + () -> RawAtlasTest.class.getResourceAsStream("outsideConnectedOneWayWays.osm")); + final WritableResource osmFile = new StringResource(); + final WritableResource pbfFile = new StringResource(); + final Resource boundaries = new InputStreamResource( + () -> RawAtlasTest.class.getResourceAsStream("DNK_SWE_boundary.txt")); + new OsmFileParser().update(osmFromJosm, osmFile); + new OsmFileToPbf().update(osmFile, pbfFile); + final CountryBoundaryMap countryBoundaryMap = CountryBoundaryMap.fromPlainText(boundaries); + final MultiPolygon boundary = countryBoundaryMap.countryBoundary("DNK").get(0) + .getBoundary(); + logger.debug("Boundary: {}", boundary.toWkt()); + final AtlasLoadingOption option = AtlasLoadingOption + .createOptionWithAllEnabled(countryBoundaryMap); + final RawAtlasGenerator generator = new RawAtlasGenerator(pbfFile, option, boundary); + final Atlas rawAtlas = generator.build(); + logger.debug("Raw Atlas: {}", rawAtlas); + + final Atlas slicedAtlas = new RawAtlasCountrySlicer("DNK", countryBoundaryMap) + .slice(rawAtlas); + logger.debug("Sliced Atlas: {}", slicedAtlas); + + // Check the top node 3089123457 has the proper tagging - nearest neighbor and on the + // boundary + Assert.assertEquals(SyntheticNearestNeighborCountryCodeTag.YES.name(), slicedAtlas + .point(3089123457000000L).tag(SyntheticNearestNeighborCountryCodeTag.KEY)); + Assert.assertEquals(SyntheticBoundaryNodeTag.EXISTING.name(), + slicedAtlas.point(3089123457000000L).tag(SyntheticBoundaryNodeTag.KEY)); + + // Check the bottom node 3089123458 has the proper tagging - nearest neighbor and on the + // boundary + Assert.assertEquals(SyntheticNearestNeighborCountryCodeTag.YES.name(), slicedAtlas + .point(3089123458000000L).tag(SyntheticNearestNeighborCountryCodeTag.KEY)); + Assert.assertEquals(SyntheticBoundaryNodeTag.EXISTING.name(), + slicedAtlas.point(3089123458000000L).tag(SyntheticBoundaryNodeTag.KEY)); + } } diff --git a/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/DNK_SWE_boundary.txt b/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/DNK_SWE_boundary.txt new file mode 100644 index 0000000000..a166560ea3 --- /dev/null +++ b/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/DNK_SWE_boundary.txt @@ -0,0 +1,2 @@ +DNK||MULTIPOLYGON (((12.76302329063 55.59512845369, 12.80636778831 55.59503145851, 12.80465117455 55.57373521447, 12.76122084618 55.57300734823, 12.76302329063 55.59512845369))) +SWE||MULTIPOLYGON (((12.81217998751 55.58015672226, 12.81184618447 55.57264298618, 12.82883979379 55.57243711016, 12.82844529928 55.58034540489, 12.81217998751 55.58015672226)))# diff --git a/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/outsideConnectedOneWayWays.osm b/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/outsideConnectedOneWayWays.osm new file mode 100644 index 0000000000..029cae13ba --- /dev/null +++ b/src/test/resources/org/openstreetmap/atlas/geography/atlas/pbf/outsideConnectedOneWayWays.osm @@ -0,0 +1,2731 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/DNK_SWE_boundary.txt b/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/DNK_SWE_boundary.txt new file mode 100644 index 0000000000..a166560ea3 --- /dev/null +++ b/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/DNK_SWE_boundary.txt @@ -0,0 +1,2 @@ +DNK||MULTIPOLYGON (((12.76302329063 55.59512845369, 12.80636778831 55.59503145851, 12.80465117455 55.57373521447, 12.76122084618 55.57300734823, 12.76302329063 55.59512845369))) +SWE||MULTIPOLYGON (((12.81217998751 55.58015672226, 12.81184618447 55.57264298618, 12.82883979379 55.57243711016, 12.82844529928 55.58034540489, 12.81217998751 55.58015672226)))# diff --git a/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/outsideConnectedOneWayWays.osm b/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/outsideConnectedOneWayWays.osm new file mode 100644 index 0000000000..029cae13ba --- /dev/null +++ b/src/test/resources/org/openstreetmap/atlas/geography/atlas/raw/outsideConnectedOneWayWays.osm @@ -0,0 +1,2731 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +