Search in sources :

Example 1 with JTSGeometry

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.

the class AbstractJTSAggregate method computeJTSPeer.

/**
 * {@inheritDoc }
 */
@Override
protected org.locationtech.jts.geom.Geometry computeJTSPeer() {
    final List<org.locationtech.jts.geom.Geometry> childParts = new ArrayList<org.locationtech.jts.geom.Geometry>();
    for (Geometry prim : elements) {
        if (prim instanceof JTSGeometry) {
            final JTSGeometry jtsGeom = (JTSGeometry) prim;
            final org.locationtech.jts.geom.Geometry geom = jtsGeom.getJTSGeometry();
            if (geom != null) {
                childParts.add(geom);
            }
        } else {
            throw new IllegalStateException("Only JTSGeometries are allowed in the JTSAggregate class.");
        }
    }
    org.locationtech.jts.geom.Geometry result = null;
    // we want a multi geometry event if there is only one geometry
    if (childParts.size() == 1) {
        org.locationtech.jts.geom.Geometry geom = childParts.get(0);
        if (geom instanceof LineString) {
            result = JTSUtils.GEOMETRY_FACTORY.createMultiLineString(new LineString[] { (LineString) geom });
        }
        if (geom instanceof Polygon) {
            result = JTSUtils.GEOMETRY_FACTORY.createMultiPolygon(new Polygon[] { (Polygon) geom });
        }
        if (geom instanceof Point) {
            result = JTSUtils.GEOMETRY_FACTORY.createMultiPoint(new Point[] { (Point) geom });
        }
    }
    if (result == null) {
        result = JTSUtils.GEOMETRY_FACTORY.buildGeometry(childParts);
    }
    CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
    if (crs != null) {
        final int srid = SRIDGenerator.toSRID(crs, Version.V1);
        result.setSRID(srid);
    }
    return result;
}
Also used : Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) AbstractJTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.AbstractJTSGeometry) Geometry(org.opengis.geometry.Geometry) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry) LineString(org.locationtech.jts.geom.LineString) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) AbstractJTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.AbstractJTSGeometry) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry) Polygon(org.locationtech.jts.geom.Polygon)

Example 2 with JTSGeometry

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.

the class JTSComplex method computeJTSPeer.

/**
 * Creates the JTS peer.
 */
@Override
protected final org.locationtech.jts.geom.Geometry computeJTSPeer() {
    ArrayList subParts = new ArrayList();
    Iterator elemIt = elements.iterator();
    while (elemIt.hasNext()) {
        JTSGeometry prim = (JTSGeometry) elemIt.next();
        subParts.add(prim.getJTSGeometry());
    }
    // class it can.
    return JTSUtils.GEOMETRY_FACTORY.buildGeometry(subParts);
}
Also used : AbstractJTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.AbstractJTSGeometry) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)

Example 3 with JTSGeometry

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.

the class JTSPolygon method computeJTSPeer.

/**
 * {@inheritDoc }
 */
@Override
public org.locationtech.jts.geom.Geometry computeJTSPeer() {
    final SurfaceBoundary boundary = getBoundary();
    final Ring exterior = boundary.getExterior();
    final List interiors = boundary.getInteriors();
    if (exterior != null) {
        final org.locationtech.jts.geom.Geometry g = ((JTSGeometry) exterior).getJTSGeometry();
        final int numHoles = (interiors != null) ? interiors.size() : 0;
        final org.locationtech.jts.geom.LinearRing jtsExterior = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g.getCoordinates());
        final org.locationtech.jts.geom.LinearRing[] jtsInterior = new org.locationtech.jts.geom.LinearRing[numHoles];
        for (int i = 0; i < numHoles; i++) {
            final org.locationtech.jts.geom.Geometry g2 = ((JTSGeometry) interiors.get(i)).getJTSGeometry();
            jtsInterior[i] = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g2.getCoordinates());
        }
        final org.locationtech.jts.geom.Polygon result = JTSUtils.GEOMETRY_FACTORY.createPolygon(jtsExterior, jtsInterior);
        final CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
        if (crs != null) {
            final int srid = SRIDGenerator.toSRID(crs, Version.V1);
            result.setSRID(srid);
        }
        return result;
    }
    return null;
}
Also used : SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) Ring(org.opengis.geometry.primitive.Ring) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)

Example 4 with JTSGeometry

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.

the class JTSPolyhedralSurface method computeJTSPeer.

/**
 * {@inheritDoc }
 */
@Override
protected org.locationtech.jts.geom.Geometry computeJTSPeer() {
    if (patches.size() > 1) {
        // throw new UnsupportedOperationException("This implementation does not support surfaces with multiple patches.");
        final org.locationtech.jts.geom.Polygon[] polygons = new org.locationtech.jts.geom.Polygon[patches.size()];
        for (int i = 0; i < patches.size(); i++) {
            final JTSGeometry jtsGeometry = (JTSGeometry) patches.get(i);
            polygons[i] = (org.locationtech.jts.geom.Polygon) jtsGeometry.getJTSGeometry();
        }
        return JTSUtils.GEOMETRY_FACTORY.createMultiPolygon(polygons);
    }
    return ((JTSGeometry) patches.get(0)).getJTSGeometry();
}
Also used : JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry) AbstractJTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.AbstractJTSGeometry)

