diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/GeometryReader.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/GeometryReader.java index 67deed9ced..31436f2aa4 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/GeometryReader.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/GeometryReader.java @@ -13,8 +13,9 @@ * Decodes geometries from a parquet record based on the {@link GeoParquetMetadata} provided. */ class GeometryReader { + private final Map> converters = new HashMap<>(); - private final String geometryColumn; + final String geometryColumn; GeometryReader(GeoParquetMetadata geoparquet) { this.geometryColumn = geoparquet.primaryColumn(); @@ -37,7 +38,6 @@ class GeometryReader { case "point", "geoarrow.point" -> GeoArrow::point; default -> throw new IllegalArgumentException("Unhandled type: " + columnInfo.encoding()); }; - converters.put(column, converter); } } @@ -47,7 +47,10 @@ Geometry readPrimaryGeometry(WithTags tags) throws GeometryException { } Geometry readGeometry(WithTags tags, String column) throws GeometryException { - var value = tags.getTag(column); + return parseGeometry(tags.getTag(column), column); + } + + Geometry parseGeometry(Object value, String column) throws GeometryException { var converter = converters.get(column); if (value == null) { throw new GeometryException("no_parquet_column", "Missing geometry column column " + column); diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetFeature.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetFeature.java index 6cbc826244..03bcaf7ef5 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetFeature.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetFeature.java @@ -3,7 +3,6 @@ import com.onthegomap.planetiler.geo.GeoUtils; import com.onthegomap.planetiler.geo.GeometryException; import com.onthegomap.planetiler.reader.SourceFeature; -import java.nio.file.Path; import java.util.List; import java.util.Map; import org.locationtech.jts.geom.Geometry; @@ -17,24 +16,20 @@ public class ParquetFeature extends SourceFeature { private final GeometryReader geometryParser; - private final Path filename; + private final Object rawGeometry; private Geometry latLon; private Geometry world; - ParquetFeature(String source, String sourceLayer, Path filename, long id, GeometryReader geometryParser, + ParquetFeature(String source, String sourceLayer, long id, GeometryReader geometryParser, Map tags) { super(tags, source, sourceLayer, List.of(), id); this.geometryParser = geometryParser; - this.filename = filename; - } - - public Path getFilename() { - return filename; + this.rawGeometry = tags.remove(geometryParser.geometryColumn); } @Override public Geometry latLonGeometry() throws GeometryException { - return latLon == null ? latLon = geometryParser.readPrimaryGeometry(this) : latLon; + return latLon == null ? latLon = geometryParser.parseGeometry(rawGeometry, geometryParser.geometryColumn) : latLon; } @Override diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFile.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFile.java index d6b16b42e2..393014b2b6 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFile.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFile.java @@ -50,7 +50,7 @@ public class ParquetInputFile { private final String layer; private final long count; private final int blockCount; - private final GeometryReader geometryReader; + final GeometryReader geometryReader; private final Map extraFields; private Envelope postFilterBounds = null; private boolean outOfBounds = false; @@ -177,7 +177,6 @@ public ParquetFeature next() { var feature = new ParquetFeature( source, layer, - path, idGenerator != null ? idGenerator.applyAsLong(item) : Hashing.fnv1a64(blockHash, ByteBuffer.allocate(8).putLong(i).array()), geometryReader, diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFileTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFileTest.java index 994b1dc42b..d47c5b9666 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFileTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/reader/parquet/ParquetInputFileTest.java @@ -1,8 +1,6 @@ package com.onthegomap.planetiler.reader.parquet; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.DynamicTest.dynamicTest; import com.onthegomap.planetiler.TestUtils; @@ -36,10 +34,12 @@ static List bostons() { void testReadBoston(Path path) { for (int i = 0; i < 3; i++) { Set ids = new HashSet<>(); - for (var block : new ParquetInputFile("parquet", "layer", path) - .get()) { + var file = new ParquetInputFile("parquet", "layer", path); + for (var block : file.get()) { for (var item : block) { ids.add(item.getString("id")); + assertFalse(item.hasTag(file.geometryReader.geometryColumn)); + assertNull(item.getTag(file.geometryReader.geometryColumn)); } } assertEquals(3, ids.size(), "iter " + i);