diff --git a/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java b/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java index 343cb565..2888f5e9 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryUtils.java @@ -41,10 +41,10 @@ public enum PointOrientation { // if we do not preserve this, we will result polygon rejected by elastic due to not having 3 non-collinear // points after rounding by the GeometryJson protected static GeometryJSON geometryJson = new GeometryJSON(15); - + // A value based on trial and error, this is a default value and user can override it with the yaml file @Getter @Setter - protected static double coastalPrecision = 0.05; + protected static double coastalPrecision = 0.1; // Load a coastline shape file so that we can get a spatial extents that cover sea only public static void init() { @@ -68,7 +68,10 @@ public static void init() { SimpleFeature feature = iterator.next(); Geometry landFeatureGeometry = (Geometry) feature.getDefaultGeometry(); - // This will reduce the points of the shape file for faster processing + // This will reduce the points of the shape file for faster processing, this + // simplification may cause polygon invalid and therefore need to use buffer(0.0) later + // during processing to work around this issue. Another choice is TopologyPreservingSimplifier + // but the polygon output is a bit complicated Geometry simplifiedGeometry = DouglasPeuckerSimplifier .simplify(landFeatureGeometry, getCoastalPrecision()); // Adjust tolerance diff --git a/indexer/src/test/java/au/org/aodn/esindexer/service/StacCollectionMapperServiceTest.java b/indexer/src/test/java/au/org/aodn/esindexer/service/StacCollectionMapperServiceTest.java index d05aec06..2b5ea9d2 100644 --- a/indexer/src/test/java/au/org/aodn/esindexer/service/StacCollectionMapperServiceTest.java +++ b/indexer/src/test/java/au/org/aodn/esindexer/service/StacCollectionMapperServiceTest.java @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j; import org.json.JSONException; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -78,6 +79,11 @@ public class StacCollectionMapperServiceTest { protected IndexerServiceImpl indexerService; + @BeforeAll + public static void preSetup() { + GeometryUtils.setCoastalPrecision(0.05); + } + protected void verify(String expected) throws JsonProcessingException, JSONException { Map content = objectMapper.readValue(lastRequest.get().document().toString(), Map.class); String out = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(content);