Skip to content

Commit

Permalink
Merge pull request #148 from aodn/features/5905-grid-land-debug
Browse files Browse the repository at this point in the history
Features/5905 grid land debug
  • Loading branch information
HavierD authored Oct 2, 2024
2 parents 1aab5ab + 0fc1ef0 commit 0e72b33
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}
Expand Down Expand Up @@ -283,7 +291,7 @@ protected static List<Geometry> breakLargeGeometryToGrid(final Geometry large) {

// Hard code cell size, we can adjust the break grid size. 10.0 result in 3x3 grid
// cover Australia
List<Polygon> gridPolygons = createGridPolygons(envelope, getCellSize());
List<Polygon> gridPolygons = createGridPolygons(envelope, getGridSize());

// List to store Future objects representing the results of the tasks
List<Future<Geometry>> futureResults = new ArrayList<>();
Expand Down Expand Up @@ -507,7 +515,11 @@ public static List<List<BigDecimal>> createCentroidFrom(List<List<AbstractEXGeog
// This line will cause the spatial extents to break into grid, it may help to debug but will make production
// slow and sometimes cause polygon break.
// List<List<Geometry>> polygonNoLand = splitAreaToGrid(createGeometryWithoutLand(rawInput));
List<List<Geometry>> polygonNoLand = GeometryBase.findPolygonsFrom(GeometryBase.COORDINATE_SYSTEM_CRS84, rawInput);
return (polygonNoLand != null && !polygonNoLand.isEmpty()) ? createGeoJson(polygonNoLand) : null;
List<List<Geometry>> 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;
}
}
4 changes: 4 additions & 0 deletions indexer/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
server:
port: 8081

app:
geometry:
enableGridSpatialExtents: true

elasticsearch:
index:
name: dev_portal_records
Expand Down
4 changes: 4 additions & 0 deletions indexer/src/main/resources/application-edge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ spring:
git:
location: "classpath:git.properties"

app:
geometry:
enableGridSpatialExtents: true

management:
endpoints:
web:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e72b33

Please sign in to comment.