Skip to content

Commit

Permalink
Merge pull request #1661 from lat-lon/feature/supportPatchesDefaultSu…
Browse files Browse the repository at this point in the history
…rfaceBuildJtsGeometry-XPLANBOX-2517

Added support of patches in DefaultSurface.buildJTSGeometry() (3.5)
  • Loading branch information
copierrj authored Mar 6, 2024
2 parents f3bc25a + b2a2119 commit cd7c984
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.deegree.commons.uom.Measure;
import org.deegree.commons.uom.Unit;
Expand All @@ -55,6 +57,7 @@
import org.locationtech.jts.algorithm.InteriorPointArea;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LinearRing;
import org.locationtech.jts.geom.Polygon;

/**
* Default implementation of {@link Surface}.
Expand Down Expand Up @@ -155,13 +158,28 @@ public List<Points> getInteriorRingsCoordinates() {

@Override
protected org.locationtech.jts.geom.Geometry buildJTSGeometry() {

if (patches.size() < 1 || !(patches.get(0) instanceof PolygonPatch)) {
if (patches.size() < 1 || containsNonPolygonPatches()) {
throw new IllegalArgumentException(Messages.getMessage("SURFACE_NOT_EQUIVALENT_TO_POLYGON"));
}
if (patches.size() == 1) {
PolygonPatch patch = (PolygonPatch) patches.get(0);
return createJtsPolygon(patch);
}
Polygon[] jtsPolygons = patches.stream()
.map(patch -> createJtsPolygon((PolygonPatch) patch))
.collect(Collectors.toList())
.toArray(Polygon[]::new);
return jtsFactory.createMultiPolygon(jtsPolygons);
}

private boolean containsNonPolygonPatches() {
Optional<? extends SurfacePatch> nonPolygonPatch = patches.stream()
.filter(patch -> !(patch instanceof PolygonPatch))
.findAny();
return nonPolygonPatch.isPresent();
}

// TODO handle the other patches as well
PolygonPatch patch = (PolygonPatch) patches.get(0);
private static Polygon createJtsPolygon(PolygonPatch patch) {
Ring exteriorRing = patch.getExteriorRing();
List<Ring> interiorRings = patch.getInteriorRings();

Expand Down

0 comments on commit cd7c984

Please sign in to comment.