Search in sources :

Example 1 with AbstractSamplingFeature

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

the class TrajectoryObservation method setValue.

@SuppressWarnings("rawtypes")
@Override
public void setValue(ObservationValue<?> value) {
    if (value instanceof StreamingValue || value.getValue() instanceof TLVTValue) {
        super.setValue(value);
    } else {
        Geometry geometry = null;
        if (isSetSpatialFilteringProfileParameter()) {
            geometry = getSpatialFilteringProfileParameter().getValue().getValue();
        } else {
            if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
                geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
            }
        }
        TLVTValue tlvpValue = convertSingleValueToMultiValue((SingleObservationValue<?>) value, geometry);
        if (!tlvpValue.isSetUnit() && ((AbstractObservationValue<?>) value).isSetUnit()) {
            tlvpValue.setUnit(((AbstractObservationValue<?>) value).getUnit());
        }
        final MultiObservationValues<List<TimeLocationValueTriple>> multiValue = new MultiObservationValues<List<TimeLocationValueTriple>>();
        multiValue.setValue(tlvpValue);
        if (!multiValue.isSetObservationID()) {
            if (value instanceof AbstractObservationValue && ((AbstractObservationValue) value).isSetObservationID()) {
                multiValue.setObservationID(((AbstractObservationValue) value).getObservationID());
            } else if (isSetObservationID()) {
                multiValue.setObservationID(getObservationID());
            }
        }
        super.setValue(multiValue);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) List(java.util.List) TLVTValue(org.n52.shetland.ogc.om.values.TLVTValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Example 2 with AbstractSamplingFeature

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

the class UVFEncoder method writeLine3.

private void writeLine3(Writer fw, OmObservation o, String lineEnding) throws IOException {
    // 3.Zeile 88888 0 0 0.000
    StringBuilder sb = new StringBuilder(45);
    if (o.getObservationConstellation().isSetIdentifier()) {
        sb.append(ensureIdentifierLength(o.getObservationConstellation().getIdentifier(), UVFConstants.MAX_IDENTIFIER_LENGTH));
    } else if (o.isSetIdentifier()) {
        sb.append(ensureIdentifierLength(o.getIdentifier(), UVFConstants.MAX_IDENTIFIER_LENGTH));
    } else {
        if (!o.isSetObservationID()) {
            o.setObservationID(JavaHelper.generateID(o.toString()));
        }
        sb.append(ensureIdentifierLength(o.getObservationID(), UVFConstants.MAX_IDENTIFIER_LENGTH));
    }
    fillWithSpaces(sb, UVFConstants.MAX_IDENTIFIER_LENGTH);
    AbstractFeature f = o.getObservationConstellation().getFeatureOfInterest();
    if (o.getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) o.getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) f;
        // Rechtswert
        String xString = sf.isSetGeometry() ? Double.toString(sf.getGeometry().getCoordinate().y) : "";
        xString = ensureValueLength(xString, 10);
        sb.append(xString);
        fillWithSpaces(sb, 25);
        // Hochwert
        String yString = sf.isSetGeometry() ? Double.toString(sf.getGeometry().getCoordinate().x) : "";
        yString = ensureValueLength(yString, 10);
        sb.append(yString);
        fillWithSpaces(sb, 35);
        if (sf.isSetGeometry() && !Double.isNaN(sf.getGeometry().getCoordinate().z)) {
            String zString = Double.toString(sf.getGeometry().getCoordinate().z);
            zString = ensureValueLength(zString, 10);
            sb.append(zString);
        }
    }
    fillWithSpaces(sb, 45);
    writeToFile(fw, sb.toString(), lineEnding);
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 3 with AbstractSamplingFeature

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

the class GmlEncoderv321 method createFeature.

private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
    FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
    if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
        return featurePropertyType;
    } else {
        AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
        if (samplingFeature.isSetGmlID()) {
            featurePropertyType.setHref("#" + samplingFeature.getGmlId());
            return featurePropertyType;
        } else {
            if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
                featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (!samplingFeature.isSetGeometry()) {
                featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            }
            if (samplingFeature.isSetUrl()) {
                featurePropertyType.setHref(samplingFeature.getUrl());
                if (samplingFeature.isSetName()) {
                    featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
                }
                return featurePropertyType;
            } else {
                String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
                XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
                if (encodedXmlObject != null) {
                    return encodedXmlObject;
                } else {
                    if (feature.isSetXml()) {
                        try {
                            // XmlDescription? <-- XmlCursor
                            return XmlObject.Factory.parse(feature.getXml());
                        } catch (XmlException xmle) {
                            throw new EncodingException("Error while encoding featurePropertyType!", xmle);
                        }
                    } else {
                        featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
                        if (samplingFeature.isSetName()) {
                            featurePropertyType.setTitle(feature.getFirstName().getValue());
                        }
                        return featurePropertyType;
                    }
                }
            }
        }
    }
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) XmlObject(org.apache.xmlbeans.XmlObject) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) FeaturePropertyType(net.opengis.gml.x32.FeaturePropertyType)

