Search in sources :

Example 1 with MultiCurve

use of org.geotoolkit.gml.xml.MultiCurve in project geotoolkit by Geomatys.

the class JAXPStreamFeatureWriter method setId.

/**
 * @param inc auto increment value, ids must be unique
 */
private void setId(AbstractGeometry gmlGeometry, String id) {
    if (gmlGeometry.getId() == null || gmlGeometry.getId().isEmpty()) {
        // do not override ids if they exist
        gmlGeometry.setId(id + (gidInc));
        gidInc++;
    }
    if (gmlGeometry instanceof MultiCurve) {
        for (CurveProperty po : ((MultiCurve) gmlGeometry).getCurveMember()) {
            final AbstractCurve child = po.getAbstractCurve();
            if (child instanceof AbstractGeometry) {
                setId((AbstractGeometry) child, id);
            }
        }
    } else if (gmlGeometry instanceof MultiSurface) {
        for (SurfaceProperty po : ((MultiSurface) gmlGeometry).getSurfaceMember()) {
            final AbstractSurface child = po.getAbstractSurface();
            if (child instanceof AbstractGeometry) {
                setId((AbstractGeometry) child, id);
            }
        }
    } else if (gmlGeometry instanceof MultiGeometryType) {
        for (GeometryPropertyType po : ((MultiGeometryType) gmlGeometry).getGeometryMember()) {
            final AbstractGeometryType child = po.getAbstractGeometry();
            if (child instanceof AbstractGeometry) {
                setId((AbstractGeometry) child, id);
            }
        }
    } else if (gmlGeometry instanceof MultiSolidType) {
        for (SolidPropertyType po : ((MultiSolidType) gmlGeometry).getSolidMember()) {
            final AbstractSolidType child = po.getAbstractSolid().getValue();
            if (child instanceof AbstractGeometry) {
                setId((AbstractGeometry) child, id);
            }
        }
    } else if (gmlGeometry instanceof MultiPointType) {
        for (PointPropertyType po : ((MultiPointType) gmlGeometry).getPointMember()) {
            final PointType child = po.getPoint();
            if (child instanceof AbstractGeometry) {
                setId((AbstractGeometry) child, id);
            }
        }
    }
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) MultiSurface(org.geotoolkit.gml.xml.MultiSurface) AbstractGeometryType(org.geotoolkit.gml.xml.v321.AbstractGeometryType) MultiGeometryType(org.geotoolkit.gml.xml.v321.MultiGeometryType) MultiPointType(org.geotoolkit.gml.xml.v321.MultiPointType) AbstractSurface(org.geotoolkit.gml.xml.AbstractSurface) CurveProperty(org.geotoolkit.gml.xml.CurveProperty) AbstractSolidType(org.geotoolkit.gml.xml.v321.AbstractSolidType) MultiCurve(org.geotoolkit.gml.xml.MultiCurve) SurfaceProperty(org.geotoolkit.gml.xml.SurfaceProperty) SolidPropertyType(org.geotoolkit.gml.xml.v321.SolidPropertyType) PointType(org.geotoolkit.gml.xml.v321.PointType) MultiPointType(org.geotoolkit.gml.xml.v321.MultiPointType) AbstractCurve(org.geotoolkit.gml.xml.AbstractCurve) PointPropertyType(org.geotoolkit.gml.xml.v321.PointPropertyType) GeometryPropertyType(org.geotoolkit.gml.xml.v321.GeometryPropertyType) MultiSolidType(org.geotoolkit.gml.xml.v321.MultiSolidType)

Example 2 with MultiCurve

use of org.geotoolkit.gml.xml.MultiCurve in project geotoolkit by Geomatys.

the class GeometryTransformer method get.

/**
 * Procede to conversion from GML to JTS.
 * @return Created JTS geometry. Never null, but can be an emptry geometry.
 * @throws UnconvertibleObjectException If we don't know how to process
 * source GML geometry.
 */
