Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wipfli committed Nov 22, 2024
1 parent 202c14e commit d7e4b03
Showing 1 changed file with 0 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,80 +185,7 @@ public static List<VectorTile.Feature> mergeLineStrings(List<VectorTile.Feature>
}
}
List<LineString> outputSegments = new ArrayList<>();
var i = 0;
for (var line : merger.getMergedLineStrings()) {
// TODO remove debug features comment
// Map<String, Object> attrs = new HashMap<>();
// attrs.put("idx", i++);
// result.add(feature1.copyWithNewGeometry(line.getStartPoint()).copyWithExtraAttrs(attrs));
// result.add(feature1.copyWithNewGeometry(line).copyWithExtraAttrs(attrs));
// attrs.put("end", "yes");
// result.add(feature1.copyWithNewGeometry(line.getEndPoint()).copyWithExtraAttrs(attrs));

if (buffer >= 0) {
removeDetailOutsideTile(line, buffer, outputSegments);
} else {
outputSegments.add(line);
}
}

if (!outputSegments.isEmpty()) {
outputSegments = sortByHilbertIndex(outputSegments);
Geometry newGeometry = GeoUtils.combineLineStrings(outputSegments);
result.add(feature1.copyWithNewGeometry(newGeometry));
// i = 0;
// for (var outputSegment : outputSegments) {
// Map<String, Object> attrs = new HashMap<>();
// attrs.put("idx", ++i);
// result.add(feature1.copyWithNewGeometry(outputSegment).copyWithExtraAttrs(attrs));
// }
}
}
}
return result;
}

public static List<VectorTile.Feature> mergeLineStringsAllParams(List<VectorTile.Feature> features,
Function<Map<String, Object>, Double> lengthLimitCalculator, double tolerance, double buffer, boolean resimplify,
double loopMinLength, double stubMinLength) {
List<VectorTile.Feature> result = new ArrayList<>(features.size());
var groupedByAttrs = groupByAttrs(features, result, GeometryType.LINE);
for (List<VectorTile.Feature> groupedFeatures : groupedByAttrs) {
VectorTile.Feature feature1 = groupedFeatures.getFirst();
double lengthLimit = lengthLimitCalculator.apply(feature1.tags());

// as a shortcut, can skip line merging only if:
// - only 1 element in the group
// - it doesn't need to be clipped
// - and it can't possibly be filtered out for being too short
// - and it does not need to be simplified
if (groupedFeatures.size() == 1 && buffer == 0d && lengthLimit == 0 && (!resimplify || tolerance == 0)) {
result.add(feature1);
} else {
LoopLineMerger merger = new LoopLineMerger()
.setTolerance(tolerance)
.setMergeStrokes(true)
.setMinLength(lengthLimit)
.setLoopMinLength(loopMinLength)
.setStubMinLength(stubMinLength);
for (VectorTile.Feature feature : groupedFeatures) {
try {
merger.add(feature.geometry().decode());
} catch (GeometryException e) {
e.log("Error decoding vector tile feature for line merge: " + feature);
}
}
List<LineString> outputSegments = new ArrayList<>();
var i = 0;
for (var line : merger.getMergedLineStrings()) {
// TODO remove debug features comment
// Map<String, Object> attrs = new HashMap<>();
// attrs.put("idx", i++);
// result.add(feature1.copyWithNewGeometry(line.getStartPoint()).copyWithExtraAttrs(attrs));
// result.add(feature1.copyWithNewGeometry(line).copyWithExtraAttrs(attrs));
// attrs.put("end", "yes");
// result.add(feature1.copyWithNewGeometry(line.getEndPoint()).copyWithExtraAttrs(attrs));

if (buffer >= 0) {
removeDetailOutsideTile(line, buffer, outputSegments);
} else {
Expand All @@ -270,12 +197,6 @@ public static List<VectorTile.Feature> mergeLineStringsAllParams(List<VectorTile
outputSegments = sortByHilbertIndex(outputSegments);
Geometry newGeometry = GeoUtils.combineLineStrings(outputSegments);
result.add(feature1.copyWithNewGeometry(newGeometry));
// i = 0;
// for (var outputSegment : outputSegments) {
// Map<String, Object> attrs = new HashMap<>();
// attrs.put("idx", ++i);
// result.add(feature1.copyWithNewGeometry(outputSegment).copyWithExtraAttrs(attrs));
// }
}
}
}
Expand Down

0 comments on commit d7e4b03

Please sign in to comment.