use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurveBoundary in project geotoolkit by Geomatys.
the class AbstractJTSGeometry method getBoundary.
/**
* Returns the boundary of this geometry. Returns null if the boundary is
* empty.
*/
@Override
public Boundary getBoundary() {
// PENDING(CSD):
// Need to find out if MultiPrimitives are handled correctly. (I think
// they are, but 19107's boundary semantics for multi-primitives are
// not well-specified.)
// Need to find out if GeometryCollections are handled correctly. (I
// don't think they are, but it's not clear what it would mean, nor is
// it obvious why anyone would call it in the first place.)
org.locationtech.jts.geom.Geometry jtsGeom = getJTSGeometry();
// compute the boundary of a collection object in 19107.
if (jtsGeom instanceof org.locationtech.jts.geom.GeometryCollection) {
throw new UnsupportedOperationException("Boundary cannot be computed for multi-primitives.");
}
org.locationtech.jts.geom.Geometry jtsBoundary = jtsGeom.getBoundary();
int d = jtsGeom.getDimension();
if (d == 0) {
// be NULL.
return null;
} else if (d == 1) {
// If d is 1, then the boundary is either empty (if it's a ring) or
// it's two points at either end of the curve.
// We've ruled out the possibility of multi-primitives (see the
// instanceof check above), so we know that the boundary can't be
// more than 2 points.
org.locationtech.jts.geom.Coordinate[] coords = jtsBoundary.getCoordinates();
// null).
if ((coords == null) || (coords.length == 0)) {
JTSCurveBoundary result = new JTSCurveBoundary(getCoordinateReferenceSystem(), null, null);
return result;
} else {
// endpoints.
if (coords.length != 2) {
// Should this be an assert instead?
throw new RuntimeException("ERROR: One dimensional " + "primitive had wrong number of boundary points (" + coords.length + ")");
}
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
JTSCurveBoundary result = new JTSCurveBoundary(crs, new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[0], crs)), new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[1], crs)));
return result;
}
} else if (d == 2) {
// If d == 2, then the boundary is a collection of rings.
// In particular, the JTS tests indicate that it'll be a
// MultiLineString.
org.locationtech.jts.geom.MultiLineString mls = (org.locationtech.jts.geom.MultiLineString) jtsBoundary;
int n = mls.getNumGeometries();
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
Ring exteriorRing = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(0), crs);
Ring[] interiorRings = new Ring[n - 1];
for (int i = 1; i < n; i++) {
interiorRings[n - 1] = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(i), crs);
}
JTSSurfaceBoundary result = new JTSSurfaceBoundary(crs, exteriorRing, interiorRings);
return result;
} else {
throw new UnsupportedOperationException("Computing the boundary " + "for geometries of dimension larger than 2 is not " + "supported.");
}
}
Aggregations