@Override
public Geometry get() throws UnconvertibleObjectException {
    Geometry geometry;
    /*
         * SIMPLE CASES
         */
    if (source instanceof org.geotoolkit.gml.xml.Point) {
        geometry = accumulateAndBuild(coords -> (coords.length > 0 ? GF.createPoint(coords[0]) : GF.createPoint((Coordinate) null)));
    } else if (source instanceof org.geotoolkit.gml.xml.LineString) {
        geometry = accumulateAndBuild(GF::createLineString);
    } else if (source instanceof org.geotoolkit.gml.xml.LinearRing) {
        geometry = accumulateAndBuild(GF::createLinearRing);
    } else if (source instanceof Curve) {
        geometry = convertCurve((Curve) source);
    } else if (source instanceof Envelope) {
        geometry = convertEnvelope((Envelope) source);
    /*
             * COMPOSED GEOMETRIES
             */
    } else if (source instanceof org.geotoolkit.gml.xml.Ring) {
        geometry = convertRing((Ring) source);
    } else if (source instanceof org.geotoolkit.gml.xml.Polygon) {
        geometry = convertPolygon((org.geotoolkit.gml.xml.Polygon) source);
        if (isForceMultiPolygon()) {
            Polygon[] polys = { (Polygon) geometry };
            final MultiPolygon result = GF.createMultiPolygon(polys);
            applyCRS(result);
            geometry = result;
        }
    } else if (source instanceof AbstractSurface) {
        if (source instanceof SurfaceType) {
            geometry = convertSurface((SurfaceType) source);
        } else if (source instanceof org.geotoolkit.gml.xml.v311.SurfaceType) {
            geometry = convertSurface((org.geotoolkit.gml.xml.v311.SurfaceType) source);
        } else // TODO : complex case
        {
            throw new IllegalArgumentException("Unsupported geometry type : " + source.getClass());
        }
    /*
             * GEOMETRY COLLECTIONS
             */
    } else if (source instanceof org.geotoolkit.gml.xml.MultiPoint) {
        geometry = convertMultiPoint((org.geotoolkit.gml.xml.MultiPoint) source);
    } else if (source instanceof org.geotoolkit.gml.xml.MultiLineString) {
        geometry = convertMultiLineString((org.geotoolkit.gml.xml.MultiLineString) source);
    } else if (source instanceof MultiCurve) {
        geometry = convertMultiCurve((MultiCurve) source);
    } else if (source instanceof org.geotoolkit.gml.xml.MultiPolygon) {
        geometry = convertMultiPolygon((org.geotoolkit.gml.xml.MultiPolygon) source);
    } else if (source instanceof MultiSurface) {
        geometry = convertMultiSurface((MultiSurface) source);
    } else if (source instanceof MultiGeometry) {
        geometry = convertMultiGeometry((MultiGeometry) source);
    } else {
        throw new IllegalArgumentException("Unsupported geometry type : " + source.getClass());
    }
    // store identifier in user map
    final String id = source.getId();
    if (id != null && !id.isEmpty()) {
        Object userData = geometry.getUserData();
        Map values;
        if (userData instanceof Map) {
            values = (Map) userData;
        } else if (userData instanceof CoordinateReferenceSystem) {
            values = new HashMap();
            values.put(org.apache.sis.internal.feature.jts.JTS.CRS_KEY, userData);
        } else if (userData == null) {
            values = new HashMap();
        } else {
            throw new IllegalArgumentException("Unexpected user data object : " + userData);
        }
        values.put("@id", id);
        geometry.setUserData(values);
    }
    return geometry;
}
Also used : Measure(org.apache.sis.internal.jaxb.gml.Measure) Unit(javax.measure.Unit) CRS(org.apache.sis.referencing.CRS) GeodeticCalculator(org.apache.sis.referencing.GeodeticCalculator) Spliterators(java.util.Spliterators) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Coordinate(org.locationtech.jts.geom.Coordinate) MeasureType(org.geotoolkit.gml.xml.v321.MeasureType) PolygonPatchType(org.geotoolkit.gml.xml.v321.PolygonPatchType) Envelope(org.geotoolkit.gml.xml.Envelope) Matcher(java.util.regex.Matcher) SingleCRS(org.opengis.referencing.crs.SingleCRS) GeometryProperty(org.geotoolkit.gml.xml.GeometryProperty) Map(java.util.Map) Ring(org.geotoolkit.gml.xml.Ring) TransformException(org.opengis.referencing.operation.TransformException) MultiLineString(org.locationtech.jts.geom.MultiLineString) AxesConvention(org.apache.sis.referencing.cs.AxesConvention) AbstractCRS(org.apache.sis.referencing.crs.AbstractCRS) Logger(java.util.logging.Logger) MultiSurface(org.geotoolkit.gml.xml.MultiSurface) Objects(java.util.Objects) Cache(org.apache.sis.util.collection.Cache) List(java.util.List) Stream(java.util.stream.Stream) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Polygon(org.locationtech.jts.geom.Polygon) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) SurfaceType(org.geotoolkit.gml.xml.v321.SurfaceType) Pattern(java.util.regex.Pattern) Spliterator(java.util.Spliterator) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) FactoryException(org.opengis.util.FactoryException) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Coordinates(org.geotoolkit.gml.xml.Coordinates) PointProperty(org.geotoolkit.gml.xml.PointProperty) ArgumentChecks(org.apache.sis.util.ArgumentChecks) DoubleFunction(java.util.function.DoubleFunction) LinearRing(org.locationtech.jts.geom.LinearRing) HashMap(java.util.HashMap) DirectPositionList(org.geotoolkit.gml.xml.DirectPositionList) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CurveProperty(org.geotoolkit.gml.xml.CurveProperty) MultiGeometry(org.geotoolkit.gml.xml.MultiGeometry) ArrayList(java.util.ArrayList) Angle(javax.measure.quantity.Angle) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Length(javax.measure.quantity.Length) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) AbstractCurveSegment(org.geotoolkit.gml.xml.AbstractCurveSegment) WithCoordinates(org.geotoolkit.gml.xml.WithCoordinates) AxisDirections(org.apache.sis.internal.referencing.AxisDirections) PointPropertyType(org.geotoolkit.gml.xml.v321.PointPropertyType) CurveSegmentArrayProperty(org.geotoolkit.gml.xml.CurveSegmentArrayProperty) StreamSupport(java.util.stream.StreamSupport) Point(org.geotoolkit.gml.xml.Point) NoSuchElementException(java.util.NoSuchElementException) DirectPosition(org.opengis.geometry.DirectPosition) Units(org.apache.sis.measure.Units) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Iterator(java.util.Iterator) PolygonProperty(org.geotoolkit.gml.xml.PolygonProperty) JTS(org.geotoolkit.geometry.jts.JTS) AbstractSurface(org.geotoolkit.gml.xml.AbstractSurface) Consumer(java.util.function.Consumer) MultiCurve(org.geotoolkit.gml.xml.MultiCurve) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) LineString(org.locationtech.jts.geom.LineString) AbstractMap(java.util.AbstractMap) ArcByCenterPointType(org.geotoolkit.gml.xml.v321.ArcByCenterPointType) Curve(org.geotoolkit.gml.xml.Curve) AbstractRingProperty(org.geotoolkit.gml.xml.AbstractRingProperty) MultiPoint(org.locationtech.jts.geom.MultiPoint) SurfaceProperty(org.geotoolkit.gml.xml.SurfaceProperty) Collections(java.util.Collections) LineStringProperty(org.geotoolkit.gml.xml.LineStringProperty) AbstractRing(org.geotoolkit.gml.xml.AbstractRing) MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiSurface(org.geotoolkit.gml.xml.MultiSurface) HashMap(java.util.HashMap) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Envelope(org.geotoolkit.gml.xml.Envelope) MultiCurve(org.geotoolkit.gml.xml.MultiCurve) Ring(org.geotoolkit.gml.xml.Ring) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiCurve(org.geotoolkit.gml.xml.MultiCurve) Curve(org.geotoolkit.gml.xml.Curve) Point(org.geotoolkit.gml.xml.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) SurfaceType(org.geotoolkit.gml.xml.v321.SurfaceType) AbstractSurface(org.geotoolkit.gml.xml.AbstractSurface) Geometry(org.locationtech.jts.geom.Geometry) MultiGeometry(org.geotoolkit.gml.xml.MultiGeometry) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiGeometry(org.geotoolkit.gml.xml.MultiGeometry) LinearRing(org.locationtech.jts.geom.LinearRing) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 3 with MultiCurve

