Search in sources :

Example 6 with GeometryValue

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

the class ObservationDecoder method parseNamedValueValue.

private NamedValue<?> parseNamedValueValue(JsonNode value) throws DecodingException {
    if (value.isTextual()) {
        NamedValue<W3CHrefAttribute> nv = new NamedValue<>();
        nv.setValue(new HrefAttributeValue(new W3CHrefAttribute(value.asText())));
        return nv;
    } else if (value.isBoolean()) {
        NamedValue<Boolean> nv = new NamedValue<>();
        nv.setValue(new BooleanValue(value.asBoolean()));
        return nv;
    } else if (value.isInt()) {
        NamedValue<Integer> nv = new NamedValue<>();
        nv.setValue(new CountValue(value.asInt()));
        return nv;
    } else if (value.isObject()) {
        if (value.has(JSONConstants.CODESPACE)) {
            NamedValue<String> nv = new NamedValue<>();
            nv.setValue(parseCategroyValue(value));
            return nv;
        } else if (value.has(JSONConstants.UOM)) {
            NamedValue<BigDecimal> nv = new NamedValue<>();
            nv.setValue(parseQuantityValue(value));
            return nv;
        } else if (value.has(JSONConstants.COORDINATES)) {
            NamedValue<Geometry> nv = new NamedValue<>();
            nv.setValue(new GeometryValue(geometryDecoder.decodeJSON(value, false)));
            return nv;
        }
    }
    throw new DecodingException("%s is not yet supported", value.toString());
}
Also used : NamedValue(org.n52.shetland.ogc.om.NamedValue) DecodingException(org.n52.svalbard.decode.exception.DecodingException) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) BigDecimal(java.math.BigDecimal) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue)

Example 7 with GeometryValue

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

the class PointObservation method setValue.

@Override
public void setValue(ObservationValue<?> value) {
    if (value instanceof StreamingValue<?>) {
        super.setValue(value);
    } else if (value.getValue() instanceof CvDiscretePointCoverage) {
        super.setValue(value);
    } else {
        CvDiscretePointCoverage cvDiscretePointCoverage = new CvDiscretePointCoverage(getObservationID());
        cvDiscretePointCoverage.setRangeType(new ReferenceType(getObservationConstellation().getObservablePropertyIdentifier()));
        cvDiscretePointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
        Geometry geometry = null;
        String domainExtent = "";
        if (isSetSpatialFilteringProfileParameter() && getSpatialFilteringProfileParameter().getValue() instanceof GeometryValue) {
            GeometryValue geometryValue = (GeometryValue) getSpatialFilteringProfileParameter().getValue();
            geometry = getSpatialFilteringProfileParameter().getValue().getValue();
            domainExtent = geometryValue.getGmlId();
        } else if (checkForFeatureGeometry(this)) {
            geometry = getGeometryFromFeature(this);
            domainExtent = getObservationConstellation().getFeatureOfInterest().getGmlId();
        }
        if (geometry != null) {
            cvDiscretePointCoverage.setDomainExtent("#" + geometry.getGeometryType() + "_" + domainExtent);
            Point point = null;
            if (geometry instanceof Point) {
                point = (Point) geometry;
            } else {
                point = geometry.getCentroid();
            }
            cvDiscretePointCoverage.setValue(new PointValuePair(point, value.getValue()));
        }
        super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), cvDiscretePointCoverage));
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CvDiscretePointCoverage(org.n52.shetland.ogc.om.values.CvDiscretePointCoverage) AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) Point(org.locationtech.jts.geom.Point) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 8 with GeometryValue

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

the class GeometryObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_GEOMETRY_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(GeometryValue.class)));
    GeometryValue v = (GeometryValue) value.getValue();
    assertThat(v.getUnit(), is(nullValue()));
    Geometry g = v.getValue();
    assertThat(g, is(instanceOf(LineString.class)));
    assertThat(g.getSRID(), is(2000));
    assertThat(g.getNumPoints(), is(2));
    assertThat(g.getCoordinates()[0], is(equalTo(new Coordinate(52, 7))));
    assertThat(g.getCoordinates()[1], is(equalTo(new Coordinate(51, 7))));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Example 9 with GeometryValue

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

