Search in sources :

Example 1 with LineString

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

the class GeometryParser method readLinearRingText.

/**
 * Creates a <code>Curve</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;LineString Text&gt;.
 * @return a <code>Curve</code> specified by the next
 *         token in the stream
 * @throws IOException    if an I/O error occurs
 * @throws ParseException if the coordinates used to create the <code>Curve</code>
 *                        do not form a closed linestring, or if an unexpected token was
 *                        encountered
 */
private Curve readLinearRingText(final StreamTokenizer tokenizer) throws IOException, ParseException {
    List<Position> coordList = getCoordinates(tokenizer);
    LineString lineString = geometryFactory.createLineString(coordList);
    List<CurveSegment> curveSegmentList = Collections.singletonList((CurveSegment) lineString);
    return primitiveFactory.createCurve(curveSegmentList);
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment) Position(org.opengis.geometry.coordinate.Position) DirectPosition(org.opengis.geometry.DirectPosition) LineString(org.opengis.geometry.coordinate.LineString)

Example 2 with LineString

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

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

Example 4 with LineString

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

the class GeometryParser method readLineStringText.

/**
 * Creates a <code>LineString</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;LineString Text&gt;.
 * @return a <code>LineString</code> specified by the next
 *         token in the stream
 * @throws IOException    if an I/O error occurs
 * @throws ParseException if an unexpected token was encountered
 */
private Curve readLineStringText(final StreamTokenizer tokenizer) throws IOException, ParseException {
    final List<Position> coordList = getCoordinates(tokenizer);
    final LineString lineString = geometryFactory.createLineString(coordList);
    final List<CurveSegment> curveSegmentList = Collections.singletonList((CurveSegment) lineString);
    return primitiveFactory.createCurve(curveSegmentList);
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment) Position(org.opengis.geometry.coordinate.Position) DirectPosition(org.opengis.geometry.DirectPosition) LineString(org.opengis.geometry.coordinate.LineString)

Example 5 with LineString

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

the class GeometryUtils method getLineCharSequences.

/**
 * Recursively populates the specified List with LineCharSequences corresponding
 * to the primitive elements of the specified CompositeCurve.
 * Returns null if any element of the CompositeCurve cannot be converted
 * to a LineString.
 * @param cc The CompositeCurve of interest
 * @param lsList The ArrayList to be populated
 * @return The populated List, or null if not valid
 */
private static ArrayList getLineCharSequences(final CompositeCurve cc, final ArrayList lsList) {
    // Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
    List elements = (List) cc.getGenerators();
    boolean valid = true;
    if (!elements.isEmpty()) {
        Iterator it = elements.iterator();
        LineString ls = null;
        while (it.hasNext() && valid) {
            Object element = it.next();
            if (element instanceof CompositeCurve) {
                valid = getLineCharSequences((CompositeCurve) element, lsList) != null;
            } else if (element instanceof Curve) {
                // PENDING(NL):  When we have arc geometries implemented,
                // make provision to pass in real parameters for spacing and offset.
                // What we have below essentially just returns start and end points
                // if it's not a LineString
                ls = ((Curve) element).asLineString(Double.MAX_VALUE, Double.MAX_VALUE);
                if (ls != null) {
                    lsList.add(ls);
                } else {
                    valid = false;
                }
            } else {
                valid = false;
            }
        }
    }
    if (valid) {
        return null;
    }
    return lsList;
}
Also used : LineString(org.opengis.geometry.coordinate.LineString) Iterator(java.util.Iterator) Curve(org.opengis.geometry.primitive.Curve) CompositeCurve(org.opengis.geometry.complex.CompositeCurve) CompositeCurve(org.opengis.geometry.complex.CompositeCurve) ArrayList(java.util.ArrayList) List(java.util.List)

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