Allow centroid for other geometry types in yaml configs (#945)

pull/947/head v0.8.2
Michael Barry 2024-07-02 07:35:53 -04:00 zatwierdzone przez GitHub
rodzic bbea298da6
commit a74f274c31
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
6 zmienionych plików z 79 dodań i 7 usunięć

Wyświetl plik

@ -13,7 +13,12 @@ import org.locationtech.jts.geom.Puntal;
import vector_tile.VectorTileProto;
public enum GeometryType {
UNKNOWN(VectorTileProto.Tile.GeomType.UNKNOWN, 0, "unknown"),
UNKNOWN(VectorTileProto.Tile.GeomType.UNKNOWN, 0, "unknown") {
@Override
public Expression featureTest() {
return Expression.TRUE;
}
},
@JsonProperty("point")
POINT(VectorTileProto.Tile.GeomType.POINT, 1, "point"),
@JsonProperty("line")

Wyświetl plik

@ -3,7 +3,6 @@ package com.onthegomap.planetiler.geo;
import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.onthegomap.planetiler.TestUtils;
@ -42,9 +41,9 @@ class GeometryTypeTest {
assertFalse(GeometryType.POLYGON.featureTest().evaluate(point));
assertTrue(GeometryType.POLYGON.featureTest().evaluate(poly));
assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(point));
assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(line));
assertThrows(Exception.class, () -> GeometryType.UNKNOWN.featureTest().evaluate(poly));
assertTrue(GeometryType.UNKNOWN.featureTest().evaluate(point));
assertTrue(GeometryType.UNKNOWN.featureTest().evaluate(line));
assertTrue(GeometryType.UNKNOWN.featureTest().evaluate(poly));
}
@ParameterizedTest

Wyświetl plik

@ -219,7 +219,10 @@ A feature is a defined set of objects that meet a specified filter criteria.
of:
- `point` `line` or `polygon` to pass the original feature through
- `polygon_centroid` to match on polygons, and emit a point at the center
- `line_centroid` to match on lines, and emit a point at the center
- `centroid` to match any geometry, and emit a point at the center
- `polygon_point_on_surface` to match on polygons, and emit an interior point
- `point_on_line` to match on lines, and emit a point somewhere along the line
- `polygon_centroid_if_convex` to match on polygons, and if the polygon is convex emit the centroid, otherwise emit an
interior point
- `min_tile_cover_size` - Include objects of a certain geometry size, where 1.0 means "is

Wyświetl plik

@ -354,8 +354,11 @@
"line",
"polygon",
"polygon_centroid",
"line_centroid",
"centroid",
"polygon_centroid_if_convex",
"polygon_point_on_surface"
"polygon_point_on_surface",
"point_on_line"
]
},
"source": {

Wyświetl plik

@ -16,10 +16,16 @@ public enum FeatureGeometry {
POLYGON(GeometryType.POLYGON, FeatureCollector::polygon),
@JsonProperty("polygon_centroid")
POLYGON_CENTROID(GeometryType.POLYGON, FeatureCollector::centroid),
@JsonProperty("line_centroid")
LINE_CENTROID(GeometryType.LINE, FeatureCollector::centroid),
@JsonProperty("centroid")
CENTROID(GeometryType.UNKNOWN, FeatureCollector::centroid),
@JsonProperty("polygon_centroid_if_convex")
POLYGON_CENTROID_IF_CONVEX(GeometryType.POLYGON, FeatureCollector::centroidIfConvex),
@JsonProperty("polygon_point_on_surface")
POLYGON_POINT_ON_SURFACE(GeometryType.POLYGON, FeatureCollector::pointOnSurface);
POLYGON_POINT_ON_SURFACE(GeometryType.POLYGON, FeatureCollector::pointOnSurface),
@JsonProperty("point_on_line")
POINT_ON_LINE(GeometryType.LINE, FeatureCollector::pointOnSurface);
public final GeometryType geometryType;
public final BiFunction<FeatureCollector, String, FeatureCollector.Feature> geometryFactory;

Wyświetl plik

@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.locationtech.jts.geom.Puntal;
class ConfiguredFeatureTest {
private PlanetilerConfig planetilerConfig = PlanetilerConfig.defaults();
@ -1222,4 +1223,59 @@ class ConfiguredFeatureTest {
)
), loadConfig(config).findFeatureLayer("testLayer").postProcess());
}
@Test
void testCentroid() {
var config = """
sources:
osm:
type: osm
url: geofabrik:rhode-island
local_path: data/rhode-island.osm.pbf
layers:
- id: testLayer
features:
- source: osm
geometry: centroid
""";
this.planetilerConfig = PlanetilerConfig.from(Arguments.of(Map.of()));
testPolygon(config, Map.of(
"natural", "water"
), feature -> {
assertInstanceOf(Puntal.class, feature.getGeometry());
}, 1);
testLinestring(config, Map.of(
"natural", "water"
), feature -> {
assertInstanceOf(Puntal.class, feature.getGeometry());
}, 1);
testPoint(config, Map.of(
"natural", "water"
), feature -> {
assertInstanceOf(Puntal.class, feature.getGeometry());
}, 1);
}
@ParameterizedTest
@ValueSource(strings = {"line_centroid", "point_on_line"})
void testLineCentroid(String type) {
var config = """
sources:
osm:
type: osm
url: geofabrik:rhode-island
local_path: data/rhode-island.osm.pbf
layers:
- id: testLayer
features:
- source: osm
geometry: %s
""".formatted(type);
this.planetilerConfig = PlanetilerConfig.from(Arguments.of(Map.of()));
testLinestring(config, Map.of(
"natural", "water"
), feature -> {
assertInstanceOf(Puntal.class, feature.getGeometry());
}, 1);
}
}