Skip to content

Commit

Permalink
remove primary geometry from parquet feature tags
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed May 23, 2024
1 parent f4fcb16 commit d17d582
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* Decodes geometries from a parquet record based on the {@link GeoParquetMetadata} provided.
*/
class GeometryReader {

private final Map<String, FunctionThatThrows<Object, Geometry>> converters = new HashMap<>();
private final String geometryColumn;
final String geometryColumn;

GeometryReader(GeoParquetMetadata geoparquet) {
this.geometryColumn = geoparquet.primaryColumn();
Expand All @@ -37,7 +38,6 @@ class GeometryReader {
case "point", "geoarrow.point" -> GeoArrow::point;
default -> throw new IllegalArgumentException("Unhandled type: " + columnInfo.encoding());
};

converters.put(column, converter);
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> extraFields;
private Envelope postFilterBounds = null;
private boolean outOfBounds = false;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,10 +34,12 @@ static List<Path> bostons() {
void testReadBoston(Path path) {
for (int i = 0; i < 3; i++) {
Set<Object> 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);
Expand Down

0 comments on commit d17d582

Please sign in to comment.