Porównaj commity

...

7 Commity

Autor SHA1 Wiadomość Data
Michael Barry a0e4360e7a
Merge 7c86699a04 into ade89c0739 2024-04-16 18:55:16 +03:00
dependabot[bot] ade89c0739
Bump org.slf4j:slf4j-api from 2.0.12 to 2.0.13 (#868) 2024-04-15 07:38:33 -04:00
dependabot[bot] 6f6a4dd6ed
Bump org.apache.maven.plugins:maven-gpg-plugin from 3.2.2 to 3.2.3 (#867)
Bumps [org.apache.maven.plugins:maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
- [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-3.2.2...maven-gpg-plugin-3.2.3)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-gpg-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-11 06:11:07 -04:00
dependabot[bot] 6b9c996df9
Bump org.apache.maven.plugins:maven-source-plugin from 3.3.0 to 3.3.1 (#865)
Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.0 to 3.3.1.
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.3.0...maven-source-plugin-3.3.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-10 07:13:03 -04:00
Michael Barry 978c64f0c6
Add polygon index intersection utility (#866) 2024-04-10 07:12:29 -04:00
Mike Barry 7c86699a04 undo 2024-03-04 05:13:54 -05:00
Mike Barry b38b8b37a1 encode node/way/relation in vector tile feature id 2024-03-03 20:40:17 -05:00
7 zmienionych plików z 71 dodań i 20 usunięć

Wyświetl plik

@ -77,7 +77,7 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>2.0.12</version> <version>2.0.13</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>

Wyświetl plik

@ -6,6 +6,8 @@ import com.onthegomap.planetiler.geo.GeoUtils;
import com.onthegomap.planetiler.geo.GeometryException; import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.GeometryType; import com.onthegomap.planetiler.geo.GeometryType;
import com.onthegomap.planetiler.reader.SourceFeature; import com.onthegomap.planetiler.reader.SourceFeature;
import com.onthegomap.planetiler.reader.osm.OsmElement;
import com.onthegomap.planetiler.reader.osm.OsmSourceFeature;
import com.onthegomap.planetiler.render.FeatureRenderer; import com.onthegomap.planetiler.render.FeatureRenderer;
import com.onthegomap.planetiler.stats.Stats; import com.onthegomap.planetiler.stats.Stats;
import com.onthegomap.planetiler.util.CacheByZoom; import com.onthegomap.planetiler.util.CacheByZoom;
@ -59,7 +61,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
* @return a feature that can be configured further. * @return a feature that can be configured further.
*/ */
public Feature geometry(String layer, Geometry geometry) { public Feature geometry(String layer, Geometry geometry) {
Feature feature = new Feature(layer, geometry, source.id()); Feature feature = new Feature(layer, geometry, source);
output.add(feature); output.add(feature);
return feature; return feature;
} }
@ -81,7 +83,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.worldGeometry()); return geometry(layer, source.worldGeometry());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_point", "Error getting point geometry for " + source.id()); e.log(stats, "feature_point", "Error getting point geometry for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -101,7 +103,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.line()); return geometry(layer, source.line());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_line", "Error constructing line for " + source.id()); e.log(stats, "feature_line", "Error constructing line for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -121,7 +123,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.polygon()); return geometry(layer, source.polygon());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_polygon", "Error constructing polygon for " + source.id()); e.log(stats, "feature_polygon", "Error constructing polygon for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -136,7 +138,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.centroid()); return geometry(layer, source.centroid());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_centroid", "Error getting centroid for " + source.id()); e.log(stats, "feature_centroid", "Error getting centroid for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -153,7 +155,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.centroidIfConvex()); return geometry(layer, source.centroidIfConvex());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_centroid_if_convex", "Error constructing centroid if convex for " + source.id()); e.log(stats, "feature_centroid_if_convex", "Error constructing centroid if convex for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -169,7 +171,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.pointOnSurface()); return geometry(layer, source.pointOnSurface());
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_point_on_surface", "Error constructing point on surface for " + source.id()); e.log(stats, "feature_point_on_surface", "Error constructing point on surface for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -191,7 +193,7 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
return geometry(layer, source.innermostPoint(tolerance)); return geometry(layer, source.innermostPoint(tolerance));
} catch (GeometryException e) { } catch (GeometryException e) {
e.log(stats, "feature_innermost_point", "Error constructing innermost point for " + source.id()); e.log(stats, "feature_innermost_point", "Error constructing innermost point for " + source.id());
return new Feature(layer, EMPTY_GEOM, source.id()); return new Feature(layer, EMPTY_GEOM, source);
} }
} }
@ -275,11 +277,21 @@ public class FeatureCollector implements Iterable<FeatureCollector.Feature> {
private String numPointsAttr = null; private String numPointsAttr = null;
private Feature(String layer, Geometry geom, long id) { private Feature(String layer, Geometry geom, SourceFeature source) {
this.layer = layer; this.layer = layer;
this.geom = geom; this.geom = geom;
this.geometryType = GeometryType.typeOf(geom); this.geometryType = GeometryType.typeOf(geom);
this.id = id; if (source instanceof OsmSourceFeature osmSourceFeature) {
long osmId = osmSourceFeature.originalElement().id();
this.id = switch (osmSourceFeature.originalElement()) {
case OsmElement.Node node -> node.id() * 10 + 1;
case OsmElement.Way way -> way.id() * 10 + 2;
case OsmElement.Relation relation -> relation.id() * 10 + 3;
default -> osmId * 10;
};
} else {
this.id = source.id();
}
if (geometryType == GeometryType.POINT) { if (geometryType == GeometryType.POINT) {
minPixelSizeAtMaxZoom = 0; minPixelSizeAtMaxZoom = 0;
defaultMinPixelSize = 0; defaultMinPixelSize = 0;

Wyświetl plik

@ -57,11 +57,29 @@ public class PolygonIndex<T> {
return postFilterContaining(point, items); return postFilterContaining(point, items);
} }
/** Returns the data associated with all polygons containing {@code point}. */
public List<T> getIntersecting(Geometry geom) {
build();
List<?> items = index.query(geom.getEnvelopeInternal());
return postFilterIntersecting(geom, items);
}
private List<T> postFilterContaining(Point point, List<?> items) { private List<T> postFilterContaining(Point point, List<?> items) {
List<T> result = new ArrayList<>(items.size()); List<T> result = new ArrayList<>(items.size());
for (Object item : items) { for (Object item : items) {
if (item instanceof GeomWithData<?> value && value.poly.contains(point)) { if (item instanceof GeomWithData<?>(var poly,var data) && poly.contains(point)) {
@SuppressWarnings("unchecked") T t = (T) value.data; @SuppressWarnings("unchecked") T t = (T) data;
result.add(t);
}
}
return result;
}
private List<T> postFilterIntersecting(Geometry geom, List<?> items) {
List<T> result = new ArrayList<>(items.size());
for (Object item : items) {
if (item instanceof GeomWithData<?>(var poly,var data) && poly.intersects(geom)) {
@SuppressWarnings("unchecked") T t = (T) data;
result.add(t); result.add(t);
} }
} }

Wyświetl plik

@ -875,7 +875,7 @@ class PlanetilerTests {
feature(newPoint(128, 128), Map.of( feature(newPoint(128, 128), Map.of(
"attr", "value", "attr", "value",
"name", "name value" "name", "name value"
)) )).withId(11)
) )
), results.tiles); ), results.tiles);
} }
@ -964,7 +964,7 @@ class PlanetilerTests {
feature(newLineString(128, 128, 192, 192), Map.of( feature(newLineString(128, 128, 192, 192), Map.of(
"attr", "value", "attr", "value",
"name", "name value" "name", "name value"
)) )).withId(32)
) )
), results.tiles); ), results.tiles);
} }
@ -1089,7 +1089,7 @@ class PlanetilerTests {
"attr", "value", "attr", "value",
"name", "name value", "name", "name value",
"relname", "rel name" "relname", "rel name"
)) )).withId(173)
) )
), results.tiles); ), results.tiles);
} }

