Search in sources :

Example 11 with Ring

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

the class AbstractGeometryTest method createSurfaceBoundary.

/**
 * creates a SurfaceBoundary using a curve as the exterior
 *
 * @param exterior
 * @return <tt>SurfaceBoundary</tt>
 */
protected SurfaceBoundary createSurfaceBoundary(final Curve exterior) {
    final Ring exteriorRing = createRing(exterior);
    List interiorRingList = Collections.EMPTY_LIST;
    SurfaceBoundary surfaceBoundary = null;
    surfaceBoundary = PRIMITIVE_FACTORY.createSurfaceBoundary(exteriorRing, interiorRingList);
    return surfaceBoundary;
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with Ring

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

the class SurfaceImplTest method testLargeSurface.

/**
 * We need to create a large surface with 7000 points
 */
@Test
public void testLargeSurface() {
    int NUMBER = 100000;
    double delta = 360.0 / (double) NUMBER;
    PointArray points = postitionFactory.createPointArray();
    for (double angle = 0.0; angle < 360.0; angle += delta) {
        double[] coordinates = new double[] { Math.sin(Math.toRadians(angle)), Math.cos(Math.toRadians(angle)) };
        DirectPosition point = postitionFactory.createDirectPosition(coordinates);
        points.add(point);
    }
    List<OrientableCurve> curves = new ArrayList<OrientableCurve>();
    // A curve will be created
    // - The curve will be set as parent curves for the Curve segments
    // - Start and end params for the CurveSegments will be set
    List<CurveSegment> segmentList = new ArrayList<CurveSegment>();
    for (int i = 0; i < points.size(); i++) {
        int start = i;
        int end = (i + 1) % points.size();
        DirectPosition point1 = points.getDirectPosition(start, null);
        DirectPosition point2 = points.getDirectPosition(end, null);
        LineSegment segment = geometryFactory.createLineSegment(point1, point2);
        segmentList.add(segment);
    }
    Curve curve = primitiveFactory.createCurve(segmentList);
    curves.add(curve);
    Ring ring = primitiveFactory.createRing(curves);
    SurfaceBoundary boundary = primitiveFactory.createSurfaceBoundary(ring, new ArrayList());
    JTSSurface surface = (JTSSurface) primitiveFactory.createSurface(boundary);
    Geometry peer = surface.computeJTSPeer();
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) ArrayList(java.util.ArrayList) Curve(org.opengis.geometry.primitive.Curve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) PointArray(org.opengis.geometry.coordinate.PointArray) Geometry(org.locationtech.jts.geom.Geometry) CurveSegment(org.opengis.geometry.primitive.CurveSegment) Ring(org.opengis.geometry.primitive.Ring) LineSegment(org.opengis.geometry.coordinate.LineSegment) Test(org.junit.Test)

Example 13 with Ring

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

the class JTSPolygon method computeJTSPeer.

/**
 * {@inheritDoc }
 */
@Override
public org.locationtech.jts.geom.Geometry computeJTSPeer() {
    final SurfaceBoundary boundary = getBoundary();
    final Ring exterior = boundary.getExterior();
    final List interiors = boundary.getInteriors();
    if (exterior != null) {
        final org.locationtech.jts.geom.Geometry g = ((JTSGeometry) exterior).getJTSGeometry();
        final int numHoles = (interiors != null) ? interiors.size() : 0;
        final org.locationtech.jts.geom.LinearRing jtsExterior = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g.getCoordinates());
        final org.locationtech.jts.geom.LinearRing[] jtsInterior = new org.locationtech.jts.geom.LinearRing[numHoles];
        for (int i = 0; i < numHoles; i++) {
            final org.locationtech.jts.geom.Geometry g2 = ((JTSGeometry) interiors.get(i)).getJTSGeometry();
            jtsInterior[i] = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g2.getCoordinates());
        }
        final org.locationtech.jts.geom.Polygon result = JTSUtils.GEOMETRY_FACTORY.createPolygon(jtsExterior, jtsInterior);
        final CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
        if (crs != null) {
            final int srid = SRIDGenerator.toSRID(crs, Version.V1);
            result.setSRID(srid);
        }
        return result;
    }
    return null;
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)

Example 14 with Ring

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

the class PolyhedralSurfaceType method getIsoPolyHedralSurface.

