use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.
the class ODataFesParserTest method testFeatureOfInterestGeoIntersectsPolygon.
@Test
public void testFeatureOfInterestGeoIntersectsPolygon() throws Exception {
Filter<?> filter = parser.decode(String.format("geo.intersects(featureOfInterest,'SRID=%s;%s')", polygon.getSRID(), wktGeometry));
assertThat(filter, is(instanceOf(SpatialFilter.class)));
SpatialFilter sf = (SpatialFilter) filter;
errors.checkThat(sf.getSrid(), is(4326));
errors.checkThat(sf.getGeometry().isEnvelope(), is(false));
errors.checkThat(sf.getGeometry().isGeometry(), is(true));
errors.checkThat(sf.getGeometry().getGeometry().get(), is(instanceOf(Polygon.class)));
errors.checkThat(sf.getValueReference(), is("om:featureOfInterest/*/sams:shape"));
}
use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.
the class SosDecoderv100 method parseGetObservation.
/**
* parses the XmlBean representing the getObservation request and creates a
* SoSGetObservation request
*
* @param getObsDoc
* XmlBean created from the incoming request stream
* @return Returns SosGetObservationRequest representing the request
*
* @throws DecodingException
* * If parsing the XmlBean failed
*/
private OwsServiceRequest parseGetObservation(GetObservationDocument getObsDoc) throws DecodingException {
GetObservationRequest getObsRequest = new GetObservationRequest();
GetObservation getObs = getObsDoc.getGetObservation();
getObsRequest.setService(getObs.getService());
getObsRequest.setVersion(getObs.getVersion());
getObsRequest.setOfferings(Arrays.asList(getObs.getOffering()));
getObsRequest.setObservedProperties(Arrays.asList(getObs.getObservedPropertyArray()));
getObsRequest.setProcedures(Arrays.asList(getObs.getProcedureArray()));
getObsRequest.setTemporalFilters(parseTemporalFilters4GetObservation(getObs.getEventTimeArray()));
getObsRequest.setSrsName(getObs.getSrsName());
if (getObs.isSetFeatureOfInterest()) {
FeatureOfInterest featureOfInterest = getObs.getFeatureOfInterest();
if (featureOfInterest.isSetSpatialOps()) {
Object filter = decodeXmlElement(featureOfInterest.getSpatialOps());
if (filter instanceof SpatialFilter) {
getObsRequest.setSpatialFilter((SpatialFilter) filter);
}
} else if (featureOfInterest.getObjectIDArray() != null) {
Set<String> featureIdentifiers = Sets.newHashSet();
for (String string : featureOfInterest.getObjectIDArray()) {
featureIdentifiers.add(string);
}
getObsRequest.setFeatureIdentifiers(Lists.newArrayList(featureIdentifiers));
}
}
// TODO implement result filtering
if (getObs.isSetResult()) {
throw new NotYetSupportedDecodingException("Result filtering");
}
// return error message
if (getObs.isSetResponseFormat()) {
getObsRequest.setResponseFormat(decodeResponseFormat(getObs.getResponseFormat()));
} else {
getObsRequest.setResponseFormat(OmConstants.CONTENT_TYPE_OM.toString());
}
if (getObs.isSetResultModel()) {
getObsRequest.setResultModel(OMHelper.getObservationTypeFor(getObs.getResultModel()));
}
return getObsRequest;
}
use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.
the class FesDecoderv20 method parseSpatialFilterType.
/**
* Parses the spatial filter of a request.
*
* @param xbSpatialOpsType
* XmlBean representing the feature of interest parameter of the
* request
* @return Returns SpatialFilter created from the passed foi request
* parameter
*
* @throws DecodingException
* * if creation of the SpatialFilter failed
*/
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXType) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
if (isValueReferenceExpression(xbBBOX.getExpression())) {
spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
}
XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
} else if (sosGeometry instanceof ReferencedEnvelope) {
spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
} else {
throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
}
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
}
geometryCursor.dispose();
} else {
throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing spatial filter!", xmle);
}
return spatialFilter;
}
use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.
the class OgcDecoderv100 method parseSpatialOperatorType.
private Object parseSpatialOperatorType(BinarySpatialOpType xbSpatialOpsType) throws DecodingException {
SpatialFilter spatialFilter = new SpatialFilter();
try {
if (xbSpatialOpsType instanceof BBOXTypeImpl) {
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
BBOXTypeImpl xbBBOX = (BBOXTypeImpl) xbSpatialOpsType;
spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
XmlCursor geometryCursor = xbBBOX.newCursor();
if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
if (sosGeometry instanceof Geometry) {
spatialFilter.setGeometry((Geometry) sosGeometry);
}
} else {
throw unsupportedSpatialFilter();
}
geometryCursor.dispose();
} else {
throw unsupportedSpatialFilter();
}
} catch (XmlException xmle) {
throw errorParsingSpatialFilter(xmle);
}
return spatialFilter;
}
use of org.n52.shetland.ogc.filter.SpatialFilter in project arctic-sea by 52North.
the class FesEncoderv20Test method should_return_BBoxType_for_spatialFilter.
// @Test
// deactivated until test fails on build server.
public final void should_return_BBoxType_for_spatialFilter() throws EncodingException {
final SpatialFilter filter = new SpatialFilter();
filter.setOperator(SpatialOperator.BBOX);
filter.setGeometry(new GeometryFactory().toGeometry(new Envelope(1, 2, 3, 4)));
filter.setValueReference("valueReference");
final XmlObject encode = fesEncoder.encode(filter);
assertThat(encode, is(instanceOf(BBOXType.class)));
final BBOXType xbBBox = (BBOXType) encode;
assertThat(xbBBox.isSetExpression(), is(TRUE));
}
Aggregations