diff --git a/indexer/src/main/java/au/org/aodn/esindexer/configuration/IndexerConfig.java b/indexer/src/main/java/au/org/aodn/esindexer/configuration/IndexerConfig.java index c0aea227..88f1fa10 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/configuration/IndexerConfig.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/configuration/IndexerConfig.java @@ -21,12 +21,22 @@ @EnableAsync public class IndexerConfig { @Value("${app.geometry.gridLandSize:10.0}") - protected double cellSize; + protected double gridSize; + + @Value("${app.geometry.enableGridSpatialExtents:false}") + protected boolean girdSpatialExtents; + + @Value("${app.geometry.coastalPrecision:0.04}") + protected double coastalPrecision; @PostConstruct public void init() { - GeometryUtils.setCellSize(cellSize); + GeometryUtils.setGridSize(gridSize); + GeometryUtils.setGridSpatialExtents(girdSpatialExtents); + GeometryUtils.setCoastalPrecision(coastalPrecision); GeometryUtils.setExecutorService(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + + GeometryUtils.init(); } @PreDestroy diff --git a/indexer/src/main/java/au/org/aodn/esindexer/service/IndexerServiceImpl.java b/indexer/src/main/java/au/org/aodn/esindexer/service/IndexerServiceImpl.java index b2e95897..69ef7afe 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/service/IndexerServiceImpl.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/service/IndexerServiceImpl.java @@ -22,7 +22,6 @@ import jakarta.xml.bind.JAXBException; import lombok.extern.slf4j.Slf4j; import au.org.aodn.stac.model.SearchSuggestionsModel; -import org.locationtech.jts.geom.Geometry; import org.opengis.referencing.FactoryException; import org.opengis.referencing.operation.TransformException; import org.springframework.beans.factory.annotation.Autowired; 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 bb6da16d..9db7c343 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 @@ -37,16 +37,24 @@ public class GeometryUtils { @Setter protected static ExecutorService executorService; + @Getter + @Setter + protected static boolean gridSpatialExtents; + @Getter @Setter protected static int centroidScale = 3; @Getter @Setter - protected static double cellSize = 10.0; + protected static double gridSize = 10.0; + + @Getter + @Setter + protected static double coastalPrecision = 0.03; // Load a coastline shape file so that we can get a spatial extents that cover sea only - static { + public static void init() { try { // shp file depends on shx, so need to have shx appear in temp folder. saveResourceToTemp("land/ne_10m_land.shx", "shapefile.shx"); @@ -69,7 +77,7 @@ public class GeometryUtils { // This will reduce the points of the shape file for faster processing Geometry simplifiedGeometry = DouglasPeuckerSimplifier - .simplify(landFeatureGeometry, 0.03); // Adjust tolerance + .simplify(landFeatureGeometry, getCoastalPrecision()); // Adjust tolerance geometries.add(simplifiedGeometry); } @@ -283,7 +291,7 @@ protected static List breakLargeGeometryToGrid(final Geometry large) { // Hard code cell size, we can adjust the break grid size. 10.0 result in 3x3 grid // cover Australia - List gridPolygons = createGridPolygons(envelope, getCellSize()); + List gridPolygons = createGridPolygons(envelope, getGridSize()); // List to store Future objects representing the results of the tasks List> futureResults = new ArrayList<>(); @@ -507,7 +515,11 @@ public static List> createCentroidFrom(List> polygonNoLand = splitAreaToGrid(createGeometryWithoutLand(rawInput)); - List> polygonNoLand = GeometryBase.findPolygonsFrom(GeometryBase.COORDINATE_SYSTEM_CRS84, rawInput); - return (polygonNoLand != null && !polygonNoLand.isEmpty()) ? createGeoJson(polygonNoLand) : null; + List> polygon = GeometryBase.findPolygonsFrom(GeometryBase.COORDINATE_SYSTEM_CRS84, rawInput); + + // This is helpful when debug, it help to visualize the grid size on say edge env. + polygon = isGridSpatialExtents() ? splitAreaToGrid(polygon) : polygon; + + return (polygon != null && !polygon.isEmpty()) ? createGeoJson(polygon) : null; } } diff --git a/indexer/src/main/resources/application-dev.yaml b/indexer/src/main/resources/application-dev.yaml index 6a7afdb3..65649e05 100644 --- a/indexer/src/main/resources/application-dev.yaml +++ b/indexer/src/main/resources/application-dev.yaml @@ -1,6 +1,10 @@ server: port: 8081 +app: + geometry: + enableGridSpatialExtents: true + elasticsearch: index: name: dev_portal_records diff --git a/indexer/src/main/resources/application-edge.yaml b/indexer/src/main/resources/application-edge.yaml index 9c316f38..e00d5acd 100644 --- a/indexer/src/main/resources/application-edge.yaml +++ b/indexer/src/main/resources/application-edge.yaml @@ -4,6 +4,10 @@ spring: git: location: "classpath:git.properties" +app: + geometry: + enableGridSpatialExtents: true + management: endpoints: web: diff --git a/indexer/src/test/java/au/org/aodn/esindexer/utils/GeometryUtilsTest.java b/indexer/src/test/java/au/org/aodn/esindexer/utils/GeometryUtilsTest.java index 94c38875..e32a8472 100644 --- a/indexer/src/test/java/au/org/aodn/esindexer/utils/GeometryUtilsTest.java +++ b/indexer/src/test/java/au/org/aodn/esindexer/utils/GeometryUtilsTest.java @@ -5,12 +5,11 @@ import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; import org.geotools.geojson.feature.FeatureJSON; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.*; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.feature.type.FeatureType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.concurrent.Executors; import static au.org.aodn.esindexer.BaseTestClass.readResourceFile; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,6 +31,16 @@ public GeometryUtilsTest() throws JAXBException { jaxb = new JaxbUtils<>(MDMetadataType .class); } + @BeforeEach + public void init() { + GeometryUtils.setCoastalPrecision(0.03); + GeometryUtils.setGridSize(10.0); + GeometryUtils.setGridSpatialExtents(false); + GeometryUtils.setExecutorService(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); + + GeometryUtils.init(); + } + @Test public void verifyLandStrippedFromSpatialExtents() throws IOException, JAXBException { String xml = readResourceFile("classpath:canned/sample_complex_area.xml"); diff --git a/indexer/src/test/resources/application-test.yaml b/indexer/src/test/resources/application-test.yaml index 3707f59b..3a1bd26f 100644 --- a/indexer/src/test/resources/application-test.yaml +++ b/indexer/src/test/resources/application-test.yaml @@ -6,6 +6,7 @@ app: # This value will affect the size of grid to divide a spatial extents which is used to calculate the # centroid point in the summaries, test case needs to change if you change this value gridLandSize: 10.0 + coastalPrecision: 0.03 indexing: pool: core: 2