Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 23, 2023
1 parent f5380b8 commit 3bbfb48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,30 @@ public static List<VectorTile.Feature> mergeLineStrings(List<VectorTile.Feature>
return mergeLineStrings(features, minLength, tolerance, buffer, false);
}

/** Merges points with the same attributes into multipoints. */
public static List<VectorTile.Feature> mergeMultiPoint(List<VectorTile.Feature> features) {
return mergeGeometries(
features,
GeometryType.POINT
);
return mergeGeometries(features, GeometryType.POINT);
}

/**
* Merges polygons with the same attributes into multipolygons.
* <p>
* 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<VectorTile.Feature> mergeMultiPolygon(List<VectorTile.Feature> features) {
return mergeGeometries(
features,
GeometryType.POLYGON
);
return mergeGeometries(features, GeometryType.POLYGON);
}

/**
* Merges linestrings with the same attributes into multilinestrings.
* <p>
* 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<VectorTile.Feature> mergeMultiLineString(List<VectorTile.Feature> features) {
return mergeGeometries(
features,
GeometryType.LINE
);
return mergeGeometries(features, GeometryType.LINE);
}

private static List<VectorTile.Feature> mergeGeometries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -725,23 +723,6 @@ void mergeMultiline() throws GeometryException {
);
}


public static void main(String[] args) {
List<VectorTile.Feature> 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);
}
}

<S extends Geometry, M extends GeometryCollection> void testMultigeometryMerger(
IntFunction<S> generateGeometry,
Function<List<S>, M> combineJTS,
Expand Down

0 comments on commit 3bbfb48

Please sign in to comment.