Example 5 with JTSGeometry

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.

the class GeometryMapping method readValue.

@Override
public void readValue(XMLStreamReader reader, GenericName propName, Feature feature) throws XMLStreamException {
    final String localName = reader.getLocalName();
    if (decorated) {
        // check if we are dealing with a link href
        String link = reader.getAttributeValue(GMLConvention.XLINK_NAMESPACE, "href");
        if (link != null) {
            toTagEnd(reader, localName);
            Attribute attribute = (Attribute) feature.getProperty(propName.toString());
            AttributeType<String> charType = (AttributeType) attribute.getType().characteristics().get(GMLConvention.XLINK_HREF.tip().toString());
            Attribute<String> charValue = charType.newInstance();
            charValue.setValue(link);
            attribute.characteristics().put(GMLConvention.XLINK_HREF.tip().toString(), charValue);
            return;
        }
    }
    boolean skipCurrent = decorated;
    int event;
    Object value;
    // backward compatible with incorrect old writings
    final String propertyName = propertyType.getName().tip().toString();
    if (propertyName.equals(localName)) {
        skipCurrent = true;
    }
    // special case for SurfacePropertyType which may contain a simple polygon
    boolean forceMultiPolygon = propertyName.equalsIgnoreCase("multipolygon");
    if (skipCurrent) {
        event = reader.next();
    } else {
        event = reader.getEventType();
    }
    while (event != START_ELEMENT) {
        if (event == END_ELEMENT) {
            return;
        }
        event = reader.next();
    }
    try {
        Unmarshaller unmarshaller = pool.acquireUnmarshaller();
        final Geometry jtsGeom;
        final Object geometry = ((JAXBElement) unmarshaller.unmarshal(reader)).getValue();
        if (geometry instanceof JTSGeometry) {
            final JTSGeometry isoGeom = (JTSGeometry) geometry;
            if (isoGeom instanceof JTSMultiCurve) {
                ((JTSMultiCurve) isoGeom).applyCRSonChild();
            }
            jtsGeom = isoGeom.getJTSGeometry();
        } else if (geometry instanceof PolygonType) {
            final PolygonType polygon = ((PolygonType) geometry);
            jtsGeom = polygon.getJTSPolygon().getJTSGeometry();
            if (polygon.getCoordinateReferenceSystem() != null) {
                JTS.setCRS(jtsGeom, polygon.getCoordinateReferenceSystem());
            }
        } else if (geometry instanceof LineStringPosListType) {
            final JTSLineString line = ((LineStringPosListType) geometry).getJTSLineString();
            jtsGeom = line.getJTSGeometry();
            if (line.getCoordinateReferenceSystem() != null) {
                JTS.setCRS(jtsGeom, line.getCoordinateReferenceSystem());
            }
        } else if (geometry instanceof AbstractGeometry) {
            try {
                jtsGeom = GeometrytoJTS.toJTS((AbstractGeometry) geometry, longitudeFirst, forceMultiPolygon);
            } catch (FactoryException ex) {
                throw new XMLStreamException("Factory Exception while transforming GML object to JTS", ex);
            }
        } else {
            throw new IllegalArgumentException("unexpected geometry type:" + geometry);
        }
        value = jtsGeom;
        value = JTSMapping.convertType(jtsGeom, ((AttributeType) propertyType).getValueClass());
        pool.recycle(unmarshaller);
    } catch (JAXBException ex) {
        String msg = ex.getMessage();
        if (msg == null && ex.getLinkedException() != null) {
            msg = ex.getLinkedException().getMessage();
        }
        throw new IllegalArgumentException("JAXB exception while reading the feature geometry: " + msg, ex);
    }
    JAXPStreamFeatureReader.setValue(feature, propertyType, propName, null, value);
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Attribute(org.opengis.feature.Attribute) FactoryException(org.opengis.util.FactoryException) JAXBException(javax.xml.bind.JAXBException) PolygonType(org.geotoolkit.internal.jaxb.PolygonType) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JAXBElement(javax.xml.bind.JAXBElement) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) LineStringPosListType(org.geotoolkit.internal.jaxb.LineStringPosListType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry) Geometry(org.locationtech.jts.geom.Geometry) XMLStreamException(javax.xml.stream.XMLStreamException) AttributeType(org.opengis.feature.AttributeType) Unmarshaller(javax.xml.bind.Unmarshaller) JTSGeometry(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)

Aggregations

JTSGeometry (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)8 AbstractJTSGeometry (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.AbstractJTSGeometry)6 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)2 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)2 LineString (org.locationtech.jts.geom.LineString)2 Point (org.locationtech.jts.geom.Point)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 NotifyingArrayList (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.NotifyingArrayList)1 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)1 AbstractGeometry (org.geotoolkit.gml.xml.AbstractGeometry)1 LineStringPosListType (org.geotoolkit.internal.jaxb.LineStringPosListType)1 PolygonType (org.geotoolkit.internal.jaxb.PolygonType)1 Geometry (org.locationtech.jts.geom.Geometry)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1