Search in sources :

Example 31 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class ProfileObservation method setFeatureGeometry.

private void setFeatureGeometry(List<Coordinate> coordinates, int srid) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = coordinates.toArray(new Coordinate[0]);
        try {
            LineString lineString = new GeometryFactory().createLineString(coords);
            lineString.setSRID(srid);
            sf.setGeometry(lineString);
            sf.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE);
        } catch (InvalidSridException e) {
        // TODO
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 32 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class TrajectoryObservation method checkForFeature.

/**
 * Create geometry for featureOfInterest from
 * {@link TimeLocationValueTriple}s
 *
 * @param values
 *            The {@link TimeLocationValueTriple}s to check for
 *            featureOfInterest
 */
private void checkForFeature(List<TimeLocationValueTriple> values) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = getCoordinates(values);
        int srid = 0;
        if (sf.isSetGeometry()) {
            srid = sf.getGeometry().getSRID();
            coords = (Coordinate[]) ArrayUtils.addAll(sf.getGeometry().getCoordinates(), coords);
        } else {
            TimeLocationValueTriple next = values.iterator().next();
            if (next.isSetLocation()) {
                srid = next.getLocation().getSRID();
            }
        }
        try {
            if (coords.length == 1) {
                Point point = new GeometryFactory().createPoint(coords[0]);
                point.setSRID(srid);
                sf.setGeometry(point);
            } else if (coords.length > 1) {
                LineString lineString = new GeometryFactory().createLineString(coords);
                lineString.setSRID(srid);
                sf.setGeometry(lineString);
            }
        } catch (InvalidSridException e) {
        // TODO
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Example 33 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class MeasurementDecodingTest method testFeatureOfInterestName.

@Test
public void testFeatureOfInterestName() {
    assertThat(observation, is(notNullValue()));
    final OmObservationConstellation oc = observation.getObservationConstellation();
    assertThat(oc, is(notNullValue()));
    final AbstractFeature foi = oc.getFeatureOfInterest();
    assertThat(foi, is(notNullValue()));
    final List<CodeType> name = foi.getName();
    assertThat(name, is(notNullValue()));
    assertThat(name.size(), is(3));
    assertThat(name.get(0), is(notNullValue()));
    assertThat(name.get(0).getValue(), is(equalTo(FEATURE_NAME)));
    assertThat(name.get(0).getCodeSpace().toString(), is(equalTo("http://x.y/z")));
    assertThat(name.get(1), is(notNullValue()));
    assertThat(name.get(1).getValue(), is(equalTo("othername1")));
    assertThat(name.get(1).isSetCodeSpace(), is(false));
    assertThat(name.get(2), is(notNullValue()));
    assertThat(name.get(2).getValue(), is(equalTo("othername2")));
    assertThat(name.get(2).isSetCodeSpace(), is(false));
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) CodeType(org.n52.shetland.ogc.gml.CodeType) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) Test(org.junit.Test)

Example 34 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class MeasurementDecodingTest method testFeatureOfInterestIdentifier.

@Test
public void testFeatureOfInterestIdentifier() {
    assertThat(observation, is(notNullValue()));
    final OmObservationConstellation oc = observation.getObservationConstellation();
    assertThat(oc, is(notNullValue()));
    final AbstractFeature foi = oc.getFeatureOfInterest();
    assertThat(foi, is(notNullValue()));
    assertThat(foi.getIdentifierCodeWithAuthority(), is(notNullValue()));
    assertThat(foi.getIdentifierCodeWithAuthority().getCodeSpace(), is(equalTo(UNKNOWN_CODESPACE)));
    assertThat(foi.getIdentifierCodeWithAuthority().getValue(), is(equalTo(FEATURE_IDENTIFIER)));
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) Test(org.junit.Test)

Example 35 with AbstractFeature

use of org.n52.shetland.ogc.gml.AbstractFeature in project arctic-sea by 52North.

the class SpecimenDecoderv20 method getSampledFeatures.

/**
 * Parse {@link FeaturePropertyType} sampledFeature to
 * {@link AbstractFeature} list.
 *
 * @param sampledFeature
 *            SampledFeature to parse
 * @return List with the parsed sampledFeature
 * @throws DecodingException
 *             If an error occurs
 */
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
    final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(1);
    if (sampledFeature != null && !sampledFeature.isNil()) {
        // if xlink:href is set
        if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
            if (sampledFeature.getHref().startsWith("#")) {
                sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
            } else {
                final AbstractSamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
                if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
                    sampFeat.addName(new CodeType(sampledFeature.getTitle()));
                }
                sampledFeatures.add(sampFeat);
            }
        } else {
            XmlObject abstractFeature = null;
            if (sampledFeature.getAbstractFeature() != null) {
                abstractFeature = sampledFeature.getAbstractFeature();
            } else if (sampledFeature.getDomNode().hasChildNodes()) {
                try {
                    abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
                } catch (final XmlException xmle) {
                    throw new DecodingException("Error while parsing feature request!", xmle);
                }
            }
            if (abstractFeature != null) {
                final Object decodedObject = decodeXmlObject(abstractFeature);
                if (decodedObject instanceof AbstractFeature) {
                    sampledFeatures.add((AbstractFeature) decodedObject);
                }
            }
            throw new DecodingException("The requested sampledFeature type is not supported by this service!");
        }
    }
    return sampledFeatures;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) XmlException(org.apache.xmlbeans.XmlException) ArrayList(java.util.ArrayList) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) CodeType(org.n52.shetland.ogc.gml.CodeType) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Aggregations

AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)33 XmlObject (org.apache.xmlbeans.XmlObject)23 XmlException (org.apache.xmlbeans.XmlException)10 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)10 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)9 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)9 OmObservation (org.n52.shetland.ogc.om.OmObservation)8 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)8 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)8 Test (org.junit.Test)6 LineString (org.locationtech.jts.geom.LineString)6 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)6 EncodingException (org.n52.svalbard.encode.exception.EncodingException)6 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 CodeType (org.n52.shetland.ogc.gml.CodeType)4 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)4 SosProcedureDescription (org.n52.shetland.ogc.sos.SosProcedureDescription)4 DateTime (org.joda.time.DateTime)3 Time (org.n52.shetland.ogc.gml.time.Time)3