Search in sources :

Example 1 with SpatialFilter

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"));
}
Also used : SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) Test(org.junit.Test)

Example 2 with SpatialFilter

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;
}
Also used : GetObservation(net.opengis.sos.x10.GetObservationDocument.GetObservation) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) Set(java.util.Set) GetFeatureOfInterest(net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest) FeatureOfInterest(net.opengis.sos.x10.GetObservationDocument.GetObservation.FeatureOfInterest) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) NotYetSupportedDecodingException(org.n52.svalbard.decode.exception.NotYetSupportedDecodingException)

Example 3 with SpatialFilter

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) BBOXType(net.opengis.fes.x20.BBOXType) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 4 with 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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) BBOXTypeImpl(net.opengis.ogc.impl.BBOXTypeImpl) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 5 with 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));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) BBOXType(net.opengis.fes.x20.BBOXType) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)9 XmlObject (org.apache.xmlbeans.XmlObject)5 XmlCursor (org.apache.xmlbeans.XmlCursor)3 XmlException (org.apache.xmlbeans.XmlException)3 Test (org.junit.Test)3 Geometry (org.locationtech.jts.geom.Geometry)3 BBOXType (net.opengis.fes.x20.BBOXType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Set (java.util.Set)1 BBOXTypeImpl (net.opengis.ogc.impl.BBOXTypeImpl)1 GetFeatureOfInterest (net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest)1 GetObservation (net.opengis.sos.x10.GetObservationDocument.GetObservation)1 FeatureOfInterest (net.opengis.sos.x10.GetObservationDocument.GetObservation.FeatureOfInterest)1 Envelope (org.locationtech.jts.geom.Envelope)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)1 ReferencedEnvelope (org.n52.shetland.util.ReferencedEnvelope)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 NotYetSupportedDecodingException (org.n52.svalbard.decode.exception.NotYetSupportedDecodingException)1