the class AbstractGmlDecoderv321 method parseNamedValueValue.

protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
    XmlObject xmlObject = xml;
    if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
        try {
            xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
        } catch (XmlException e) {
            LOGGER.error("Error while parsing NamedValueValue", e);
        }
    }
    Object value;
    if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlBoolean) xmlObject).getBooleanValue();
    } else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlString) xmlObject).getStringValue();
    } else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInt) xmlObject).getIntValue();
    } else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
    } else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlDouble) xmlObject).getDoubleValue();
    } else {
        value = decodeXmlObject(xmlObject);
    }
    if (value instanceof BooleanValue) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue((BooleanValue) value);
        return namedValue;
    } else if (value instanceof SweBoolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
        return namedValue;
    } else if (value instanceof Boolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue((Boolean) value));
        return namedValue;
    } else if (value instanceof CategoryValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((CategoryValue) value);
        return namedValue;
    } else if (value instanceof SweCategory) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
        return namedValue;
    } else if (value instanceof CountValue) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue((CountValue) value);
        return namedValue;
    } else if (value instanceof SweCount) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue(((SweCount) value).getValue()));
        return namedValue;
    } else if (value instanceof Integer) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue((Integer) value));
        return namedValue;
    } else if (value instanceof GeometryValue) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue((GeometryValue) value);
        return namedValue;
    } else if (value instanceof QuantityValue) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue((QuantityValue) value);
        return namedValue;
    } else if (value instanceof GmlMeasureType) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
        return namedValue;
    } else if (value instanceof SweQuantity) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
        return namedValue;
    } else if (value instanceof Double) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue((Double) value));
        return namedValue;
    } else if (value instanceof TextValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((TextValue) value);
        return namedValue;
    } else if (value instanceof SweText) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue(((SweText) value).getValue()));
        return namedValue;
    } else if (value instanceof String) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue((String) value));
        return namedValue;
    } else if (value instanceof AbstractGeometry) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue(new GeometryValue((AbstractGeometry) value));
        return namedValue;
    } else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
        namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
        return namedValue;
    } else if (value instanceof W3CHrefAttribute) {
        NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
        namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
        return namedValue;
    } else {
        throw new UnsupportedDecoderInputException(this, xmlObject);
    }
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) NamedValue(org.n52.shetland.ogc.om.NamedValue) XmlString(org.apache.xmlbeans.XmlString) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) XmlBoolean(org.apache.xmlbeans.XmlBoolean) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue) XmlString(org.apache.xmlbeans.XmlString) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) XmlDouble(org.apache.xmlbeans.XmlDouble) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) BigDecimal(java.math.BigDecimal) XmlInteger(org.apache.xmlbeans.XmlInteger) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) XmlException(org.apache.xmlbeans.XmlException) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Aggregations

GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)9 Geometry (org.locationtech.jts.geom.Geometry)6 BooleanValue (org.n52.shetland.ogc.om.values.BooleanValue)5 CountValue (org.n52.shetland.ogc.om.values.CountValue)5 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)4 CategoryValue (org.n52.shetland.ogc.om.values.CategoryValue)4 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)4 TextValue (org.n52.shetland.ogc.om.values.TextValue)4 XmlBoolean (org.apache.xmlbeans.XmlBoolean)3 XmlInteger (org.apache.xmlbeans.XmlInteger)3 XmlString (org.apache.xmlbeans.XmlString)3 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)3 BigDecimal (java.math.BigDecimal)2 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 Test (org.junit.Test)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)2 GmlMeasureType (org.n52.shetland.ogc.gml.GmlMeasureType)2 NamedValue (org.n52.shetland.ogc.om.NamedValue)2