Search in sources :

Example 1 with Ring

use of org.opengis.geometry.primitive.Ring in project sldeditor by robward-scisys.

the class WKTConversion method parseWKTSurface.

/**
 * Parses the WKT surface.
 *
 * @param wktGeometry the wkt geometry
 * @param geometry the geometry
 */
private static void parseWKTSurface(WKTGeometry wktGeometry, org.opengis.geometry.Geometry geometry) {
    wktGeometry.setGeometryType(getWKTType(WKT_POLYGON));
    SurfaceImpl surfaceImpl = (SurfaceImpl) geometry;
    for (Ring ring : surfaceImpl.getBoundaryRings()) {
        WKTSegmentList ptList = new WKTSegmentList();
        wktGeometry.addSegmentList(0, ptList);
        for (Primitive primitive : ring.getElements()) {
            if (primitive instanceof CurveImpl) {
                CurveImpl curve = (CurveImpl) primitive;
                extractLineSegments(curve, ptList);
            }
        }
    }
}
Also used : Primitive(org.opengis.geometry.primitive.Primitive) Ring(org.opengis.geometry.primitive.Ring) CurveImpl(org.geotools.geometry.iso.primitive.CurveImpl) SurfaceImpl(org.geotools.geometry.iso.primitive.SurfaceImpl)

Example 2 with Ring

use of org.opengis.geometry.primitive.Ring in project geotoolkit by Geomatys.

the class GeometryUtils method createPolygon.

public static Polygon createPolygon(final DirectPosition[] exteriorRingPoints, final DirectPosition[][] interiorRingsPoints) {
    final CoordinateReferenceSystem crs = exteriorRingPoints[0].getCoordinateReferenceSystem();
    final GeometryFactory geometryFactory = new JTSGeometryFactory(crs);
    final PrimitiveFactory primitiveFactory = new JTSPrimitiveFactory(crs);
    final Ring exteriorRing = createRing(primitiveFactory, exteriorRingPoints);
    List interiorRingList = interiorRingsPoints.length == 0 ? Collections.EMPTY_LIST : new ArrayList(interiorRingsPoints.length);
    for (int i = 0; i < interiorRingsPoints.length; i++) {
        final DirectPosition[] interiorRingPoints = interiorRingsPoints[i];
        interiorRingList.add(createRing(primitiveFactory, interiorRingPoints));
    }
    final SurfaceBoundary surfaceBoundary = primitiveFactory.createSurfaceBoundary(exteriorRing, interiorRingList);
    return geometryFactory.createPolygon(surfaceBoundary);
}
Also used : JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) DirectPosition(org.opengis.geometry.DirectPosition) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory)

Example 3 with Ring

use of org.opengis.geometry.primitive.Ring in project geotoolkit by Geomatys.

the class GeometryUtils method getInteriorDirectPositions.

