Search in sources :

Example 1 with PointArray

use of org.opengis.geometry.coordinate.PointArray in project geotoolkit by Geomatys.

the class GeometryUtils method getDirectPositions.

public static DirectPosition[] getDirectPositions(final LineString lineString) {
    final PointArray controlPoints = lineString.getControlPoints();
    final DirectPosition[] returnable = new DirectPosition[controlPoints.size()];
    for (int i = 0; i < controlPoints.size(); i++) {
        returnable[i] = controlPoints.getDirectPosition(i, null);
    }
    return returnable;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) PointArray(org.opengis.geometry.coordinate.PointArray)

Example 2 with PointArray

use of org.opengis.geometry.coordinate.PointArray 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 3 with PointArray

use of org.opengis.geometry.coordinate.PointArray in project geotoolkit by Geomatys.

the class JTSPositionFactory method createPositionList.

public List createPositionList(final float[] coordinates, final int start, final int end) {
    PointArray array = new JTSPointArray(crs);
    int N = crs.getCoordinateSystem().getDimension();
    for (int i = start; i < end; i += N) {
        double[] ords = new double[N];
        System.arraycopy(coordinates, i, ords, 0, N);
        array.add(createDirectPosition(ords));
    }
    return array;
}
Also used : JTSPointArray(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPointArray) PointArray(org.opengis.geometry.coordinate.PointArray) JTSPointArray(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPointArray)

Example 4 with PointArray

use of org.opengis.geometry.coordinate.PointArray 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 5 with PointArray

use of org.opengis.geometry.coordinate.PointArray 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)

Aggregations

PointArray (org.opengis.geometry.coordinate.PointArray)13 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)7 ArrayList (java.util.ArrayList)6 Ring (org.opengis.geometry.primitive.Ring)6 DirectPosition (org.opengis.geometry.DirectPosition)5 CurveSegment (org.opengis.geometry.primitive.CurveSegment)5 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)4 JTSPointArray (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPointArray)4 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)4 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)4 Primitive (org.opengis.geometry.primitive.Primitive)4 List (java.util.List)3 JTSRing (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing)3 LineString (org.opengis.geometry.coordinate.LineString)3 Position (org.opengis.geometry.coordinate.Position)3 SurfaceBoundary (org.opengis.geometry.primitive.SurfaceBoundary)3 JTSSurfaceBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary)2 Geometry (org.opengis.geometry.Geometry)2 Polygon (org.opengis.geometry.coordinate.Polygon)2 Curve (org.opengis.geometry.primitive.Curve)2