Skip to content

Commit

Permalink
Merge pull request #529 from GIScience/fix-zero-node-multipolygon-member
Browse files Browse the repository at this point in the history
fix crash while building geometry of multipolygon with zero-node way members
  • Loading branch information
tyrasd authored Jun 25, 2024
2 parents 48ccdec + 1a43e9c commit 68e9963
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

## 1.3.0-SNAPSHOT (current main)

### bugfixes

* Fix crash while building geometry of multipolygon with zero-node way members under certain circumstances


## 1.2.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ private static List<LinkedList<OSMNode>> buildRings(
joinable = false;
for (var waysIterator = ways.iterator(); waysIterator.hasNext();) {
LinkedList<OSMNode> what = waysIterator.next();
if (what.isEmpty()) {
continue;
}
if (lastId == what.getFirst().getId()) {
// end of partial ring matches to start of current line
what.removeFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.heigit.ohsome.oshdb.OSHDBTimestamp;
import org.heigit.ohsome.oshdb.osm.OSMRelation;
import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryBuilder;
import org.heigit.ohsome.oshdb.util.geometry.OSHDBGeometryTest;
import org.heigit.ohsome.oshdb.util.geometry.helpers.TimestampParser;
Expand Down Expand Up @@ -69,4 +70,14 @@ void testAllNodesOfWayNotExistent() {
Geometry result = buildGeometry(relations(502L, 0), timestamp);
assertNotNull(result);
}

@Test
void testRelationMemberWayWithoutNodes() {
// ways without nodes references (=invalid OSM data) can occur in old OSM data
// example: https://www.openstreetmap.org/api/0.6/way/25714579/6
OSMRelation rel = relations(503L, 0);
Geometry result = buildGeometry(rel);
// no exception should have been thrown at this point
assertTrue(result.isValid());
}
}
25 changes: 9 additions & 16 deletions oshdb-util/src/test/resources/incomplete-osm/polygon.osm
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
<node id="21" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.34" lat="1.05"/>
<node id="22" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.05"/>
<node id="23" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.04"/>

<node id="24" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.31" lat="1.04"/>
<node id="25" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.33" lat="1.05"/>
<node id="26" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.33" lat="1.04"/>
<node id="27" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.32" lat="1.04"/>

<node id="28" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="7.31" lat="1.01"/>
<way id="102" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="11"/>
<nd ref="12"/>
<nd ref="13"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="103" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="13"/>
Expand All @@ -31,8 +27,6 @@
<nd ref="17"/>
<nd ref="18"/>
<nd ref="11"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="105" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="24"/>
Expand All @@ -41,36 +35,35 @@
<nd ref="27"/>
<nd ref="28"/>
<nd ref="24"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
</way>
<way id="106" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<nd ref="1"/>
<nd ref="2"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="731"/>
</way>
<way id="107" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
</way>
<relation id="500" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="102" role="outer"/>
<member type="way" ref="103" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="501" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="104" role="outer"/>
<member type="way" ref="105" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="502" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="106" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="test:section" v="mp-geom"/>
<tag k="test:id" v="703"/>
<tag k="landuse" v="forest"/>
</relation>
<relation id="503" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
<member type="way" ref="102" role="outer"/>
<member type="way" ref="107" role="outer"/>
<member type="way" ref="103" role="outer"/>
<tag k="type" v="multipolygon"/>
<tag k="landuse" v="forest"/>
</relation>
</osm>

0 comments on commit 68e9963

Please sign in to comment.