Skip to content

Commit

Permalink
Fix GeoShapeWithDocValuesFieldTypeTests#testFetchVectorTile (elastic#…
Browse files Browse the repository at this point in the history
…76063)

ignore invalid geometries the same way we are doing it in ArraySourceValueFetcher and
only simplify (multi)polygons if they are valid
  • Loading branch information
iverase authored Aug 5, 2021
1 parent b371463 commit 2985f7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void testFetchSourceValue() throws IOException {
assertEquals(List.of(wktLineString, wktPoint), fetchSourceValue(mapper, sourceValue, "wkt"));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/76059")
public void testFetchVectorTile() throws IOException {
fetchVectorTile(GeometryTestUtils.randomPoint());
fetchVectorTile(GeometryTestUtils.randomMultiPoint(false));
Expand Down Expand Up @@ -111,7 +110,14 @@ private void fetchVectorTile(Geometry geometry) throws IOException {
}

final List<?> sourceValue = fetchSourceValue(mapper, WellKnownText.toWKT(geometry), mvtString);
final List<byte[]> features = featureFactory.getFeatures(geometry);
List<byte[]> features;
try {
features = featureFactory.getFeatures(geometry);
} catch (IllegalArgumentException iae) {
// if parsing fails means that we must be ignoring malformed values. In case of mvt might
// happen that the geometry is out of range (close to the poles).
features = List.of();
}
assertThat(features.size(), Matchers.equalTo(sourceValue.size()));
for (int i = 0; i < features.size(); i++) {
assertThat(sourceValue.get(i), Matchers.equalTo(features.get(i)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,29 @@ private LineString buildLine(Line line) {

@Override
public org.locationtech.jts.geom.Geometry visit(Polygon polygon) throws RuntimeException {
final org.locationtech.jts.geom.Polygon jtsPolygon = buildPolygon(polygon);
if (jtsPolygon.contains(tile)) {
// shortcut, we return the tile
return tile;
}
return TopologyPreservingSimplifier.simplify(jtsPolygon, pixelPrecision);
return simplifyGeometry(buildPolygon(polygon));
}

@Override
public org.locationtech.jts.geom.Geometry visit(MultiPolygon multiPolygon) throws RuntimeException {
final org.locationtech.jts.geom.Polygon[] polygons = new org.locationtech.jts.geom.Polygon[multiPolygon.size()];
for (int i = 0; i < multiPolygon.size(); i++) {
final org.locationtech.jts.geom.Polygon jtsPolygon = buildPolygon(multiPolygon.get(i));
if (jtsPolygon.contains(tile)) {
// shortcut, we return the tile
return tile;
}
polygons[i] = jtsPolygon;
}
return TopologyPreservingSimplifier.simplify(geomFactory.createMultiPolygon(polygons), pixelPrecision);
return simplifyGeometry(geomFactory.createMultiPolygon(polygons));
}

private org.locationtech.jts.geom.Geometry simplifyGeometry(org.locationtech.jts.geom.Geometry geometry) {
if (geometry.isValid() == false) {
// we only simplify the geometry if it is valid, otherwise algorithm might fail.
return geometry;
}
if (geometry.contains(tile)) {
// shortcut, we return the tile
return tile;
}
return TopologyPreservingSimplifier.simplify(geometry, pixelPrecision);
}

private org.locationtech.jts.geom.Polygon buildPolygon(Polygon polygon) {
Expand Down

0 comments on commit 2985f7f

Please sign in to comment.