From 88194a6e438538a466c80b46374c7a0507e6b1d5 Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Thu, 2 May 2024 06:07:46 -0400 Subject: [PATCH] ignore duplicate relation members --- .../com/onthegomap/planetiler/reader/osm/OsmReader.java | 8 +++++++- .../java/com/onthegomap/planetiler/PlanetilerTests.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmReader.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmReader.java index 30343f7cdc..72abb5e792 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmReader.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/OsmReader.java @@ -35,8 +35,10 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; @@ -788,11 +790,15 @@ public MultipolygonSourceFeature(OsmElement.Relation relation, NodeLocationProvi @Override protected Geometry computeWorldGeometry() throws GeometryException { List rings = new ArrayList<>(relation.members().size()); + Set added = new HashSet<>(); for (OsmElement.Relation.Member member : relation.members()) { String role = member.role(); LongArrayList poly = multipolygonWayGeometries.get(member.ref()); if (member.type() == OsmElement.Type.WAY) { - if (poly != null && !poly.isEmpty()) { + if (!added.add(member.ref())) { + // ignore duplicate relation members + stats.dataError("osm_" + relation.getTag("type") + "_duplicate_member"); + } else if (poly != null && !poly.isEmpty()) { rings.add(poly); } else { // boundary and land_area relations might not be complete for extracts, but multipolygons should be diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java index 610af5d9ad..ffe58fffcd 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java @@ -1053,6 +1053,7 @@ record TestRelationInfo(long id, String name) implements OsmRelationInfo {} rel.members().add(new OsmElement.Relation.Member(OsmElement.Type.WAY, 14, "outer")); rel.members().add(new OsmElement.Relation.Member(OsmElement.Type.WAY, 15, null)); // missing rel.members().add(new OsmElement.Relation.Member(OsmElement.Type.WAY, 16, "inner")); // incorrect + rel.members().add(new OsmElement.Relation.Member(OsmElement.Type.WAY, 14, "outer")); // duplicate }), with(new OsmElement.Relation(18), rel -> { rel.setTag("type", "relation");