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;
}
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;
}
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);
}
}
Aggregations