use of org.geotoolkit.gml.xml.MultiCurve in project geotoolkit by Geomatys.

the class GeometryTransformer method convertMultiCurve.

private MultiLineString convertMultiCurve(final MultiCurve mc) {
    final LineString[] lines;
    try {
        lines = extractCurves(mc.getCurveMember().stream()).map(GeometryTransformer::get).map(LineString.class::cast).toArray(size -> new LineString[size]);
    } catch (ClassCastException e) {
        throw new UnconvertibleObjectException("Cannot create a multi-curve, because some of its components are not lines", e);
    }
    final MultiLineString mls = GF.createMultiLineString(lines);
    applyCRS(mls);
    return mls;
}
Also used : Measure(org.apache.sis.internal.jaxb.gml.Measure) Unit(javax.measure.Unit) CRS(org.apache.sis.referencing.CRS) GeodeticCalculator(org.apache.sis.referencing.GeodeticCalculator) Spliterators(java.util.Spliterators) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Coordinate(org.locationtech.jts.geom.Coordinate) MeasureType(org.geotoolkit.gml.xml.v321.MeasureType) PolygonPatchType(org.geotoolkit.gml.xml.v321.PolygonPatchType) Envelope(org.geotoolkit.gml.xml.Envelope) Matcher(java.util.regex.Matcher) SingleCRS(org.opengis.referencing.crs.SingleCRS) GeometryProperty(org.geotoolkit.gml.xml.GeometryProperty) Map(java.util.Map) Ring(org.geotoolkit.gml.xml.Ring) TransformException(org.opengis.referencing.operation.TransformException) MultiLineString(org.locationtech.jts.geom.MultiLineString) AxesConvention(org.apache.sis.referencing.cs.AxesConvention) AbstractCRS(org.apache.sis.referencing.crs.AbstractCRS) Logger(java.util.logging.Logger) MultiSurface(org.geotoolkit.gml.xml.MultiSurface) Objects(java.util.Objects) Cache(org.apache.sis.util.collection.Cache) List(java.util.List) Stream(java.util.stream.Stream) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Polygon(org.locationtech.jts.geom.Polygon) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) SurfaceType(org.geotoolkit.gml.xml.v321.SurfaceType) Pattern(java.util.regex.Pattern) Spliterator(java.util.Spliterator) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) FactoryException(org.opengis.util.FactoryException) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Coordinates(org.geotoolkit.gml.xml.Coordinates) PointProperty(org.geotoolkit.gml.xml.PointProperty) ArgumentChecks(org.apache.sis.util.ArgumentChecks) DoubleFunction(java.util.function.DoubleFunction) LinearRing(org.locationtech.jts.geom.LinearRing) HashMap(java.util.HashMap) DirectPositionList(org.geotoolkit.gml.xml.DirectPositionList) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CurveProperty(org.geotoolkit.gml.xml.CurveProperty) MultiGeometry(org.geotoolkit.gml.xml.MultiGeometry) ArrayList(java.util.ArrayList) Angle(javax.measure.quantity.Angle) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Length(javax.measure.quantity.Length) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) AbstractCurveSegment(org.geotoolkit.gml.xml.AbstractCurveSegment) WithCoordinates(org.geotoolkit.gml.xml.WithCoordinates) AxisDirections(org.apache.sis.internal.referencing.AxisDirections) PointPropertyType(org.geotoolkit.gml.xml.v321.PointPropertyType) CurveSegmentArrayProperty(org.geotoolkit.gml.xml.CurveSegmentArrayProperty) StreamSupport(java.util.stream.StreamSupport) Point(org.geotoolkit.gml.xml.Point) NoSuchElementException(java.util.NoSuchElementException) DirectPosition(org.opengis.geometry.DirectPosition) Units(org.apache.sis.measure.Units) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Iterator(java.util.Iterator) PolygonProperty(org.geotoolkit.gml.xml.PolygonProperty) JTS(org.geotoolkit.geometry.jts.JTS) AbstractSurface(org.geotoolkit.gml.xml.AbstractSurface) Consumer(java.util.function.Consumer) MultiCurve(org.geotoolkit.gml.xml.MultiCurve) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) LineString(org.locationtech.jts.geom.LineString) AbstractMap(java.util.AbstractMap) ArcByCenterPointType(org.geotoolkit.gml.xml.v321.ArcByCenterPointType) Curve(org.geotoolkit.gml.xml.Curve) AbstractRingProperty(org.geotoolkit.gml.xml.AbstractRingProperty) MultiPoint(org.locationtech.jts.geom.MultiPoint) SurfaceProperty(org.geotoolkit.gml.xml.SurfaceProperty) Collections(java.util.Collections) LineStringProperty(org.geotoolkit.gml.xml.LineStringProperty) AbstractRing(org.geotoolkit.gml.xml.AbstractRing) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Aggregations

AbstractGeometry (org.geotoolkit.gml.xml.AbstractGeometry)3 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Spliterator (java.util.Spliterator)2 Spliterators (java.util.Spliterators)2 Consumer (java.util.function.Consumer)2 DoubleFunction (java.util.function.DoubleFunction)2 Function (java.util.function.Function)2 Supplier (java.util.function.Supplier)2 Logger (java.util.logging.Logger)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2