Skip to content

Commit

Permalink
Merge pull request osmlab#107 from maps-osm/dev-merge-2
Browse files Browse the repository at this point in the history
Merge Public Changes
  • Loading branch information
Lucas Cram authored and GitHub Enterprise committed Oct 3, 2018
2 parents 2a0d542 + 866550a commit 9b6c66f
Show file tree
Hide file tree
Showing 30 changed files with 958 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,45 +64,6 @@ public class RawAtlasIntegrationTest
@Rule
public DynamicRawAtlasSectioningTestRule setup = new DynamicRawAtlasSectioningTestRule();

@Test
public void testOverlappingNodesWithUniqueLayerTags()
{
// Based on https://www.openstreetmap.org/way/467880095 and
// https://www.openstreetmap.org/way/28247094 having two different layer tag values and
// having overlapping nodes (https://www.openstreetmap.org/node/4661272336 and
// https://www.openstreetmap.org/node/5501637097) that should not be merged.
final Location overlappingLocation = Location.forString("1.3248985,103.6452864");
final String path = RawAtlasIntegrationTest.class.getResource("layerTagTestCase.pbf")
.getPath();
final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path));
final Atlas rawAtlas = rawAtlasGenerator.build();

// Verify both points made it into the raw atlas
Assert.assertTrue(Iterables.size(rawAtlas.pointsAt(overlappingLocation)) == 2);

// Prepare the country and boundary
final Set<String> singaporeCountry = new HashSet<>();
singaporeCountry.add("SGP");
final CountryBoundaryMap boundaryMap = CountryBoundaryMap
.fromPlainText(new InputStreamResource(() -> RawAtlasIntegrationTest.class
.getResourceAsStream("testNodesWithDifferentLayerTagsBoundaryMap.txt")));

final Atlas slicedRawAtlas = new RawAtlasCountrySlicer(singaporeCountry, boundaryMap)
.slice(rawAtlas);
final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas,
AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();

// Make sure there is no sectioning happening between the two ways with different layer tag
// values. There is a one-way overpass and a bi-directional residential street, resulting in
// 3 total edges and 4 nodes (one on both ends of the two segments)
Assert.assertEquals(3, finalAtlas.numberOfEdges());
Assert.assertEquals(4, finalAtlas.numberOfNodes());

// Again, verify there is no node at the duplicated location
Assert.assertTrue(Iterables.size(finalAtlas.nodesAt(overlappingLocation)) == 0);
Assert.assertEquals(0, finalAtlas.numberOfPoints());
}

@Test
public void testPbfToSlicedAtlasWithExpansion()
{
Expand Down Expand Up @@ -340,6 +301,130 @@ public void testStandAloneNodeIngest()
Assert.assertEquals(0, finalAtlas.numberOfRelations());
}

@Test
public void testTwoWaysWithDifferentLayersIntersectingAtEnd()
{
// Based on https://www.openstreetmap.org/way/26071941 and
// https://www.openstreetmap.org/way/405246856 having two different layer tag values and
// having a shared node (https://www.openstreetmap.org/node/281526976) at which one of the
// ways ends. This is a fairly common OSM use-case, where two roads (often ramps or links)
// having different layer tags should be connected.
final Location intersection = Location.forString("55.0480165, 82.9406646");
final String path = RawAtlasIntegrationTest.class
.getResource("twoWaysWithDifferentLayersIntersectingAtEnd.pbf").getPath();
final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path));
final Atlas rawAtlas = rawAtlasGenerator.build();

// Prepare the country and boundary
final Set<String> countries = new HashSet<>();
countries.add("RUS");
final CountryBoundaryMap boundaryMap = CountryBoundaryMap
.fromPlainText(new InputStreamResource(() -> RawAtlasIntegrationTest.class
.getResourceAsStream("layerIntersectionAtEndBoundaryMap.txt")));

final Atlas slicedRawAtlas = new RawAtlasCountrySlicer(countries, boundaryMap)
.slice(rawAtlas);
final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas,
AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();

// Make sure there are exactly three edges created. Both ways are one-way and one of them
// gets way-sectioned into two edges.
Assert.assertEquals(3, finalAtlas.numberOfEdges());

// Make sure there are exactly 4 nodes
Assert.assertEquals(4, finalAtlas.numberOfNodes());

// Explicitly check for a single node at the intersection location
Assert.assertEquals(1, Iterables.size(finalAtlas.nodesAt(intersection)));

// Explicitly check that the layer=0 link is connected to both the layer=-1 trunk edges
Assert.assertEquals(2, finalAtlas.edge(26071941000000L).connectedEdges().size());
}

