Search in sources :

Example 1 with OmObservation

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

the class OmObservationTest method should_have_SpatialFilteringProfileParameter.

@Test
public final void should_have_SpatialFilteringProfileParameter() throws OwsExceptionReport, DecodingException {
    OmObservation omObservation = new OmObservation();
    NamedValue<Geometry> namedValue = new NamedValue<>();
    namedValue.setName(new ReferenceType(OmConstants.PARAM_NAME_SAMPLING_GEOMETRY));
    GeometryFactory fac = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    namedValue.setValue(new GeometryValue(fac.createPoint(new Coordinate(34.5, 76.4))));
    // test no parameter is set
    assertFalse(omObservation.isSetParameter());
    assertFalse(omObservation.isSetSpatialFilteringProfileParameter());
    omObservation.addParameter(namedValue);
    // test with set SpatialFilteringProfile parameter
    assertTrue(omObservation.isSetParameter());
    assertTrue(omObservation.isSetSpatialFilteringProfileParameter());
    assertThat(omObservation.getSpatialFilteringProfileParameter(), is(equalTo(namedValue)));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) Test(org.junit.Test)

Example 2 with OmObservation

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

the class SweHelper method createSosSweDataArray.

/**
 * Create {@link SweDataArray} from {@link OmObservation}
 *
 * @param sosObservation
 *            The {@link OmObservation} to create {@link SweDataArray} from
 *
 * @return Created {@link SweDataArray}
 *
 * @throws EncodingException
 *             If the service does not support the {@link SweDataArray}
 *             creation from value of {@link OmObservation}
 */
public SweDataArray createSosSweDataArray(OmObservation sosObservation) throws EncodingException {
    String observablePropertyIdentifier = sosObservation.getObservationConstellation().getObservableProperty().getIdentifier();
    SweDataArrayValue dataArrayValue = new SweDataArrayValue();
    SweDataArray dataArray = new SweDataArray();
    dataArray.setEncoding(createTextEncoding(sosObservation));
    dataArrayValue.setValue(dataArray);
    if (sosObservation.getValue() instanceof SingleObservationValue) {
        SingleObservationValue<?> singleValue = (SingleObservationValue<?>) sosObservation.getValue();
        if (singleValue.getValue() instanceof SweDataArrayValue) {
            return (SweDataArray) singleValue.getValue().getValue();
        } else {
            dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
            dataArrayValue.addBlock(createBlock(dataArray.getElementType(), sosObservation.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
        }
    } else if (sosObservation.getValue() instanceof MultiObservationValues) {
        MultiObservationValues<?> multiValue = (MultiObservationValues<?>) sosObservation.getValue();
        if (multiValue.getValue() instanceof SweDataArrayValue) {
            return ((SweDataArrayValue) multiValue.getValue()).getValue();
        } else if (multiValue.getValue() instanceof TVPValue) {
            TVPValue tvpValues = (TVPValue) multiValue.getValue();
            for (TimeValuePair timeValuePair : tvpValues.getValue()) {
                if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
                    if (!dataArray.isSetElementTyp()) {
                        dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
                    }
                    List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
                    dataArrayValue.addBlock(newBlock);
                }
            }
        }
    }
    return dataArray;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 3 with OmObservation

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

the class UVFEncoder method getFilename.

private String getFilename(List<OmObservation> observations) {
    Set<String> identifiers = new HashSet<>();
    for (OmObservation o : observations) {
        if (o.getObservationConstellation().isSetIdentifier()) {
            identifiers.add(o.getObservationConstellation().getIdentifier());
        }
    }
    StringBuffer pathBuffer = new StringBuffer();
    if (!identifiers.isEmpty()) {
        for (String identifier : identifiers) {
            pathBuffer.append(identifier).append("_");
        }
        pathBuffer.replace(pathBuffer.lastIndexOf("_"), pathBuffer.length(), "");
    } else {
        pathBuffer.append("_").append(Long.toString(java.lang.System.nanoTime()));
    }
    pathBuffer.append(".uvf");
    return pathBuffer.toString();
}
Also used : OmObservation(org.n52.shetland.ogc.om.OmObservation) HashSet(java.util.HashSet)

Example 4 with OmObservation

use of org.n52.shetland.ogc.om.OmObservation 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 5 with OmObservation

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

the class UVFEncoder method writeMessStellenname.

private void writeMessStellenname(Writer fw, OmObservation o, String lineEnding) throws IOException {
    if (o.getObservationConstellation().getFeatureOfInterest().isSetName()) {
        final CodeType firstName = o.getObservationConstellation().getFeatureOfInterest().getFirstName();
        String name = ensureIdentifierLength(firstName.isSetValue() ? firstName.getValue() : "", UVFConstants.MAX_IDENTIFIER_LENGTH);
        writeToFile(fw, String.format("$sb Mess-Stellenname: %s", name), lineEnding);
    }
}
Also used : CodeType(org.n52.shetland.ogc.gml.CodeType)

Aggregations

OmObservation (org.n52.shetland.ogc.om.OmObservation)32 XmlObject (org.apache.xmlbeans.XmlObject)17 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)16 Time (org.n52.shetland.ogc.gml.time.Time)15 EncodingException (org.n52.svalbard.encode.exception.EncodingException)14 DateTime (org.joda.time.DateTime)13 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)11 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)11 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)10 XmlString (org.apache.xmlbeans.XmlString)9 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)9 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)9 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)7 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)7 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)7 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)6 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)6 List (java.util.List)5 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)5 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)5