Example 4 with AbstractSamplingFeature

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

the class SamplingEncoderv100 method createFeature.

private XmlObject createFeature(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGPOINT) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT) || sampFeat.getGeometry() instanceof Point) {
            SamplingPointDocument xbSamplingPointDoc = SamplingPointDocument.Factory.newInstance(getXmlOptions());
            SamplingPointType xbSamplingPoint = xbSamplingPointDoc.addNewSamplingPoint();
            addValuesToFeature(xbSamplingPoint, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingPoint.addNewPosition().addNewPoint().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingPointDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGCURVE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE) || sampFeat.getGeometry() instanceof LineString) {
            SamplingCurveDocument xbSamplingCurveDoc = SamplingCurveDocument.Factory.newInstance(getXmlOptions());
            SamplingCurveType xbSamplingCurve = xbSamplingCurveDoc.addNewSamplingCurve();
            addValuesToFeature(xbSamplingCurve, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingCurve.addNewShape().addNewCurve().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingCurveDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGSURFACE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE) || sampFeat.getGeometry() instanceof Polygon) {
            SamplingSurfaceDocument xbSamplingSurfaceDoc = SamplingSurfaceDocument.Factory.newInstance(getXmlOptions());
            SamplingSurfaceType xbSamplingSurface = xbSamplingSurfaceDoc.addNewSamplingSurface();
            addValuesToFeature(xbSamplingSurface, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingSurface.addNewShape().addNewSurface().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingSurfaceDoc;
        }
    } else if (absFeature instanceof FeatureCollection) {
        createFeatureCollection((FeatureCollection) absFeature);
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : SamplingSurfaceType(net.opengis.sampling.x10.SamplingSurfaceType) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point) SamplingCurveDocument(net.opengis.sampling.x10.SamplingCurveDocument) SamplingCurveType(net.opengis.sampling.x10.SamplingCurveType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SamplingPointDocument(net.opengis.sampling.x10.SamplingPointDocument) LineString(org.locationtech.jts.geom.LineString) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingPointType(net.opengis.sampling.x10.SamplingPointType) XmlObject(org.apache.xmlbeans.XmlObject) SamplingSurfaceDocument(net.opengis.sampling.x10.SamplingSurfaceDocument) Polygon(org.locationtech.jts.geom.Polygon)

Example 5 with AbstractSamplingFeature

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

the class SamplingEncoderv100 method addValuesToFeature.

private void addValuesToFeature(SamplingFeatureType xbSamplingFeature, AbstractSamplingFeature sampFeat) throws EncodingException {
    xbSamplingFeature.setId(sampFeat.getGmlId());
    if (sampFeat.isSetIdentifier()) {
        sampFeat.getIdentifierCodeWithAuthority().setCodeSpace("uniquID");
        xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sampFeat.getIdentifierCodeWithAuthority()));
    }
    if (sampFeat.isSetName()) {
        for (CodeType sosName : sampFeat.getName()) {
            xbSamplingFeature.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, sosName));
        }
    }
    // TODO: CHECK
    if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
        for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
            FeaturePropertyType sp = xbSamplingFeature.addNewSampledFeature();
            sp.setHref(sampledFeature.getIdentifier());
            if (sampFeat.isSetName() && sampFeat.getFirstName().isSetValue()) {
                sp.setTitle(sampFeat.getFirstName().getValue());
            }
        // xbSamplingFeature.addNewSampledFeature().set(createFeature(sampledFeature));
        }
    } else {
        xbSamplingFeature.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
    }
    // set metadataProperty
    setMetaDataProperty(xbSamplingFeature, sampFeat);
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) SamplingFeaturePropertyType(net.opengis.sampling.x10.SamplingFeaturePropertyType) FeaturePropertyType(net.opengis.gml.FeaturePropertyType)

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