Search in sources :

Example 16 with AbstractGeometryType

use of org.geotoolkit.gml.xml.v321.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)

Example 17 with AbstractGeometryType

use of org.geotoolkit.gml.xml.v321.AbstractGeometryType in project geotoolkit by Geomatys.

the class ShapeType method equals.

/**
 * Verify if this entry is identical to specified object.
 */
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof ShapeType) {
        final ShapeType that = (ShapeType) object;
        AbstractGeometryType thatgeom = null;
        if (that.abstractGeometry != null) {
            thatgeom = that.abstractGeometry.getValue();
        }
        AbstractGeometryType thisgeom = null;
        if (this.abstractGeometry != null) {
            thisgeom = this.abstractGeometry.getValue();
        }
        return Objects.equals(thisgeom, thatgeom) && Objects.equals(this.actuate, that.actuate) && Objects.equals(this.href, that.href) && Objects.equals(this.remoteSchema, that.remoteSchema) && Objects.equals(this.role, that.role) && Objects.equals(this.show, that.show) && Objects.equals(this.nilReason, that.nilReason) && Objects.equals(this.type, that.type) && Objects.equals(this.arcrole, that.arcrole);
    }
    return false;
}
Also used : AbstractGeometryType(org.geotoolkit.gml.xml.v321.AbstractGeometryType)

Example 18 with AbstractGeometryType

use of org.geotoolkit.gml.xml.v321.AbstractGeometryType in project geotoolkit by Geomatys.

the class OGC110toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.1 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v110.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v110.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) ops;
        final JAXBElement<? extends AbstractGeometryType> geom = binary.getAbstractGeometry();
        final JAXBElement<EnvelopeType> env = binary.getEnvelope();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = binary.getPropertyName().getValue();
        final Expression left = visitPropertyName(pnt);
        final Expression right;
        if (env != null && env.getValue() != null) {
            try {
                right = visitEnv(env);
            } catch (FactoryException ex) {
                throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
            }
        } else {
            right = visit(geom);
        }
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v110.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v110.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v110.DistanceType dt = dstOp.getDistanceType();
        final JAXBElement<? extends AbstractGeometryType> geom = dstOp.getAbstractGeometry();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = dstOp.getPropertyName();
        final Expression geom1 = visitPropertyName(pnt);
        final Expression geom2 = visit(geom);
        // TODO marche pas ? ou est la distance ? Double.valueOf(dt.getContent());
        final double distance = 0;
        final String units = dt.getUnits();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.BBOXType) {
        final org.geotoolkit.ogc.xml.v110.BBOXType binary = (org.geotoolkit.ogc.xml.v110.BBOXType) ops;
        final EnvelopeType box = binary.getEnvelope();
        final String pnt = binary.getPropertyName();
        final Expression geom;
        if (pnt != null) {
            geom = visitPropertyName(pnt);
        } else {
            geom = null;
        }
        final double minx = box.getLowerCorner().getOrdinate(0);
        final double maxx = box.getUpperCorner().getOrdinate(0);
        final double miny = box.getLowerCorner().getOrdinate(1);
        final double maxy = box.getUpperCorner().getOrdinate(1);
        // final double minx = box.getPos().get(0).getOrdinate(0);
        // final double maxx = box.getPos().get(0).getOrdinate(1);
        // final double miny = box.getPos().get(1).getOrdinate(0);
        // final double maxy = box.getPos().get(1).getOrdinate(1);
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : FactoryException(org.opengis.util.FactoryException) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) SpatialOpsType(org.geotoolkit.ogc.xml.v110.SpatialOpsType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression)

Example 19 with AbstractGeometryType

use of org.geotoolkit.gml.xml.v321.AbstractGeometryType in project geotoolkit by Geomatys.

the class OGC200toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.1 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v200.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v200.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) ops;
        Object geom = binary.getAny();
        if (geom instanceof JAXBElement) {
            geom = ((JAXBElement) geom).getValue();
        }
        final Expression left = visitPropertyName(binary.getValueReference());
        final Expression right;
        if (geom instanceof EnvelopeType) {
            try {
                right = visitEnv((EnvelopeType) geom);
            } catch (FactoryException ex) {
                throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
            }
        } else if (geom instanceof AbstractGeometryType) {
            right = visit((AbstractGeometryType) geom);
        } else {
            throw new IllegalArgumentException("Unexpected geometry type:" + geom);
        }
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v200.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v200.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v200.MeasureType dt = dstOp.getDistanceType();
        Object opAny = dstOp.getAny();
        if (opAny instanceof JAXBElement) {
            opAny = ((JAXBElement) opAny).getValue();
        }
        if (!(opAny instanceof AbstractGeometryType)) {
            throw new IllegalArgumentException("geometry type is unexpected:" + opAny);
        }
        final AbstractGeometryType geom = (AbstractGeometryType) opAny;
        final String pnt = dstOp.getPropertyName();
        final Expression geom1 = visitPropertyName(pnt);
        final Expression geom2 = visit(geom);
        // TODO marche pas ? ou est la distance ? Double.valueOf(dt.getContent());
        final double distance = 0;
        final String units = dt.getUom();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.BBOXType) {
        final org.geotoolkit.ogc.xml.v200.BBOXType binary = (org.geotoolkit.ogc.xml.v200.BBOXType) ops;
        Object binAny = binary.getAny();
        if (binAny instanceof JAXBElement) {
            binAny = ((JAXBElement) binAny).getValue();
        }
        if (!(binAny instanceof EnvelopeType)) {
            throw new IllegalArgumentException("geometry type is unexpected:" + binAny);
        }
        final EnvelopeType box = (EnvelopeType) binAny;
        final String pnt = binary.getPropertyName();
        final Expression geom;
        if (pnt != null) {
            geom = visitPropertyName(pnt);
        } else {
            geom = null;
        }
        final double minx = box.getLowerCorner().getOrdinate(0);
        final double maxx = box.getUpperCorner().getOrdinate(0);
        final double miny = box.getLowerCorner().getOrdinate(1);
        final double maxy = box.getUpperCorner().getOrdinate(1);
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v321.EnvelopeType) FactoryException(org.opengis.util.FactoryException) AbstractGeometryType(org.geotoolkit.gml.xml.v321.AbstractGeometryType) org.geotoolkit.ogc.xml.v200(org.geotoolkit.ogc.xml.v200) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression)

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