Search in sources :

Example 21 with Ring

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

the class GeometryParser method readPolygonText.

/**
 * Creates a <code>SurfaceBoundary</code> using the next token in the stream.
 *
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 *                  format. The next tokens must form a &lt;Polygon Text&gt;.
 * @return a <code>Surface</code> specified by the vertices in the stream
 * @throws ParseException if the coordinates used to create the <code>Polygon</code>
 *                        shell and holes do not form closed linestrings, or if an unexpected
 *                        token was encountered.
 * @throws IOException    if an I/O error occurs
 */
private Surface readPolygonText(final StreamTokenizer tokenizer) throws IOException, ParseException {
    String nextToken = getNextEmptyOrOpener(tokenizer);
    if (nextToken.equals(EMPTY)) {
        return null;
    }
    Curve curve = readLinearRingText(tokenizer);
    List<OrientableCurve> curveList = Collections.singletonList((OrientableCurve) curve);
    Ring shell = primitiveFactory.createRing(curveList);
    // Ring shell = readLinearRingText(tokenizer);
    List<Ring> holes = new ArrayList<Ring>();
    nextToken = getNextCloserOrComma(tokenizer);
    while (nextToken.equals(COMMA)) {
        Curve holecurve = readLinearRingText(tokenizer);
        List<OrientableCurve> holeList = Collections.singletonList((OrientableCurve) holecurve);
        Ring hole = primitiveFactory.createRing(holeList);
        // Ring hole = readLinearRingText(tokenizer);
        holes.add(hole);
        nextToken = getNextCloserOrComma(tokenizer);
    }
    SurfaceBoundary sb = primitiveFactory.createSurfaceBoundary(shell, holes);
    return primitiveFactory.createSurface(sb);
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) Curve(org.opengis.geometry.primitive.Curve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) ArrayList(java.util.ArrayList) LineString(org.opengis.geometry.coordinate.LineString) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve)

Example 22 with Ring

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

the class GeometryUtils method createSurfaceBoundary.

private static SurfaceBoundary createSurfaceBoundary(final PrimitiveFactory primitiveFactory, final DirectPosition[] exteriorRingPoints, final DirectPosition[][] interiorRingsPoints) {
    final Ring exteriorRing = createRing(primitiveFactory, exteriorRingPoints);
    final List interiorRingList = interiorRingsPoints.length == 0 ? Collections.EMPTY_LIST : new ArrayList();
    for (int i = 0; i < interiorRingsPoints.length; i++) {
        interiorRingList.add(createRing(primitiveFactory, interiorRingsPoints[i]));
    }
    final SurfaceBoundary surfaceBoundary = primitiveFactory.createSurfaceBoundary(exteriorRing, interiorRingList);
    return surfaceBoundary;
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with Ring

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

the class GeometryUtils method createRing.

private static Ring createRing(final PrimitiveFactory primitiveFactory, final DirectPosition[] points) {
    final List curveList = Collections.singletonList(createCurve(primitiveFactory, points));
    final Ring ring = primitiveFactory.createRing(curveList);
    return ring;
}
Also used : Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with Ring

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

the class GeometryUtils method getExteriorDirectPositions.

public static DirectPosition[] getExteriorDirectPositions(final Polygon polygon) {
    final SurfaceBoundary surfaceBoundary = polygon.getBoundary();
    final Ring exteriorRing = surfaceBoundary.getExterior();
    return GeometryUtils.getDirectPositions(exteriorRing);
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring)

Example 25 with Ring

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

the class JTSUtils method linearRingToRing.

public static Ring linearRingToRing(final org.locationtech.jts.geom.LineString jtsLinearRing, final CoordinateReferenceSystem crs) {
    int numPoints = jtsLinearRing.getNumPoints();
    if (numPoints != 0 && !jtsLinearRing.getCoordinateN(0).equals(jtsLinearRing.getCoordinateN(numPoints - 1))) {
        throw new IllegalArgumentException("LineString must be a ring");
    }
    // FactoryFinder.getPrimitiveFactory(hints);
    PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
    // FactoryFinder.getGeometryFactory(hints);
    GeometryFactory gf = new JTSGeometryFactory(crs);
    LineString ls = gf.createLineString(new ArrayList());
    List pointList = ls.getControlPoints();
    for (int i = 0; i < numPoints; i++) {
        pointList.add(coordinateToDirectPosition(jtsLinearRing.getCoordinateN(i), crs));
    }
    Curve curve = pf.createCurve(new ArrayList());
    // Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
    ((List) curve.getSegments()).add(ls);
    Ring result = pf.createRing(new ArrayList());
    // Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
    ((List) result.getGenerators()).add(curve);
    return result;
}
Also used : JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) Curve(org.opengis.geometry.primitive.Curve) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) ArrayList(java.util.ArrayList) List(java.util.List) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint)

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