Search in sources :

Example 1 with LineStringPosListType

use of org.geotoolkit.internal.jaxb.LineStringPosListType 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

JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 JTSGeometry (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry)1 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)1 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)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 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1 Point (org.locationtech.jts.geom.Point)1 Attribute (org.opengis.feature.Attribute)1 AttributeType (org.opengis.feature.AttributeType)1 FactoryException (org.opengis.util.FactoryException)1