Search in sources :

Example 16 with SweQuantity

use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.

the class SweCommonDecoderV101Test method should_decode_Quantity_with_Quality_Category.

@Test
public void should_decode_Quantity_with_Quality_Category() throws DecodingException {
    final QuantityDocument xbQuantity = QuantityDocument.Factory.newInstance();
    final String categoryValue = "quality-category";
    xbQuantity.addNewQuantity().addNewQuality().addNewCategory().setValue(categoryValue);
    final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
    assertThat(decodedObject, is(instanceOf(SweQuantity.class)));
    final SweQuantity sweQuantity = (SweQuantity) decodedObject;
    assertThat(sweQuantity.isSetQuality(), is(true));
    assertThat(sweQuantity.getQuality().size(), is(1));
    assertThat(sweQuantity.getQuality().iterator().next(), is(instanceOf(SweCategory.class)));
    assertThat(((SweCategory) sweQuantity.getQuality().iterator().next()).getValue(), is(categoryValue));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) QuantityDocument(net.opengis.swe.x101.QuantityDocument) Test(org.junit.Test)

Example 17 with SweQuantity

use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.

the class SweEnvelopeTest method should_create_valid_sosSweEnvelope_from_sosEnvelope.

@Test
public void should_create_valid_sosSweEnvelope_from_sosEnvelope() {
    final int srid = 52;
    final double x1 = 1;
    final double y1 = 2;
    final double y2 = 3;
    final double x2 = 4;
    final BigDecimal bx1 = new BigDecimal(x1);
    final BigDecimal by1 = new BigDecimal(y1);
    final BigDecimal by2 = new BigDecimal(y2);
    final BigDecimal bx2 = new BigDecimal(x2);
    final String uom = "deg";
    final ReferencedEnvelope sosEnvelope = new ReferencedEnvelope(new Envelope(x1, x2, y1, y2), srid);
    final SweEnvelope sweEnvelope = new SweEnvelope(sosEnvelope, uom, false);
    // srid
    assertThat(sweEnvelope.getReferenceFrame(), is(Integer.toString(srid)));
    // x1
    final List<? extends SweCoordinate<?>> lcCoordinates = sweEnvelope.getLowerCorner().getCoordinates();
    assertThat(((BigDecimal) lcCoordinates.get(0).getValue().getValue()), is(bx1));
    // y1
    assertThat(((BigDecimal) lcCoordinates.get(1).getValue().getValue()), is(by1));
    // x2
    final List<? extends SweCoordinate<?>> ucCoordinates = sweEnvelope.getUpperCorner().getCoordinates();
    assertThat(((BigDecimal) ucCoordinates.get(0).getValue().getValue()), is(bx2));
    // y2
    assertThat(((BigDecimal) ucCoordinates.get(1).getValue().getValue()), is(by2));
    // uom
    assertThat(((SweQuantity) lcCoordinates.get(0).getValue()).getUom(), is(uom));
    assertThat(((SweQuantity) lcCoordinates.get(1).getValue()).getUom(), is(uom));
    assertThat(((SweQuantity) ucCoordinates.get(0).getValue()).getUom(), is(uom));
    assertThat(((SweQuantity) ucCoordinates.get(1).getValue()).getUom(), is(uom));
    // northing
    assertThat(lcCoordinates.get(0).getName(), is(SweCoordinateNames.EASTING));
    assertThat(ucCoordinates.get(0).getName(), is(SweCoordinateNames.EASTING));
    // easting
    assertThat(lcCoordinates.get(1).getName(), is(SweCoordinateNames.NORTHING));
    assertThat(ucCoordinates.get(1).getName(), is(SweCoordinateNames.NORTHING));
}
Also used : ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 18 with SweQuantity

use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.

the class SweEnvelope method createSweVector.

private static SweVector createSweVector(double x, double y, String uom) {
    SweQuantity xCoord = new SweQuantity().setAxisID(SweConstants.X_AXIS).setValue(x).setUom(uom);
    SweQuantity yCoord = new SweQuantity().setAxisID(SweConstants.Y_AXIS).setValue(y).setUom(uom);
    return new SweVector(new SweCoordinate<>(SweCoordinateNames.EASTING, xCoord), new SweCoordinate<>(SweCoordinateNames.NORTHING, yCoord));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity)

Example 19 with SweQuantity

use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.

the class FieldDecoderTest method testQuantityWithValue.

@Test
public void testQuantityWithValue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.QUANTITY_TYPE).put(JSONConstants.UOM, UOM).put(JSONConstants.VALUE, QUANTITY_VALUE_START);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweQuantity.class)));
    SweQuantity swe = (SweQuantity) field.getElement();
    errors.checkThat(swe.getValue().doubleValue(), is(QUANTITY_VALUE_START));
    errors.checkThat(swe.getUom(), is(UOM));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) Test(org.junit.Test)

Example 20 with SweQuantity

use of org.n52.shetland.ogc.swe.simpleType.SweQuantity 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

SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)22 Test (org.junit.Test)11 XmlObject (org.apache.xmlbeans.XmlObject)9 SweField (org.n52.shetland.ogc.swe.SweField)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)9 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)8 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)8 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)7 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)5 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)5 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)5 SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 BigDecimal (java.math.BigDecimal)3 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)3 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3