public static DirectPosition[][] getInteriorDirectPositions(final Polygon polygon) {
    final SurfaceBoundary surfaceBoundary = polygon.getBoundary();
    final List interiorRings = surfaceBoundary.getInteriors();
    final DirectPosition[][] returnable = new DirectPosition[interiorRings.size()][];
    for (int i = 0; i < interiorRings.size(); i++) {
        returnable[i] = getDirectPositions((Ring) interiorRings.get(i));
    }
    return returnable;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Ring

use of org.opengis.geometry.primitive.Ring in project geotoolkit by Geomatys.

the class JTSUtils method toISO.

/**
 * Creates a 19107 primitive geometry from the given JTS geometry.
 */
public static Geometry toISO(final org.locationtech.jts.geom.Geometry jtsGeom, CoordinateReferenceSystem crs) {
    if (jtsGeom == null) {
        return null;
    }
    if (crs == null) {
        // try to extract the crs from the srid
        final int srid = jtsGeom.getSRID();
        if (srid != 0) {
            final String strCRS = SRIDGenerator.toSRS(srid, SRIDGenerator.Version.V1);
            try {
                crs = CRS.forCode(strCRS);
            } catch (FactoryException ex) {
                Logger.getLogger("org.geotoolkit.geometry.isoonjts").log(Level.SEVERE, null, ex);
            }
        }
    }
    // TODO use factory finder when primitive factory and geometry factory are ready.
    // FactoryFinder.getPrimitiveFactory(hints);
    final PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
    // FactoryFinder.getGeometryFactory(hints);
    final GeometryFactory gf = new JTSGeometryFactory(crs);
    if (jtsGeom instanceof org.locationtech.jts.geom.Point) {
        org.locationtech.jts.geom.Point candidate = (org.locationtech.jts.geom.Point) jtsGeom;
        DirectPosition dp = pointToDirectPosition(candidate, crs);
        return pf.createPoint(dp);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LineString) {
        org.locationtech.jts.geom.LineString candidate = (org.locationtech.jts.geom.LineString) jtsGeom;
        LineString ls = gf.createLineString(new ArrayList<Position>());
        PointArray pointList = ls.getControlPoints();
        for (int i = 0, n = candidate.getNumPoints(); i < n; i++) {
            pointList.add(coordinateToDirectPosition(candidate.getCoordinateN(i), crs));
        }
        return (JTSLineString) ls;
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LinearRing) {
        return linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsGeom, crs);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.Polygon) {
        org.locationtech.jts.geom.Polygon jtsPolygon = (org.locationtech.jts.geom.Polygon) jtsGeom;
        Ring externalRing = linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getExteriorRing(), crs);
        ArrayList internalRings = new ArrayList();
        for (int i = 0, n = jtsPolygon.getNumInteriorRing(); i < n; i++) {
            internalRings.add(linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getInteriorRingN(i), crs));
        }
        SurfaceBoundary boundary = pf.createSurfaceBoundary(externalRing, internalRings);
        Polygon polygon = gf.createPolygon(boundary);
        return (JTSPolygon) polygon;
    /*ArrayList<Polygon> patches = new ArrayList<Polygon>();
            patches.add(polygon);
            PolyhedralSurface result = gf.createPolyhedralSurface(patches);
            return result;*/
    } else if (jtsGeom instanceof GeometryCollection) {
        org.locationtech.jts.geom.GeometryCollection jtsCollection = (org.locationtech.jts.geom.GeometryCollection) jtsGeom;
        boolean multiPoint = jtsGeom instanceof MultiPoint;
        boolean multiCurve = jtsGeom instanceof MultiLineString;
        boolean multiSurface = jtsGeom instanceof MultiPolygon;
        // determine it by analyzing its content.
        if (!(multiPoint || multiCurve || multiSurface || jtsGeom.isEmpty())) {
            multiPoint = multiCurve = multiSurface = true;
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n && (multiPoint || multiCurve || multiSurface); i++) {
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Point)) {
                    multiPoint = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.LineString)) {
                    multiCurve = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Polygon)) {
                    multiSurface = false;
                }
            }
        }
        AbstractJTSAggregate result;
        if (multiPoint) {
            result = new JTSMultiPoint(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else if (multiCurve) {
            result = new JTSMultiCurve(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                Geometry element = toISO(jtsCollection.getGeometryN(i), crs);
                if (element instanceof JTSLineString) {
                    JTSCurve curve = new JTSCurve(crs);
                    curve.getSegments().add((JTSLineString) element);
                    element = curve;
                }
                elements.add(element);
            }
        } else if (multiSurface) {
            result = new JTSMultiSurface(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else {
            result = new JTSMultiPrimitive();
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Unsupported geometry type: " + jtsGeom.getGeometryType());
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) MultiLineString(org.locationtech.jts.geom.MultiLineString) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) Set(java.util.Set) FactoryException(org.opengis.util.FactoryException) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) ArrayList(java.util.ArrayList) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) Polygon(org.opengis.geometry.coordinate.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) AbstractJTSAggregate(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.AbstractJTSAggregate) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) JTSMultiSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiSurface) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) PointArray(org.opengis.geometry.coordinate.PointArray) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSMultiPrimitive(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.opengis.geometry.Geometry) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Ring(org.opengis.geometry.primitive.Ring)

Example 5 with Ring

use of org.opengis.geometry.primitive.Ring 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.");
    }
}
Also used : JTSSurfaceBoundary(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSCurveBoundary(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurveBoundary) Ring(org.opengis.geometry.primitive.Ring) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

Ring (org.opengis.geometry.primitive.Ring)28 ArrayList (java.util.ArrayList)14 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)13 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)13 DirectPosition (org.opengis.geometry.DirectPosition)13 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)12 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)12 JTSRing (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing)11 JTSSurfaceBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary)11 SurfaceBoundary (org.opengis.geometry.primitive.SurfaceBoundary)11 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)11 List (java.util.List)9 PointArray (org.opengis.geometry.coordinate.PointArray)6 CurveSegment (org.opengis.geometry.primitive.CurveSegment)6 Primitive (org.opengis.geometry.primitive.Primitive)6 JTSPolyhedralSurface (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPolyhedralSurface)5 StringReader (java.io.StringReader)4 StringWriter (java.io.StringWriter)4 JTSGeometryFactory (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory)4 JTSPrimitiveFactory (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory)4