Search in sources :

Example 1 with GeometryObject

use of org.citydb.config.geometry.GeometryObject in project web-feature-service by 3dcitydb.

the class SpatialFilterBuilder method buildBinaryOperator.

private Predicate buildBinaryOperator(BinarySpatialOpType binarySpatialOp, QName opName, FeatureType featureType, NamespaceFilter namespaceFilter, String handle) throws WFSException {
    JAXBElement<?>[] operands = parseOperands(binarySpatialOp.getExpressionOrAny());
    JAXBElement<?> valueReference_ = operands[0];
    JAXBElement<?> geometry_ = operands[1];
    if (geometry_ == null)
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "The spatial operator '" + opName + "' lacks a GML geometry operand.", handle);
    if (valueReference_ == null)
        throw new WFSException(WFSExceptionCode.MISSING_PARAMETER_VALUE, "The spatial operator '" + opName + "' requires a ValueReference pointing to the geometry property to be tested.", handle);
    // map XPath expression
    ValueReference valueReference = parseValueReference((String) valueReference_.getValue(), featureType, namespaceFilter, handle);
    // map geometry object
    GeometryObject geometry = null;
    try {
        geometry = gmlParser.parseGeometry(geometry_);
        if (geometry == null)
            throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + geometry_.getName() + "' geometry.", handle);
    } catch (GeometryParseException | SrsParseException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + geometry_.getName() + "' geometry.", handle, e);
    }
    try {
        switch(SpatialOperatorName.fromValue(opName.getLocalPart())) {
            case EQUALS:
                return SpatialOperationFactory.equals(valueReference, geometry);
            case DISJOINT:
                return SpatialOperationFactory.disjoint(valueReference, geometry);
            case TOUCHES:
                return SpatialOperationFactory.touches(valueReference, geometry);
            case WITHIN:
                return SpatialOperationFactory.within(valueReference, geometry);
            case OVERLAPS:
                return SpatialOperationFactory.overlaps(valueReference, geometry);
            case INTERSECTS:
                return SpatialOperationFactory.intersects(valueReference, geometry);
            case CONTAINS:
                return SpatialOperationFactory.contains(valueReference, geometry);
            case BBOX:
            case DWITHIN:
            case BEYOND:
                return null;
        }
    } catch (FilterException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to build filter expression.", handle, e);
    }
    return null;
}
Also used : SrsParseException(org.citydb.core.query.geometry.SrsParseException) WFSException(vcs.citydb.wfs.exception.WFSException) GeometryObject(org.citydb.config.geometry.GeometryObject) FilterException(org.citydb.core.query.filter.FilterException) JAXBElement(javax.xml.bind.JAXBElement) GeometryParseException(org.citydb.core.query.geometry.GeometryParseException) ValueReference(org.citydb.core.query.filter.selection.expression.ValueReference)

Example 2 with GeometryObject

use of org.citydb.config.geometry.GeometryObject in project web-feature-service by 3dcitydb.

the class SpatialFilterBuilder method buildDistanceOperator.

private Predicate buildDistanceOperator(DistanceBufferType distanceOp, QName opName, FeatureType featureType, NamespaceFilter namespaceFilter, String handle) throws WFSException {
    JAXBElement<?>[] operands = parseOperands(distanceOp.getExpressionOrAny());
    JAXBElement<?> valueReference_ = operands[0];
    JAXBElement<?> geometry_ = operands[1];
    MeasureType distance_ = distanceOp.getDistance();
    if (geometry_ == null)
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "The spatial operator '" + opName + "' lacks a GML geometry operand.", handle);
    if (distance_ == null)
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "The spatial operator '" + opName + "' requires a Distance operand.", handle);
    // map XPath expression
    ValueReference valueReference = null;
    if (valueReference_ != null)
        valueReference = parseValueReference((String) valueReference_.getValue(), featureType, namespaceFilter, handle);
    // map geometry object
    GeometryObject geometry = null;
    try {
        geometry = gmlParser.parseGeometry(geometry_);
        if (geometry == null)
            throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + geometry_.getName() + "' geometry.", handle);
    } catch (GeometryParseException | SrsParseException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + geometry_.getName() + "' geometry.", handle, e);
    }
    // handle distance
    DistanceUnit unit = null;
    if (distance_.isSetUom()) {
        unit = DistanceUnit.fromSymbol(distance_.getUom());
        if (unit == null) {
            WFSExceptionMessage message = new WFSExceptionMessage(WFSExceptionCode.OPERATION_PROCESSING_FAILED);
            message.addExceptionText("Failed to recognize the unit '" + distance_.getUom() + "' on the Distance operand.");
            message.addExceptionText("Supportes units are " + Util.collection2string(Arrays.asList(DistanceUnit.values()), ", ") + ".");
            message.setLocator(handle);
            throw new WFSException(message);
        }
    } else
        unit = DistanceUnit.METER;
    Distance distance = new Distance(distance_.getValue(), unit);
    try {
        switch(SpatialOperatorName.fromValue(opName.getLocalPart())) {
            case DWITHIN:
                return SpatialOperationFactory.dWithin(valueReference, geometry, distance);
            case BEYOND:
                return SpatialOperationFactory.beyond(valueReference, geometry, distance);
            case EQUALS:
            case DISJOINT:
            case TOUCHES:
            case WITHIN:
            case OVERLAPS:
            case INTERSECTS:
            case CONTAINS:
            case BBOX:
                return null;
        }
    } catch (FilterException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to build filter expression.", handle, e);
    }
    return null;
}
Also used : GeometryObject(org.citydb.config.geometry.GeometryObject) MeasureType(net.opengis.fes._2.MeasureType) JAXBElement(javax.xml.bind.JAXBElement) GeometryParseException(org.citydb.core.query.geometry.GeometryParseException) SrsParseException(org.citydb.core.query.geometry.SrsParseException) WFSException(vcs.citydb.wfs.exception.WFSException) WFSExceptionMessage(vcs.citydb.wfs.exception.WFSExceptionMessage) FilterException(org.citydb.core.query.filter.FilterException) DistanceUnit(org.citydb.core.query.filter.selection.operator.spatial.DistanceUnit) Distance(org.citydb.core.query.filter.selection.operator.spatial.Distance) ValueReference(org.citydb.core.query.filter.selection.expression.ValueReference)

