Skip to content

Commit

Permalink
sort features before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 25, 2023
1 parent 1b53493 commit c0fa519
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -117,6 +118,7 @@ private static List<VectorTile.Feature> mergeGeometries(
List<VectorTile.Feature> features,
GeometryType geometryType
) {
features = features.stream().sorted(Comparator.comparingInt(f -> f.geometry().index())).toList();
List<VectorTile.Feature> result = new ArrayList<>(features.size());
var groupedByAttrs = groupByAttrs(features, result, geometryType);
for (List<VectorTile.Feature> groupedFeatures : groupedByAttrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.onthegomap.planetiler.geo.GeometryException;
import com.onthegomap.planetiler.geo.GeometryType;
import com.onthegomap.planetiler.geo.MutableCoordinateSequence;
import com.onthegomap.planetiler.util.Hilbert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -923,6 +924,13 @@ public VectorGeometry filterPointsOutsideBuffer(double buffer) {
return this;
}
}

public int index() {
// 0 -> 4096*2*2
int x = commands[1];
int y = commands[2];
return Hilbert.hilbertXYToIndex(14, x, y);
}
}

/**
Expand Down

0 comments on commit c0fa519

Please sign in to comment.