From 3bbfb48481c212d8166b559e5f94d6e49440c1ce Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Sat, 23 Sep 2023 06:08:49 -0400 Subject: [PATCH] comments --- .../onthegomap/planetiler/FeatureMerge.java | 29 +++++++++++-------- .../planetiler/FeatureMergeTest.java | 19 ------------ 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java index aa2bf20e52..41fc61f0b7 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/FeatureMerge.java @@ -87,25 +87,30 @@ public static List mergeLineStrings(List return mergeLineStrings(features, minLength, tolerance, buffer, false); } + /** Merges points with the same attributes into multipoints. */ public static List mergeMultiPoint(List features) { - return mergeGeometries( - features, - GeometryType.POINT - ); + return mergeGeometries(features, GeometryType.POINT); } + /** + * Merges polygons with the same attributes into multipolygons. + *

+ * NOTE: This does not attempt to combine overlapping geometries, see {@link #mergeOverlappingPolygons(List, double)} + * or {@link #mergeNearbyPolygons(List, double, double, double, double)} for that. + */ public static List mergeMultiPolygon(List features) { - return mergeGeometries( - features, - GeometryType.POLYGON - ); + return mergeGeometries(features, GeometryType.POLYGON); } + /** + * Merges linestrings with the same attributes into multilinestrings. + *

+ * NOTE: This does not attempt to connect linestrings that intersect at endpoints, see + * {@link #mergeLineStrings(List, double, double, double, boolean)} for that. Also, this removes extra detail that was + * preserved to improve connected-linestring merging, so you should only use one or the other. + */ public static List mergeMultiLineString(List features) { - return mergeGeometries( - features, - GeometryType.LINE - ); + return mergeGeometries(features, GeometryType.LINE); } private static List mergeGeometries( diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java index 1d8d45955e..3402910b75 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/FeatureMergeTest.java @@ -11,11 +11,9 @@ import com.onthegomap.planetiler.geo.GeometryType; import com.onthegomap.planetiler.mbtiles.Mbtiles; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.function.Function; import java.util.function.IntFunction; import java.util.function.UnaryOperator; @@ -725,23 +723,6 @@ void mergeMultiline() throws GeometryException { ); } - - public static void main(String[] args) { - List features = new ArrayList<>(); - Random r = new Random(0); - for (int i = 0; i < 100_000; i++) { - var lineString = newPoint(r.nextDouble(256), r.nextDouble(256)); - features.add(new VectorTile.Feature("layer", i, VectorTile.encodeGeometry(lineString), Map.of("a", 1))); - } - for (int j = 0; j < 10; j++) { - long start = System.currentTimeMillis(); - for (int i = 0; i < 1_000; i++) { - FeatureMerge.mergeMultiLineString(features); - } - System.err.println(System.currentTimeMillis() - start); - } - } - void testMultigeometryMerger( IntFunction generateGeometry, Function, M> combineJTS,