Search in sources :

Example 11 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType 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 12 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project ddf by codice.

the class GeometryAdapter method unmarshalFrom.

public static Attribute unmarshalFrom(GeometryElement element) throws ConversionFailedException {
    AttributeImpl attribute = null;
    GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
    WKTWriter wktWriter = new WKTWriter();
    for (Value xmlValue : element.getValue()) {
        JAXBElement<AbstractGeometryType> xmlGeometry = xmlValue.getGeometry();
        Geometry geometry = null;
        if (xmlGeometry != null && xmlGeometry.getValue() != null) {
            try {
                geometry = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
            } catch (ConversionFailedException e) {
                LOGGER.debug("Unable to adapt goemetry. ", e);
            }
        }
        if (geometry != null && !geometry.isEmpty()) {
            String wkt = wktWriter.write(geometry);
            if (attribute == null) {
                attribute = new AttributeImpl(element.getName(), wkt);
            } else {
                attribute.addValue(wkt);
            }
        }
    }
    return attribute;
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(org.locationtech.jts.geom.Geometry) WKTWriter(org.locationtech.jts.io.WKTWriter) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value)

Example 13 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project ddf by codice.

the class CswFilterFactory method createBinarySpatialOpTypeUsingGeometry.

@SuppressWarnings("unchecked")
private BinarySpatialOpType createBinarySpatialOpTypeUsingGeometry(PropertyNameType propertyName, JAXBElement<? extends AbstractGeometryType> geometry) {
    BinarySpatialOpType binarySpatialOpType = new BinarySpatialOpType();
    binarySpatialOpType.getPropertyName().add(propertyName);
    binarySpatialOpType.setGeometry((JAXBElement<AbstractGeometryType>) geometry);
    return binarySpatialOpType;
}
Also used : AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) BinarySpatialOpType(net.opengis.filter.v_1_1_0.BinarySpatialOpType)

Example 14 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project arctic-sea by 52North.

the class GmlEncoderv321 method createAbstractGeometry.