public JTSPolyhedralSurface getIsoPolyHedralSurface() {
    JTSPolyhedralSurface result = new JTSPolyhedralSurface(coordinateReferenceSystem);
    for (JTSSurfaceBoundary s : patchList.getPatches()) {
        s.setCoordinateReferenceSystem(coordinateReferenceSystem);
        ((JTSRing) s.getExterior()).setCoordinateReferenceSystem(coordinateReferenceSystem);
        for (Primitive p : s.getExterior().getElements()) {
            if (p instanceof JTSCurve) {
                JTSCurve curve = (JTSCurve) p;
                curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
                for (CurveSegment cv : curve.getSegments()) {
                    if (cv instanceof JTSLineString) {
                        JTSLineString line = (JTSLineString) cv;
                        PointArray pa = line.getControlPoints();
                        List<Position> newPositions = new ArrayList<Position>();
                        for (Position pos : pa) {
                            if (pos instanceof GeneralDirectPosition) {
                                ((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
                                newPositions.add(pos);
                            }
                        }
                        line.getControlPoints().clear();
                        line.getControlPoints().addAll(newPositions);
                    }
                }
            }
        }
        if (s.getInteriors() != null) {
            for (Ring ring : s.getInteriors()) {
                ((JTSRing) ring).setCoordinateReferenceSystem(coordinateReferenceSystem);
                for (Primitive p : ring.getElements()) {
                    if (p instanceof JTSCurve) {
                        JTSCurve curve = (JTSCurve) p;
                        curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
                        for (CurveSegment cv : curve.getSegments()) {
                            if (cv instanceof JTSLineString) {
                                JTSLineString line = (JTSLineString) cv;
                                PointArray pa = line.getControlPoints();
                                List<Position> newPositions = new ArrayList<Position>();
                                for (Position pos : pa) {
                                    if (pos instanceof GeneralDirectPosition) {
                                        ((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
                                        newPositions.add(pos);
                                    }
                                }
                                line.getControlPoints().clear();
                                line.getControlPoints().addAll(newPositions);
                            }
                        }
                    }
                }
            }
        }
        result.getPatches().add(new JTSPolygon(s));
    }
    return result;
}
Also used : JTSPolyhedralSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPolyhedralSurface) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) Position(org.opengis.geometry.coordinate.Position) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSSurfaceBoundary(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) ArrayList(java.util.ArrayList) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) PointArray(org.opengis.geometry.coordinate.PointArray) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) Primitive(org.opengis.geometry.primitive.Primitive) CurveSegment(org.opengis.geometry.primitive.CurveSegment) JTSRing(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing) Ring(org.opengis.geometry.primitive.Ring)

Example 15 with Ring

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

the class GMLUtilities method getGMLFromISO.

/**
 * @param geometry The ISO geometry to convert.
 * @return A GML 3.1.1 geometry matching given geometry definition.
 * @deprecated This method should not be used for multiple reasons:
 * <ol>
 * <li>OpenGIS definition is based on an obsolete ISO-19107 draft</li>
 * <li>The GML version is fixed and obsolete</li>
 * <li>Only partial management of geometries</li>
 * </ol>
 */
