Skip to content

Commit

Permalink
Fix single nested relations issue in RawAtlasGenerator (#212)
Browse files Browse the repository at this point in the history
* Fix single nested relations issue

* added osm files
  • Loading branch information
matthieun authored and jwpgage committed Sep 4, 2018
1 parent cd8789e commit 351a9c6
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ private Atlas rebuildAtlas(final Atlas atlas, final Set<Long> pointsToRemove,
line -> rebuilder.addLine(line.getIdentifier(), line.asPolyLine(), line.getTags()));

// Add Relations
// Keep a set of all relations that have members that have been removed, so if that member
// is the only member, we do not add the parent relation either.
final Set<Long> relationsToCheckForRemoval = new HashSet<>();
atlas.relationsLowerOrderFirst().forEach(relation ->
{
final RelationBean bean = new RelationBean();
Expand All @@ -431,6 +434,14 @@ private Atlas rebuildAtlas(final Atlas atlas, final Set<Long> pointsToRemove,
"Excluding point {} from relation {} since point was removed from Atlas",
memberIdentifier, relation.getIdentifier());
}
else if (entity.getType() == ItemType.RELATION
&& relationsToCheckForRemoval.contains(memberIdentifier))
{
// Make sure not to add any removed relations
logger.debug(
"Excluding relation member {} from parent relation {} since that relation member became empty",
memberIdentifier, relation.getIdentifier());
}
else
{
bean.addItem(memberIdentifier, member.getRole(), entity.getType());
Expand All @@ -444,8 +455,9 @@ private Atlas rebuildAtlas(final Atlas atlas, final Set<Long> pointsToRemove,
}
else
{
logger.debug("Relation {} bean is empty, dropping from Atlas",
relation.getIdentifier());
final long relationIdentifier = relation.getIdentifier();
logger.debug("Relation {} bean is empty, dropping from Atlas", relationIdentifier);
relationsToCheckForRemoval.add(relationIdentifier);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openstreetmap.atlas.geography.atlas.pbf.OsmPbfLoader;
import org.openstreetmap.atlas.geography.atlas.pbf.OsmosisReaderMock;
import org.openstreetmap.atlas.streaming.resource.File;
import org.openstreetmap.atlas.streaming.resource.InputStreamResource;
import org.openstreetmap.atlas.tags.SyntheticDuplicateOsmNodeTag;
import org.openstreetmap.atlas.tags.annotations.validation.Validators;
import org.openstreetmap.atlas.utilities.collections.Iterables;
Expand Down Expand Up @@ -107,6 +108,21 @@ public void testLoadingPbfWithWayThatReferencesMissingNode()
Assert.assertEquals(0, atlas.numberOfRelations());
}

@Test
public void testNestedSingleRelations()
{
final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(
new InputStreamResource(() -> RawAtlasGeneratorTest.class
.getResourceAsStream("nestedSingleRelations.osm.pbf")));
final Atlas atlas = rawAtlasGenerator.build();

// Verify Atlas Entities
assertBasicRawAtlasPrinciples(atlas);
Assert.assertEquals(5, atlas.numberOfPoints());
Assert.assertEquals(1, atlas.numberOfLines());
Assert.assertEquals(2, atlas.numberOfRelations());
}

@Test
public void testParityBetweenRawAtlasAndGeneratedAtlas()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='JOSM'>
<node id='-126692' action='modify' lat='4.64106693493' lon='62.20467537641'>
<tag k='duplicate' v='1' />
</node>
<node id='-126693' action='modify' lat='4.64106693493' lon='62.20467537641'>
<tag k='duplicate' v='2' />
</node>
<node id='-126707' action='modify' lat='5.2548712486' lon='62.26990983733' />
<node id='-126708' action='modify' lat='5.26930670118' lon='62.55259250132' />
<node id='-126709' action='modify' lat='5.11700779075' lon='62.56043489553' />
<node id='-126710' action='modify' lat='5.10256885516' lon='62.27775223154' />
<way id='-126711' action='modify'>
<nd ref='-126707' />
<nd ref='-126708' />
<nd ref='-126709' />
<nd ref='-126710' />
<nd ref='-126707' />
<tag k='building' v='yes' />
</way>
<relation id='-126699' action='modify'>
<member type='node' ref='-126692' role='child' />
<tag k='type' v='parent1' />
</relation>
<relation id='-126702' action='modify'>
<member type='relation' ref='-126699' role='childrelation' />
<tag k='type' v='parent1-1' />
</relation>
<relation id='-126718' action='modify'>
<member type='node' ref='-126693' role='child' />
<tag k='type' v='parent2' />
</relation>
<relation id='-126725' action='modify'>
<member type='relation' ref='-126718' role='childrelation' />
<tag k='type' v='parent2-2' />
</relation>
</osm>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='JOSM' timestamp='2017-12-19T21:43:02Z'>
<node id='126692' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='4.64106693493' lon='62.20467537641'>
<tag k='duplicate' v='1' />
</node>
<node id='126693' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='4.64106693493' lon='62.20467537641'>
<tag k='duplicate' v='2' />
</node>
<node id='126707' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='5.2548712486' lon='62.26990983733' />
<node id='126708' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='5.26930670118' lon='62.55259250132' />
<node id='126709' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='5.11700779075' lon='62.56043489553' />
<node id='126710' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify' lat='5.10256885516' lon='62.27775223154' />
<way id='126711' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify'>
<nd ref='126707' />
<nd ref='126708' />
<nd ref='126709' />
<nd ref='126710' />
<nd ref='126707' />
<tag k='building' v='yes' />
</way>
<relation id='126699' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify'>
<member type='node' ref='126692' role='child' />
<tag k='type' v='parent1' />
</relation>
<relation id='126702' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify'>
<member type='relation' ref='126699' role='childrelation' />
<tag k='type' v='parent1-1' />
</relation>
<relation id='126718' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify'>
<member type='node' ref='126693' role='child' />
<tag k='type' v='parent2' />
</relation>
<relation id='126725' uid='1' version='1' changeset='1' user='myself' timestamp='2017-12-19T21:43:02Z' action='modify'>
<member type='relation' ref='126718' role='childrelation' />
<tag k='type' v='parent2-2' />
</relation>
</osm>
Binary file not shown.

0 comments on commit 351a9c6

Please sign in to comment.