Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector tiles: increase the size of the envelope used to clip geometries #79030

Merged
merged 6 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ public class FeatureFactory {
private final CoordinateSequenceFilter sequenceFilter;
// pixel precision of the tile in the mercator projection.
private final double pixelPrecision;
// size of the buffer in pixels for the clip envelope. we choose a values that makes sure
// we have values outside the tile for polygon crossing the tile so the outline of the
// tile is not part of the final result.
// TODO: consider exposing this parameter so users have control of the buffer's size.
private static final int BUFFER_SIZE_PIXELS = 5;

public FeatureFactory(int z, int x, int y, int extent) {
this.pixelPrecision = 2 * SphericalMercatorUtils.MERCATOR_BOUNDS / ((1L << z) * extent);
final Rectangle r = SphericalMercatorUtils.recToSphericalMercator(GeoTileUtils.toBoundingBox(x, y, z));
final Envelope tileEnvelope = new Envelope(r.getMinX(), r.getMaxX(), r.getMinY(), r.getMaxY());
final Envelope clipEnvelope = new Envelope(tileEnvelope);
clipEnvelope.expandBy(this.pixelPrecision, this.pixelPrecision);
// expand enough the clip envelope to prevent visual artefacts
clipEnvelope.expandBy(BUFFER_SIZE_PIXELS * this.pixelPrecision, BUFFER_SIZE_PIXELS * this.pixelPrecision);
final GeometryFactory geomFactory = new GeometryFactory();
this.builder = new JTSGeometryBuilder(geomFactory);
this.clipTile = geomFactory.toGeometry(clipEnvelope);
Expand Down