Example 3 with GeometryObject

use of org.citydb.config.geometry.GeometryObject in project web-feature-service by 3dcitydb.

the class SpatialFilterBuilder method buildBBOXOperator.

private Predicate buildBBOXOperator(BBOXType bboxOp, QName opName, FeatureType featureType, NamespaceFilter namespaceFilter, String handle) throws WFSException {
    JAXBElement<?>[] operands = parseOperands(bboxOp.getExpressionOrAny());
    JAXBElement<?> valueReference_ = operands[0];
    JAXBElement<?> envelope_ = operands[1];
    if (envelope_ == null || !(envelope_.getValue() instanceof EnvelopeType))
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "A '" + new QName(GMLCoreModule.v3_1_1.getNamespaceURI(), "Envelope").toString() + "' is expected as spatial operand of the BBOX operator.", handle);
    // map XPath expression
    ValueReference valueReference = null;
    if (valueReference_ != null)
        valueReference = parseValueReference((String) valueReference_.getValue(), featureType, namespaceFilter, handle);
    // map geometry object
    GeometryObject geometry = null;
    try {
        geometry = gmlParser.parseGeometry(envelope_);
        if (geometry == null)
            throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + envelope_.getName() + "' geometry.", handle);
    } catch (GeometryParseException | SrsParseException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to parse the '" + envelope_.getName() + "' geometry.", handle, e);
    }
    try {
        return SpatialOperationFactory.bbox(valueReference, geometry);
    } catch (FilterException e) {
        throw new WFSException(WFSExceptionCode.OPERATION_PROCESSING_FAILED, "Failed to build filter expression.", handle, e);
    }
}
Also used : SrsParseException(org.citydb.core.query.geometry.SrsParseException) EnvelopeType(net.opengis.gml.EnvelopeType) WFSException(vcs.citydb.wfs.exception.WFSException) GeometryObject(org.citydb.config.geometry.GeometryObject) QName(javax.xml.namespace.QName) FilterException(org.citydb.core.query.filter.FilterException) JAXBElement(javax.xml.bind.JAXBElement) GeometryParseException(org.citydb.core.query.geometry.GeometryParseException) ValueReference(org.citydb.core.query.filter.selection.expression.ValueReference)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)3 GeometryObject (org.citydb.config.geometry.GeometryObject)3 FilterException (org.citydb.core.query.filter.FilterException)3 ValueReference (org.citydb.core.query.filter.selection.expression.ValueReference)3 GeometryParseException (org.citydb.core.query.geometry.GeometryParseException)3 SrsParseException (org.citydb.core.query.geometry.SrsParseException)3 WFSException (vcs.citydb.wfs.exception.WFSException)3 QName (javax.xml.namespace.QName)1 MeasureType (net.opengis.fes._2.MeasureType)1 EnvelopeType (net.opengis.gml.EnvelopeType)1 Distance (org.citydb.core.query.filter.selection.operator.spatial.Distance)1 DistanceUnit (org.citydb.core.query.filter.selection.operator.spatial.DistanceUnit)1 WFSExceptionMessage (vcs.citydb.wfs.exception.WFSExceptionMessage)1