diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java index 9663c32184..32ed2afb07 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/osm/PbfDecoder.java @@ -297,11 +297,11 @@ public OsmElement.Node next() { int version = 0; if (denseInfo != null) { - version = denseInfo.getVersion(i); - timestamp += denseInfo.getTimestamp(i); - changeset += denseInfo.getChangeset(i); - uid += denseInfo.getUid(i); - userSid += denseInfo.getUserSid(i); + version = denseInfo.getVersionCount() > i ? denseInfo.getVersion(i) : 0; + timestamp += denseInfo.getTimestampCount() > i ? denseInfo.getTimestamp(i) : 0; + changeset += denseInfo.getChangesetCount() > i ? denseInfo.getChangeset(i) : 0; + uid += denseInfo.getUidCount() > i ? denseInfo.getUid(i) : 0; + userSid += denseInfo.getUserSidCount() > i ? denseInfo.getUserSid(i) : 0; } i++; diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/osm/OsmInputFileTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/osm/OsmInputFileTest.java index a56b5462e9..ab83b405da 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/osm/OsmInputFileTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/osm/OsmInputFileTest.java @@ -121,4 +121,49 @@ void testReadMonacoTwice(boolean lazy) { } } } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + @Timeout(30) + void testReadMonacoWithoutChangesetsTwice(boolean lazy) { + for (int i = 1; i <= 2; i++) { + AtomicInteger nodes = new AtomicInteger(0); + AtomicInteger ways = new AtomicInteger(0); + AtomicInteger rels = new AtomicInteger(0); + AtomicReference node = new AtomicReference<>(); + AtomicReference way = new AtomicReference<>(); + AtomicReference rel = new AtomicReference<>(); + var file = new OsmInputFile(TestUtils.pathToResource("monaco-latest-without-changesets.osm.pbf"), lazy); + try (var osmReader = file.get()) { + WorkerPipeline.start("test", Stats.inMemory()) + .fromGenerator("pbf", osmReader::forEachBlock) + .addBuffer("pbf_blocks", 100) + .sinkToConsumer("counter", 1, block -> { + for (var elem : block.decodeElements()) { + if (elem instanceof OsmElement.Node n) { + if (n.id() == expectedNode.id()) { + node.set(n); + } + nodes.incrementAndGet(); + } else if (elem instanceof OsmElement.Way w) { + if (w.id() == expectedWay.id()) { + way.set(w); + } + ways.incrementAndGet(); + } else if (elem instanceof OsmElement.Relation r) { + if (r.id() == expectedRel.id()) { + rel.set(r); + } + rels.incrementAndGet(); + } + } + }).await(); + assertEquals(27_135, nodes.get(), "nodes pass " + i); + assertEquals(4_295, ways.get(), "ways pass " + i); + assertEquals(255, rels.get(), "rels pass " + i); + + assertEquals(new OsmElement.Info(0, 1647347498, 0, 8, ""), node.get().info()); + } + } + } } diff --git a/planetiler-core/src/test/resources/monaco-latest-without-changesets.osm.pbf b/planetiler-core/src/test/resources/monaco-latest-without-changesets.osm.pbf new file mode 100644 index 0000000000..cb9ee5f3e5 Binary files /dev/null and b/planetiler-core/src/test/resources/monaco-latest-without-changesets.osm.pbf differ