Search in sources :

Example 11 with AbstractSamplingFeature

use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature 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 12 with AbstractSamplingFeature

use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature 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 13 with AbstractSamplingFeature

use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature in project arctic-sea by 52North.

the class MultiPointObservation method getEnvelope.

/**
 * Get the envelope from {@link PointValuePair}s {@link List}
 *
 * @param pointValuePairs
 *            The {@link PointValuePair}s to get the envelope from
 * @return The envelope of the {@link PointValuePair}s
 */
private Geometry getEnvelope(List<PointValuePair> pointValuePairs) {
    Envelope envelope = new Envelope();
    GeometryFactory factory = null;
    int srid = 4326;
    if (CollectionHelper.isNotEmpty(pointValuePairs)) {
        for (PointValuePair pointValuePair : pointValuePairs) {
            if (factory == null && pointValuePair.getPoint() != null) {
                factory = pointValuePair.getPoint().getFactory();
            }
            if (pointValuePair.getPoint().getSRID() > 0) {
                srid = pointValuePair.getPoint().getSRID();
            }
            envelope.expandToInclude(pointValuePair.getPoint().getEnvelopeInternal());
        }
    } else {
        if (isSetSpatialFilteringProfileParameter()) {
            Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
            if (geometry != null) {
                if (factory == null) {
                    factory = geometry.getFactory();
                }
                if (geometry.getSRID() > 0) {
                    srid = geometry.getSRID();
                }
                envelope.expandToInclude(geometry.getEnvelopeInternal());
            }
        } else {
            if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
                Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
                if (geometry != null) {
                    if (factory == null) {
                        factory = geometry.getFactory();
                    }
                    if (geometry.getSRID() > 0) {
                        srid = geometry.getSRID();
                    }
                    envelope.expandToInclude(geometry.getEnvelopeInternal());
                }
            }
        }
    }
    if (factory == null) {
        factory = JTSHelper.getGeometryFactoryForSRID(srid);
    }
    Geometry geometry = factory.toGeometry(envelope);
    geometry.setSRID(srid);
    return geometry;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Envelope(org.locationtech.jts.geom.Envelope) Point(org.locationtech.jts.geom.Point) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 14 with AbstractSamplingFeature

use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature in project arctic-sea by 52North.

the class MultiPointObservation method getPoint.

/**
 * Get the point from samplingGeometry or featureOfInterest
 *
 * @return The {@link Point}
 */
private Point getPoint() {
    Point point = null;
    if (isSetSpatialFilteringProfileParameter()) {
        Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
        point = geometry.getInteriorPoint();
        point.setSRID(geometry.getSRID());
    } else {
        if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
            Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
            point = geometry.getInteriorPoint();
            point.setSRID(geometry.getSRID());
        }
    }
    return point;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point)

Example 15 with AbstractSamplingFeature

use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature 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

AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)14 XmlObject (org.apache.xmlbeans.XmlObject)11 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)8 XmlException (org.apache.xmlbeans.XmlException)5 Geometry (org.locationtech.jts.geom.Geometry)5 LineString (org.locationtech.jts.geom.LineString)5 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 Point (org.locationtech.jts.geom.Point)4 CodeType (org.n52.shetland.ogc.gml.CodeType)4 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 ArrayList (java.util.ArrayList)2 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 AbstractMetaData (org.n52.shetland.ogc.gml.AbstractMetaData)2 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 TimeLocationValueTriple (org.n52.shetland.ogc.om.TimeLocationValueTriple)2