private AbstractGeometryType createAbstractGeometry(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
    XmlObject xbGeometry = createPosition(element.getGeometry(), ctx);
    AbstractGeometryType abstractGeometryType = null;
    if (xbGeometry instanceof AbstractGeometryType) {
        abstractGeometryType = (AbstractGeometryType) xbGeometry;
    } else if (xbGeometry instanceof GeometryPropertyType) {
        abstractGeometryType = ((GeometryPropertyType) xbGeometry).getAbstractGeometry();
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    if (element.isSetIdentifier()) {
        abstractGeometryType.setIdentifier(createCodeWithAuthorityType(element.getIdentifierCodeWithAuthority()));
    }
    if (element.isSetName()) {
        for (org.n52.shetland.ogc.gml.CodeType codeType : element.getName()) {
            abstractGeometryType.addNewName().set(createCodeType(codeType));
        }
    }
    if (element.isSetDescription()) {
        abstractGeometryType.addNewDescription().setStringValue(element.getDescription());
    }
    return abstractGeometryType;
}
Also used : AbstractGeometryType(net.opengis.gml.x32.AbstractGeometryType) XmlObject(org.apache.xmlbeans.XmlObject) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 15 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project geotoolkit by Geomatys.

the class JAXPStreamTransactionWriter method write.

// <xsd:element name="Update" type="wfs:UpdateElementType"/>
// <xsd:complexType name="UpdateElementType">
// <xsd:sequence>
// <xsd:element ref="wfs:Property" maxOccurs="unbounded"/>
// <xsd:element ref="ogc:Filter" minOccurs="0" maxOccurs="1"/>
// </xsd:sequence>
// <xsd:attribute name="handle" type="xsd:string" use="optional"/>
// <xsd:attribute name="typeName" type="xsd:QName" use="required"/>
// <xsd:attribute name="inputFormat" type="xsd:string"
// use="optional" default="text/xml; subversion=gml/3.1.1"/>
// <xsd:attribute name="srsName" type="xsd:anyURI" use="optional"/>
// </xsd:complexType>
// <xsd:element name="Property" type="wfs:PropertyType"/>
// <xsd:complexType name="PropertyType">
// <xsd:sequence>
// <xsd:element name="Name" type="xsd:QName"/>
// <xsd:element name="Value" minOccurs="0"/>
// </xsd:sequence>
// </xsd:complexType>
private void write(final XMLStreamWriter writer, final Update element) throws XMLStreamException, FactoryException, JAXBException {
    writer.writeStartElement(WFS_PREFIX, TAG_UPDATE, WFS_NAMESPACE);
    // write typename--------------------------------------------------------
    final GenericName typeName = element.getTypeName();
    final String ns = NamesExt.getNamespace(typeName);
    if (ns != null && !ns.isEmpty()) {
        final String prefix = "geons" + inc.incrementAndGet();
        writer.writeAttribute("xmlns:" + prefix, ns);
        writer.writeAttribute(PROP_TYPENAME, prefix + ':' + typeName.tip());
    } else {
        writer.writeAttribute(PROP_TYPENAME, typeName.tip().toString());
    }
    // write crs-------------------------------------------------------------
    final CoordinateReferenceSystem crs = element.getCoordinateReferenceSystem();
    if (crs != null) {
        final String id = ReferencingUtilities.lookupIdentifier(crs, true);
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_SRSNAME, id);
    }
    // write format----------------------------------------------------------
    final String format = element.getInputFormat();
    if (format != null) {
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_INPUTFORMAT, format);
    }
    // write handle----------------------------------------------------------
    final String handle = element.getHandle();
    if (handle != null) {
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_HANDLE, handle);
    }
    // write filter ---------------------------------------------------------
    final Filter filter = element.getFilter();
    if (filter != null) {
        // TODO : parameterize version
        writeFilter(element.getFilter(), FilterVersion.V110, writer);
        writer.flush();
    }
    // write properties------------------------------------------------------
    for (final Entry<PropertyType, Object> entry : element.updates().entrySet()) {
        writer.writeStartElement(WFS_PREFIX, TAG_PROPERTY, WFS_NAMESPACE);
        // write namespace
        final GenericName name = entry.getKey().getName();
        final String ns2 = NamesExt.getNamespace(name);
        String pref = writer.getNamespaceContext().getPrefix(ns2);
        if (pref == null && ns2 != null && !ns2.isEmpty()) {
            pref = "geons" + inc.incrementAndGet();
            writer.writeAttribute("xmlns:" + pref, ns2);
        }
        // write name
        writer.writeStartElement(WFS_PREFIX, TAG_NAME, WFS_NAMESPACE);
        if (pref != null) {
            writer.writeCharacters(pref + ':' + name.tip());
        } else {
            writer.writeCharacters(name.tip().toString());
        }
        writer.writeEndElement();
        // write value
        final PropertyType propertyType = entry.getKey();
        Object value = entry.getValue();
        if (value != null) {
            if (value instanceof Geometry) {
                value = new GeometryPropertyType((AbstractGeometryType) JTStoGeometry.toGML("3.1.1", (Geometry) value));
                final Marshaller marshaller = GMLPOOL.acquireMarshaller();
                marshaller.setProperty(marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                marshaller.marshal(new ObjectFactory().createValue(value), writer);
                GMLPOOL.recycle(marshaller);
            } else if (value instanceof org.opengis.geometry.Geometry) {
                final Marshaller marshaller = POOL.acquireMarshaller();
                marshaller.setProperty(marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                marshaller.marshal(new ObjectFactory().createValue(value), writer);
                POOL.recycle(marshaller);
            } else {
                writer.writeStartElement(WFS_PREFIX, TAG_VALUE, WFS_NAMESPACE);
                QName qname = Utils.getQNameFromType(propertyType, "");
                writer.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, PROP_TYPE, qname.getLocalPart());
                writer.writeCharacters(Utils.getStringValue(value));
                writer.writeEndElement();
            }
        }
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) QName(javax.xml.namespace.QName) GeometryPropertyType(org.geotoolkit.gml.xml.v311.GeometryPropertyType) PropertyType(org.opengis.feature.PropertyType) JTStoGeometry(org.geotoolkit.gml.JTStoGeometry) Geometry(org.locationtech.jts.geom.Geometry) GenericName(org.opengis.util.GenericName) ObjectFactory(org.geotoolkit.internal.jaxb.ObjectFactory) Filter(org.opengis.filter.Filter) XMLFilter(org.geotoolkit.ogc.xml.XMLFilter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryPropertyType(org.geotoolkit.gml.xml.v311.GeometryPropertyType)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)8 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)7 Geometry (org.locationtech.jts.geom.Geometry)5 AbstractGeometryType (org.geotoolkit.gml.xml.v311.AbstractGeometryType)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)2 QName (javax.xml.namespace.QName)2 AbstractGeometryType (net.opengis.gml.x32.AbstractGeometryType)2 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)2 CurveType (org.geotoolkit.gml.xml.v311.CurveType)2 LineStringType (org.geotoolkit.gml.xml.v311.LineStringType)2 MultiCurveType (org.geotoolkit.gml.xml.v311.MultiCurveType)2 MultiGeometryType (org.geotoolkit.gml.xml.v311.MultiGeometryType)2 MultiPointType (org.geotoolkit.gml.xml.v311.MultiPointType)2 MultiPolygonType (org.geotoolkit.gml.xml.v311.MultiPolygonType)2 PointType (org.geotoolkit.gml.xml.v311.PointType)2 PolygonType (org.geotoolkit.gml.xml.v311.PolygonType)2 PolyhedralSurfaceType (org.geotoolkit.gml.xml.v311.PolyhedralSurfaceType)2 AbstractGeometryType (org.geotoolkit.gml.xml.v321.AbstractGeometryType)2