public static AbstractGeometryType getGMLFromISO(final org.opengis.geometry.Geometry geometry) {
    if (geometry instanceof Point) {
        Point point = (Point) geometry;
        PointType gmlPoint = new PointType(null, point.getDirectPosition());
        return gmlPoint;
    } else if (geometry instanceof OrientableSurface) {
        OrientableSurface surface = (OrientableSurface) geometry;
        SurfaceBoundary boundary = surface.getBoundary();
        Ring exterior = boundary.getExterior();
        List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
        for (Primitive p : exterior.getElements()) {
            curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
        }
        RingType gmlExterior = new RingType();
        gmlExterior.getCurveMember().addAll(curves);
        List<Ring> interiors = boundary.getInteriors();
        List<RingType> gmlInteriors = new ArrayList<RingType>();
        for (Ring interior : interiors) {
            List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
            for (Primitive p : interior.getElements()) {
                intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
            }
            RingType gmlinterior = new RingType();
            gmlinterior.getCurveMember().addAll(intcurves);
            gmlInteriors.add(gmlinterior);
        }
        PolygonType poly = new PolygonType(gmlExterior, gmlInteriors);
        return poly;
    } else if (geometry instanceof MultiSurface) {
        MultiSurface multiPrim = (MultiSurface) geometry;
        List<PolygonPropertyType> geometries = new ArrayList<PolygonPropertyType>();
        for (Geometry prim : multiPrim.getElements()) {
            PolygonType element = (PolygonType) getGMLFromISO(prim);
            PolygonPropertyType gp = new PolygonPropertyType((PolygonType) element);
            geometries.add(gp);
        }
        MultiPolygonType gmlMulti = new MultiPolygonType(null, geometries);
        return gmlMulti;
    } else if (geometry instanceof MultiCurve) {
        MultiCurve multiPrim = (MultiCurve) geometry;
        List<CurvePropertyType> geometries = new ArrayList<CurvePropertyType>();
        for (OrientableCurve prim : multiPrim.getElements()) {
            AbstractCurveType element = (AbstractCurveType) getGMLFromISO(prim);
            CurvePropertyType gp = new CurvePropertyType((AbstractCurveType) element);
            geometries.add(gp);
        }
        MultiCurveType gmlMulti = new MultiCurveType(geometries);
        return gmlMulti;
    } else if (geometry instanceof MultiPoint) {
        MultiPoint multiPrim = (MultiPoint) geometry;
        List<PointPropertyType> geometries = new ArrayList<PointPropertyType>();
        for (Point prim : multiPrim.getElements()) {
            PointType element = (PointType) getGMLFromISO(prim);
            PointPropertyType gp = new PointPropertyType((PointType) element);
            geometries.add(gp);
        }
        MultiPointType gmlMulti = new MultiPointType(null, geometries);
        return gmlMulti;
    } else if (geometry instanceof MultiPrimitive) {
        MultiPrimitive multiPrim = (MultiPrimitive) geometry;
        List<GeometryPropertyType> geometries = new ArrayList<GeometryPropertyType>();
        for (Primitive prim : multiPrim.getElements()) {
            AbstractGMLType element = getGMLFromISO(prim);
            GeometryPropertyType gp = new GeometryPropertyType((AbstractGeometryType) element);
            geometries.add(gp);
        }
        MultiGeometryType gmlMulti = new MultiGeometryType(geometries);
        return gmlMulti;
    } else if (geometry instanceof Curve) {
        Curve curve = (Curve) geometry;
        List<? extends CurveSegment> segments = curve.getSegments();
        List<LineStringSegmentType> gmlSegments = new ArrayList<LineStringSegmentType>();
        for (CurveSegment segment : segments) {
            CurveInterpolationType interpolation = CurveInterpolationType.fromValue(segment.getInterpolation().identifier());
            PointArray array = GeometricUtilities.getSamplePoints(segment);
            List<DirectPosition> positions = new ArrayList<DirectPosition>();
            for (int i = 0; i < array.size(); i++) {
                positions.add(array.getDirectPosition(i, null));
            }
            LineStringSegmentType gmlSegment = new LineStringSegmentType(segment.getNumDerivativesAtStart(), segment.getNumDerivativesAtEnd(), segment.getNumDerivativesInterior(), interpolation, positions);
            gmlSegments.add(gmlSegment);
        }
        CurveType gmlCurve = new CurveType(gmlSegments);
        return gmlCurve;
    } else if (geometry instanceof LineString) {
        LineString line = (LineString) geometry;
        PointArray array = GeometricUtilities.getSamplePoints(line);
        List<DirectPosition> positions = new ArrayList<DirectPosition>();
        for (int i = 0; i < array.size(); i++) {
            positions.add(array.getDirectPosition(i, null));
        }
        LineStringType gmlLine = new LineStringType(positions);
        return gmlLine;
    } else if (geometry instanceof Polygon) {
        Polygon polygon = (Polygon) geometry;
        SurfaceBoundary boundary = polygon.getBoundary();
        Ring exterior = boundary.getExterior();
        List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
        for (Primitive p : exterior.getElements()) {
            curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
        }
        RingType gmlExterior = new RingType();
        gmlExterior.getCurveMember().addAll(curves);
        List<Ring> interiors = boundary.getInteriors();
        List<RingType> gmlInteriors = new ArrayList<RingType>();
        for (Ring interior : interiors) {
            List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
            for (Primitive p : interior.getElements()) {
                intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
            }
            RingType gmlinterior = new RingType();
            gmlinterior.getCurveMember().addAll(intcurves);
            gmlInteriors.add(gmlinterior);
        }
        PolygonType gmlPolygon = new PolygonType(gmlExterior, gmlInteriors);
        return gmlPolygon;
    } else if (geometry instanceof PolyhedralSurface) {
        PolyhedralSurface polySurface = (PolyhedralSurface) geometry;
        List<PolygonPatchType> gmlPatches = new ArrayList<PolygonPatchType>();
        List<? extends Polygon> patches = polySurface.getPatches();
        for (Polygon polygon : patches) {
            SurfaceInterpolationType interpolation = SurfaceInterpolationType.fromValue(polygon.getInterpolation().identifier());
            SurfaceBoundary boundary = polygon.getBoundary();
            Ring exterior = boundary.getExterior();
            List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
            for (Primitive p : exterior.getElements()) {
                curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
            }
            RingType gmlExterior = new RingType();
            gmlExterior.getCurveMember().addAll(curves);
            List<Ring> interiors = boundary.getInteriors();
            List<RingType> gmlInteriors = new ArrayList<RingType>();
            for (Ring interior : interiors) {
                List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
                for (Primitive p : interior.getElements()) {
                    intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
                }
                RingType gmlinterior = new RingType();
                gmlinterior.getCurveMember().addAll(intcurves);
                gmlInteriors.add(gmlinterior);
            }
            PolygonPatchType patche = new PolygonPatchType(interpolation, gmlExterior, gmlInteriors);
            gmlPatches.add(patche);
        }
        PolygonPatchArrayPropertyType pathArray = new PolygonPatchArrayPropertyType(gmlPatches);
        PolyhedralSurfaceType gmlPolySurface = new PolyhedralSurfaceType(pathArray);
        return gmlPolySurface;
    } else {
        System.out.println("unexpected iso geometry type:" + geometry.getClass().getName());
    }
    return null;
}
Also used : MultiPoint(org.opengis.geometry.aggregate.MultiPoint) DirectPosition(org.opengis.geometry.DirectPosition) MultiCurveType(org.geotoolkit.gml.xml.v311.MultiCurveType) OrientableSurface(org.opengis.geometry.primitive.OrientableSurface) ArrayList(java.util.ArrayList) MultiGeometryType(org.geotoolkit.gml.xml.v311.MultiGeometryType) MultiPrimitive(org.opengis.geometry.aggregate.MultiPrimitive) CurveSegment(org.opengis.geometry.primitive.CurveSegment) MultiCurve(org.opengis.geometry.aggregate.MultiCurve) ArrayList(java.util.ArrayList) List(java.util.List) CurvePropertyType(org.geotoolkit.gml.xml.v311.CurvePropertyType) Polygon(org.opengis.geometry.coordinate.Polygon) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) Curve(org.opengis.geometry.primitive.Curve) MultiCurve(org.opengis.geometry.aggregate.MultiCurve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) PolygonType(org.geotoolkit.gml.xml.v311.PolygonType) MultiPolygonType(org.geotoolkit.gml.xml.v311.MultiPolygonType) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) LineStringType(org.geotoolkit.gml.xml.v311.LineStringType) MultiPointType(org.geotoolkit.gml.xml.v311.MultiPointType) CurveInterpolationType(org.geotoolkit.gml.xml.v311.CurveInterpolationType) RingType(org.geotoolkit.gml.xml.v311.RingType) PolyhedralSurfaceType(org.geotoolkit.gml.xml.v311.PolyhedralSurfaceType) LineStringSegmentType(org.geotoolkit.gml.xml.v311.LineStringSegmentType) MultiSurface(org.opengis.geometry.aggregate.MultiSurface) SurfaceInterpolationType(org.geotoolkit.gml.xml.v311.SurfaceInterpolationType) AbstractCurveType(org.geotoolkit.gml.xml.v311.AbstractCurveType) MultiCurveType(org.geotoolkit.gml.xml.v311.MultiCurveType) CurveType(org.geotoolkit.gml.xml.v311.CurveType) AbstractGMLType(org.geotoolkit.gml.xml.v311.AbstractGMLType) PolygonPatchArrayPropertyType(org.geotoolkit.gml.xml.v311.PolygonPatchArrayPropertyType) MultiPrimitive(org.opengis.geometry.aggregate.MultiPrimitive) Primitive(org.opengis.geometry.primitive.Primitive) MultiPolygonType(org.geotoolkit.gml.xml.v311.MultiPolygonType) PolygonPatchType(org.geotoolkit.gml.xml.v311.PolygonPatchType) Point(org.opengis.geometry.primitive.Point) MultiPoint(org.opengis.geometry.aggregate.MultiPoint) PointArray(org.opengis.geometry.coordinate.PointArray) Point(org.opengis.geometry.primitive.Point) MultiPoint(org.opengis.geometry.aggregate.MultiPoint) PolyhedralSurface(org.opengis.geometry.coordinate.PolyhedralSurface) Geometry(org.opengis.geometry.Geometry) AbstractCurveType(org.geotoolkit.gml.xml.v311.AbstractCurveType) LineString(org.opengis.geometry.coordinate.LineString) Ring(org.opengis.geometry.primitive.Ring) PolygonPropertyType(org.geotoolkit.gml.xml.v311.PolygonPropertyType) PointType(org.geotoolkit.gml.xml.v311.PointType) MultiPointType(org.geotoolkit.gml.xml.v311.MultiPointType) PointPropertyType(org.geotoolkit.gml.xml.v311.PointPropertyType) GeometryPropertyType(org.geotoolkit.gml.xml.v311.GeometryPropertyType)

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