@Test
public void testTwoWaysWithDifferentLayersIntersectingAtStart()
{
// Based on https://www.openstreetmap.org/way/551411163 and partial piece of
// https://www.openstreetmap.org/way/67803311 having two different layer tag values and
// having a shared node (https://www.openstreetmap.org/node/5325270497) at which one of the
// ways ends. This is a fairly common OSM use-case, where two roads (often ramps or links)
// having different layer tags should be connected. In this case, we also check that the
// trunk link is connected to the trunk at both the start and end nodes.
final Location intersection = Location.forString("52.4819691, 38.7603042");
final String path = RawAtlasIntegrationTest.class
.getResource("twoWaysWithDifferentLayersIntersectingAtStart.pbf").getPath();
final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path));
final Atlas rawAtlas = rawAtlasGenerator.build();

// Prepare the country and boundary
final Set<String> countries = new HashSet<>();
countries.add("RUS");
final CountryBoundaryMap boundaryMap = CountryBoundaryMap
.fromPlainText(new InputStreamResource(() -> RawAtlasIntegrationTest.class
.getResourceAsStream("layerIntersectionAtStartBoundaryMap.txt")));

final Atlas slicedRawAtlas = new RawAtlasCountrySlicer(countries, boundaryMap)
.slice(rawAtlas);
final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas,
AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();

// Make sure there are exactly six edges created. The trunk link (551411163) is
// way-sectioned into 2 pieces - at an intermediate crossing, while the trunk (67803311) is
// sectioned into 4 pieces - once at the start of the link, once at an intermediate crossing
// and again at the end of the link.
Assert.assertEquals(6, finalAtlas.numberOfEdges());

// Make sure there are exactly 6 nodes
Assert.assertEquals(6, finalAtlas.numberOfNodes());

// Explicitly check for a single node at the intersection location
Assert.assertEquals(1, Iterables.size(finalAtlas.nodesAt(intersection)));

// Explicitly check that the layer=0 link is connected to both the layer=1 trunk edges and
// its own sectioned edge
Assert.assertEquals(3, finalAtlas.edge(551411163000001L).connectedEdges().size());
Assert.assertEquals(3, finalAtlas.edge(551411163000002L).connectedEdges().size());
}

@Test
public void testTwoWaysWithDifferentLayersIntersectingInMiddle()
{
// Based on https://www.openstreetmap.org/way/467880095 and
// https://www.openstreetmap.org/way/28247094 having two different layer tag values and
// having overlapping nodes (https://www.openstreetmap.org/node/4661272336 and
// https://www.openstreetmap.org/node/5501637097) that should not be merged.
final Location overlappingLocation = Location.forString("1.3248985,103.6452864");
final String path = RawAtlasIntegrationTest.class
.getResource("twoWaysWithDifferentLayersIntersectingInMiddle.pbf").getPath();
final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path));
final Atlas rawAtlas = rawAtlasGenerator.build();

// Verify both points made it into the raw atlas
Assert.assertTrue(Iterables.size(rawAtlas.pointsAt(overlappingLocation)) == 2);

// Prepare the country and boundary
final Set<String> singaporeCountry = new HashSet<>();
singaporeCountry.add("SGP");
final CountryBoundaryMap boundaryMap = CountryBoundaryMap
.fromPlainText(new InputStreamResource(() -> RawAtlasIntegrationTest.class
.getResourceAsStream("layerIntersectionInMiddleBoundaryMap.txt")));

final Atlas slicedRawAtlas = new RawAtlasCountrySlicer(singaporeCountry, boundaryMap)
.slice(rawAtlas);
final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas,
AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();

// Make sure there is no sectioning happening between the two ways with different layer tag
// values. There is a one-way overpass and a bi-directional residential street, resulting in
// 3 total edges and 4 nodes (one on both ends of the two segments)
Assert.assertEquals(3, finalAtlas.numberOfEdges());
Assert.assertEquals(4, finalAtlas.numberOfNodes());

// Again, verify there is no node at the duplicated location
Assert.assertTrue(Iterables.size(finalAtlas.nodesAt(overlappingLocation)) == 0);
Assert.assertEquals(0, finalAtlas.numberOfPoints());
}

private void assertAllEntitiesHaveCountryCode(final Atlas atlas)
{
atlas.lines().forEach(line ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUS||POLYGON((82.9358393 55.0504618, 82.9440158 55.0514274, 82.9463965 55.0445087, 82.9378292 55.0434533, 82.9358393 55.0504618))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUS||POLYGON((38.7492934 52.4698156, 38.7907408 52.4800608, 38.8020636 52.4476597, 38.7715000 52.4466020, 38.7492934 52.4698156))
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main/java/org/openstreetmap/atlas/geography/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public Location center()
*/
public Iterable<Location> closedLoop()
{
return new MultiIterable<>(this, Iterables.from(this.first()));
if (!this.first().equals(this.last()))
{
return new MultiIterable<>(this, Iterables.from(this.first()));
}
return this;
}

/**
Expand Down
Loading

0 comments on commit 9b6c66f

Please sign in to comment.