Search in sources :

Example 1 with AbstractRing

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

the class JTStoGeometry method toGML.

/**
 * Convert JTS Polygon to GML PolygonType
 * @param jtsGeom
 * @param crs Coordinate Reference System
 * @return PolygonType
 *
 * @throws org.opengis.referencing.NoSuchAuthorityCodeException - if {@link CoordinateReferenceSystem crs}
 * can't be injected into the {@link AbstractGeometry}.
 * @throws org.opengis.util.FactoryException - if {@link CoordinateReferenceSystem crs} can't be injected into the
 * {@link AbstractGeometry}.
 */
public static org.geotoolkit.gml.xml.Polygon toGML(final String gmlVersion, final Polygon jtsGeom, final CoordinateReferenceSystem crs) throws NoSuchAuthorityCodeException, FactoryException {
    // Test if it's a 2D Geometry from CRS
    isValideGeometry(crs);
    final String srsName = getSRS(crs);
    final int srsDimension = crs.getCoordinateSystem().getDimension();
    // get exterior ring
    final AbstractRing gmlExterior = toGML(gmlVersion, (LinearRing) jtsGeom.getExteriorRing(), crs);
    gmlExterior.setSrsName(null);
    gmlExterior.setSrsDimension(null);
    // get interiors ring
    final List<AbstractRing> gmlInterior = new ArrayList<>();
    for (int i = 0; i < jtsGeom.getNumInteriorRing(); i++) {
        org.geotoolkit.gml.xml.LinearRing interior = toGML(gmlVersion, (LinearRing) jtsGeom.getInteriorRingN(i), crs);
        interior.setSrsName(null);
        interior.setSrsDimension(null);
        gmlInterior.add(interior);
    }
    return buildPolygon(gmlVersion, gmlExterior, gmlInterior, srsName, srsDimension);
}
Also used : AbstractRing(org.geotoolkit.gml.xml.AbstractRing) ArrayList(java.util.ArrayList) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 2 with AbstractRing

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

the class GeoSpatialBound method extractBoundary.

private void extractBoundary(final AbstractGeometry geom) {
    if (geom instanceof Point) {
        final Point p = (Point) geom;
        if (p.getPos() != null) {
            addXCoordinate(p.getPos().getOrdinate(0));
            addYCoordinate(p.getPos().getOrdinate(1));
        }
    } else if (geom instanceof LineString) {
        final LineString ls = (LineString) geom;
        final Envelope env = ls.getBounds();
        if (env != null) {
            addXCoordinate(env.getMinimum(0));
            addXCoordinate(env.getMaximum(0));
            addYCoordinate(env.getMinimum(1));
            addYCoordinate(env.getMaximum(1));
        }
    } else if (geom instanceof Polygon) {
        final Polygon p = (Polygon) geom;
        AbstractRing ext = p.getExterior().getAbstractRing();
    // TODO
    }
}
Also used : AbstractRing(org.geotoolkit.gml.xml.AbstractRing) LineString(org.geotoolkit.gml.xml.LineString) Point(org.geotoolkit.gml.xml.Point) Envelope(org.geotoolkit.gml.xml.Envelope) Polygon(org.geotoolkit.gml.xml.Polygon)

Example 3 with AbstractRing

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

the class GeometryTransformer method convertPolygonLike.

private Polygon convertPolygonLike(AbstractRingProperty exteriorProperty, final List<? extends AbstractRingProperty> interiorProperties) {
    final AbstractRing exterior = exteriorProperty.getAbstractRing();
    final Geometry extRing = new GeometryTransformer(exterior, this).get();
    // Check now to avoid costly parsing of interior geometries
    if (!(extRing instanceof LinearRing)) {
        throw new UnconvertibleObjectException("Cannot create a polygon, because its exterior is not a ring");
    }
    final LinearRing[] interiors;
    try {
        final Stream<? extends AbstractRingProperty> interiorStream = interiorProperties == null ? Stream.empty() : interiorProperties.stream();
        interiors = interiorStream.map(AbstractRingProperty::getAbstractRing).map(ring -> new GeometryTransformer(ring, this).get()).map(LinearRing.class::cast).toArray(size -> new LinearRing[size]);
    } catch (ClassCastException e) {
        throw new UnconvertibleObjectException("Cannot create a polygon, because some of its interior geometries are not rings", e);
    }
    final Polygon poly = GF.createPolygon((LinearRing) extRing, interiors);
    applyCRS(poly);
    return poly;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) MultiGeometry(org.geotoolkit.gml.xml.MultiGeometry) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) 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) AbstractRing(org.geotoolkit.gml.xml.AbstractRing) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) AbstractRingProperty(org.geotoolkit.gml.xml.AbstractRingProperty) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

AbstractRing (org.geotoolkit.gml.xml.AbstractRing)3 ArrayList (java.util.ArrayList)2 Envelope (org.geotoolkit.gml.xml.Envelope)2 Point (org.geotoolkit.gml.xml.Point)2 AbstractMap (java.util.AbstractMap)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 Consumer (java.util.function.Consumer)1 DoubleFunction (java.util.function.DoubleFunction)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Logger (java.util.logging.Logger)1