From e3c740c77a8bc86cd54a3a140b6a2d796fb5799c Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Tue, 19 Oct 2021 08:04:52 +0200 Subject: [PATCH] Vector tiles: increase the size of the envelope used to clip geometries (#79030) (#79416) Removes the tile outline from polygons that cross contiguous tiles. --- .../xpack/vectortile/feature/FeatureFactory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/feature/FeatureFactory.java b/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/feature/FeatureFactory.java index e1e517231ba1e..a38e4bc706512 100644 --- a/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/feature/FeatureFactory.java +++ b/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/feature/FeatureFactory.java @@ -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);