Skip to content

Commit

Permalink
Merge pull request #168 from aodn/features/6008-simplify-polygon
Browse files Browse the repository at this point in the history
Reduce precision default value
  • Loading branch information
utas-raymondng authored Nov 19, 2024
2 parents 6197be9 + c5d3ed7 commit 6d820b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6d820b3

Please sign in to comment.