Wyświetl plik

@ -279,7 +279,9 @@ public class TestUtils {
case UNKNOWN -> throw new IllegalArgumentException("cannot decompress \"UNKNOWN\""); case UNKNOWN -> throw new IllegalArgumentException("cannot decompress \"UNKNOWN\"");
}; };
var decoded = VectorTile.decode(bytes).stream() var decoded = VectorTile.decode(bytes).stream()
.map(feature -> feature(decodeSilently(feature.geometry()), feature.layer(), feature.attrs())).toList(); .map(
feature -> feature(decodeSilently(feature.geometry()), feature.layer(), feature.attrs()).withId(feature.id()))
.toList();
tiles.put(tile.coord(), decoded); tiles.put(tile.coord(), decoded);
} }
return tiles; return tiles;
@ -467,12 +469,21 @@ public class TestUtils {
public record ComparableFeature( public record ComparableFeature(
GeometryComparision geometry, GeometryComparision geometry,
String layer, String layer,
Map<String, Object> attrs Map<String, Object> attrs,
Long id
) { ) {
ComparableFeature(
GeometryComparision geometry,
String layer,
Map<String, Object> attrs
) {
this(geometry, layer, attrs, null);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
return o == this || (o instanceof ComparableFeature other && return o == this || (o instanceof ComparableFeature other &&
(id == null || other.id == null || id.equals(other.id)) &&
geometry.equals(other.geometry) && geometry.equals(other.geometry) &&
attrs.equals(other.attrs) && attrs.equals(other.attrs) &&
(layer == null || other.layer == null || Objects.equals(layer, other.layer))); (layer == null || other.layer == null || Objects.equals(layer, other.layer)));
@ -484,6 +495,10 @@ public class TestUtils {
result = 31 * result + attrs.hashCode(); result = 31 * result + attrs.hashCode();
return result; return result;
} }
ComparableFeature withId(long id) {
return new ComparableFeature(geometry, layer, attrs, id);
}
} }
public static ComparableFeature feature(Geometry geom, String layer, Map<String, Object> attrs) { public static ComparableFeature feature(Geometry geom, String layer, Map<String, Object> attrs) {

Wyświetl plik

@ -21,10 +21,13 @@ class PolygonIndexTest {
void testSingle() { void testSingle() {
index.put(rectangle(0, 1), 1); index.put(rectangle(0, 1), 1);
assertListsContainSameElements(List.of(1), index.getContaining(newPoint(0.5, 0.5))); assertListsContainSameElements(List.of(1), index.getContaining(newPoint(0.5, 0.5)));
assertListsContainSameElements(List.of(1), index.getIntersecting(newPoint(0.5, 0.5)));
assertListsContainSameElements(List.of(1), index.getIntersecting(rectangle(1, 2)));
assertListsContainSameElements(List.of(1), index.getContainingOrNearest(newPoint(0.5, 0.5))); assertListsContainSameElements(List.of(1), index.getContainingOrNearest(newPoint(0.5, 0.5)));
assertListsContainSameElements(List.of(), index.getContaining(newPoint(1.5, 1.5))); assertListsContainSameElements(List.of(), index.getContaining(newPoint(1.5, 1.5)));
assertListsContainSameElements(List.of(), index.getContainingOrNearest(newPoint(1.5, 1.5))); assertListsContainSameElements(List.of(), index.getContainingOrNearest(newPoint(1.5, 1.5)));
assertListsContainSameElements(List.of(), index.getIntersecting(rectangle(2, 3)));
} }
@Test @Test
@ -33,6 +36,9 @@ class PolygonIndexTest {
index.put(rectangle(0, 1), 2); index.put(rectangle(0, 1), 2);
assertListsContainSameElements(List.of(1, 2), index.getContaining(newPoint(0.5, 0.5))); assertListsContainSameElements(List.of(1, 2), index.getContaining(newPoint(0.5, 0.5)));
assertListsContainSameElements(List.of(1, 2), index.getContainingOrNearest(newPoint(0.5, 0.5))); assertListsContainSameElements(List.of(1, 2), index.getContainingOrNearest(newPoint(0.5, 0.5)));
assertListsContainSameElements(List.of(1, 2), index.getIntersecting(rectangle(0.5, 1.5)));
assertListsContainSameElements(List.of(1, 2), index.getIntersecting(rectangle(1, 2)));
assertListsContainSameElements(List.of(), index.getIntersecting(rectangle(2, 3)));
} }
@Test @Test

Wyświetl plik

@ -313,7 +313,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version> <version>3.3.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>
@ -394,7 +394,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>3.2.2</version> <version>3.2.3</version>
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>