Skip to content

Commit

Permalink
Synthetic Boundary Node Tagging (#201)
Browse files Browse the repository at this point in the history
* Adding Ice Road Tag

* Adding public access tag value

* Reproducing the issue in old and new flow

* Adding boundary files for tests

* Renaming method to stay consistent

* Removing relations, they're not needed for the point of the test

* Updating tests, relations do matter, minor simplification in code
  • Loading branch information
MikeGost authored and matthieun committed Aug 22, 2018
1 parent f525c07 commit 6974d9f
Show file tree
Hide file tree
Showing 7 changed files with 5,548 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@

/**
* @author matthieun
* @author mgostintsev
*/
public class RawAtlasTest
{
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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)))#
Loading

0 comments on commit 6974d9f

Please sign in to comment.