Search in sources :

Example 6 with LineString

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

the class GeometryUtils method getDirectPositions.

public static DirectPosition[] getDirectPositions(final Ring ring) {
    final List directPositionList = new ArrayList();
    // Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
    final List /*<Curve>*/
    generators = (List) ring.getGenerators();
    for (int i = 0; i < generators.size(); i++) {
        final Curve curve = (Curve) generators.get(i);
        final List /*<CurveSegments>*/
        segments = curve.getSegments();
        for (int j = 0; j < segments.size(); j++) {
            final CurveSegment curveSegment = (CurveSegment) segments.get(j);
            if (curveSegment instanceof LineString) {
                final LineString lineString = (LineString) curveSegment;
                final DirectPosition[] positions = getDirectPositions(lineString);
                directPositionList.addAll(Arrays.asList(positions));
            /*final List<Position> positions = lineString.getControlPoints().positions();
                    for (int k = 0; k < positions.size(); k++) {
                        Position position = (Position) positions.get(k);
                        directPositionList.add(position.getPosition());
                    }*/
            }
        }
    }
    if (directPositionList.size() > 0) {
        return (DirectPosition[]) directPositionList.toArray(new DirectPosition[directPositionList.size()]);
    }
    return new DirectPosition[0];
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) CurveSegment(org.opengis.geometry.primitive.CurveSegment) LineString(org.opengis.geometry.coordinate.LineString) ArrayList(java.util.ArrayList) Curve(org.opengis.geometry.primitive.Curve) CompositeCurve(org.opengis.geometry.complex.CompositeCurve) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with LineString

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

Example 8 with LineString

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

the class JTSGeometryFactory method createLineString.

/**
 * {@inheritDoc }
 */
@Override
public LineString createLineString(final List points) {
    LineString result = new JTSLineString(crs);
    PointArray pa = result.getControlPoints();
    List list = pa;
    Iterator it = points.iterator();
    while (it.hasNext()) {
        // Object o = it.next();
        // if (o instanceof DirectPosition) {
        // list.add(o);
        // } else if (o instanceof Position) {
        // Position p = (Position) o;
        // DirectPosition dp = p.getPosition();
        // /*if (dp == null) {
        // dp = p.getIndirect().getPosition();
        // }*/
        // list.add(dp);
        // }
        Position position = (Position) it.next();
        DirectPosition directPosition = position.getDirectPosition();
        list.add(directPosition);
    }
    return result;
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) LineString(org.opengis.geometry.coordinate.LineString) Position(org.opengis.geometry.coordinate.Position) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) Iterator(java.util.Iterator) List(java.util.List) PointArray(org.opengis.geometry.coordinate.PointArray)

Aggregations

LineString (org.opengis.geometry.coordinate.LineString)8 DirectPosition (org.opengis.geometry.DirectPosition)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CurveSegment (org.opengis.geometry.primitive.CurveSegment)4 PointArray (org.opengis.geometry.coordinate.PointArray)3 Curve (org.opengis.geometry.primitive.Curve)3 Ring (org.opengis.geometry.primitive.Ring)3 Iterator (java.util.Iterator)2 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)2 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)2 JTSMultiPoint (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint)2 JTSGeometryFactory (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory)2 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)2 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)2 JTSPrimitiveFactory (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory)2 Geometry (org.opengis.geometry.Geometry)2 CompositeCurve (org.opengis.geometry.complex.CompositeCurve)2 Polygon (org.opengis.geometry.coordinate.Polygon)2 Position (org.opengis.geometry.coordinate.Position)2