Search in sources :

Example 1 with SweEnvelope

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

the class SweCommonEncoderv101 method encode.

@Override
public XmlObject encode(Object element, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof SweAbstractSimpleType) {
        encodedObject = createSimpleType((SweAbstractSimpleType<?>) element, context);
    // }
    // if (element instanceof SweBoolean) {
    // encodedObject = createBoolean((SweBoolean) element);
    // } else if (element instanceof SweCategory) {
    // encodedObject = createCategory((SweCategory) element);
    // } else if (element instanceof SweCount) {
    // encodedObject = createCount((SweCount) element);
    // } else if (element instanceof SweObservableProperty) {
    // encodedObject = createObservableProperty((SweObservableProperty)
    // element);
    // } else if (element instanceof SweQuantity) {
    // encodedObject = createQuantity((SweQuantity) element);
    // } else if (element instanceof SweQuantityRange) {
    // encodedObject = createQuantityRange((SweQuantityRange) element);
    // } else if (element instanceof SweText) {
    // encodedObject = createText((SweText) element);
    // } else if (element instanceof SweTime) {
    // encodedObject = createTime((SweTime) element);
    // } else if (element instanceof SweTimeRange) {
    // encodedObject = createTimeRange((SweTimeRange) element);
    } else if (element instanceof SweCoordinate) {
        encodedObject = createCoordinate((SweCoordinate<?>) element);
    } else if (element instanceof SweDataArray) {
        encodedObject = createDataArray((SweDataArray) element);
    } else if (element instanceof SweDataRecord) {
        DataRecordType drt = createDataRecord((SweDataRecord) element);
        if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
            DataRecordDocument drd = DataRecordDocument.Factory.newInstance(getXmlOptions());
            drd.setDataRecord(drt);
            encodedObject = drd;
        } else {
            encodedObject = drt;
        }
    } else if (element instanceof SweEnvelope) {
        encodedObject = createEnvelope((SweEnvelope) element);
    } else if (element instanceof SweSimpleDataRecord) {
        encodedObject = createSimpleDataRecord((SweSimpleDataRecord) element);
    } else if (element instanceof TimePeriod) {
        encodedObject = createTimeGeometricPrimitivePropertyType((TimePeriod) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x101.DataRecordDocument) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 2 with SweEnvelope

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

the class SweCommonEncoderv101Test method should_encode_ReferencedEnvelope.

@Test
public void should_encode_ReferencedEnvelope() throws EncodingException {
    final int srid = 4326;
    final double y1 = 7.0;
    final double x1 = 51.0;
    final double y2 = 8.0;
    final double x2 = 52.0;
    final String uom = "test-uom";
    final String definition = "test-definition";
    final SweEnvelope sweEnvelope = new SweEnvelope(new ReferencedEnvelope(new Envelope(x1, x2, y1, y2), srid), uom, true);
    final String xAxisId = "x";
    final String yAxisId = "y";
    final String northing = "northing";
    final String easting = "easting";
    sweEnvelope.setDefinition(definition);
    final XmlObject encode = sweCommonEncoderv101.encode(sweEnvelope);
    assertThat(encode, instanceOf(EnvelopeType.class));
    final EnvelopeType xbEnvelope = (EnvelopeType) encode;
    assertThat(xbEnvelope.isSetDefinition(), is(true));
    assertThat(xbEnvelope.getDefinition(), is(definition));
    final Coordinate lcX = xbEnvelope.getLowerCorner().getVector().getCoordinateArray(0);
    assertThat(lcX.getName(), is(easting));
    assertThat(lcX.getQuantity().getAxisID(), is(xAxisId));
    assertThat(lcX.getQuantity().getUom().getCode(), is(uom));
    assertThat(lcX.getQuantity().getValue(), is(y1));
    final Coordinate lcY = xbEnvelope.getLowerCorner().getVector().getCoordinateArray(1);
    assertThat(lcY.getName(), is(northing));
    assertThat(lcY.getQuantity().getAxisID(), is(yAxisId));
    assertThat(lcY.getQuantity().getUom().getCode(), is(uom));
    assertThat(lcY.getQuantity().getValue(), is(x1));
    final Coordinate ucX = xbEnvelope.getUpperCorner().getVector().getCoordinateArray(0);
    assertThat(ucX.getName(), is(easting));
    assertThat(ucX.getQuantity().getAxisID(), is(xAxisId));
    assertThat(ucX.getQuantity().getUom().getCode(), is(uom));
    assertThat(ucX.getQuantity().getValue(), is(y2));
    final Coordinate ucY = xbEnvelope.getUpperCorner().getVector().getCoordinateArray(1);
    assertThat(ucY.getName(), is(northing));
    assertThat(ucY.getQuantity().getAxisID(), is(yAxisId));
    assertThat(ucY.getQuantity().getUom().getCode(), is(uom));
    assertThat(ucY.getQuantity().getValue(), is(x2));
    assertThat(xbEnvelope.isSetReferenceFrame(), is(true));
    assertThat(xbEnvelope.getReferenceFrame(), is("" + srid));
}
Also used : ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) EnvelopeType(net.opengis.swe.x101.EnvelopeType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Coordinate(net.opengis.swe.x101.VectorType.Coordinate) XmlObject(org.apache.xmlbeans.XmlObject) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Test(org.junit.Test)

Example 3 with SweEnvelope

use of org.n52.shetland.ogc.swe.SweEnvelope 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 4 with SweEnvelope

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

the class SweCommonDecoderV101 method parseEnvelope.

private SweAbstractDataComponent parseEnvelope(EnvelopeType envelopeType) throws DecodingException {
    String referenceFrame = null;
    SweVector lowerCorner = null;
    SweVector upperCorner = null;
    SweTimeRange time = null;
    if (envelopeType.isSetReferenceFrame()) {
        referenceFrame = envelopeType.getReferenceFrame();
    }
    if (envelopeType.getLowerCorner() != null) {
        lowerCorner = parseVectorProperty(envelopeType.getLowerCorner());
    }
    if (envelopeType.getUpperCorner() != null) {
        upperCorner = parseVectorProperty(envelopeType.getUpperCorner());
    }
    if (envelopeType.isSetTime()) {
        time = parseTimeRange(envelopeType.getTime().getTimeRange());
    }
    // FIXME get the northing first value for the reference frame
    boolean northingFirst = false;
    return new SweEnvelope(referenceFrame, upperCorner, lowerCorner, time, northingFirst);
}
Also used : SweVector(org.n52.shetland.ogc.swe.SweVector) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

Example 5 with SweEnvelope

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

the class SweCommonEncoderv101 method createDataArray.

private DataArrayDocument createDataArray(SweDataArray sosDataArray) throws EncodingException {
    if (sosDataArray != null) {
        if (sosDataArray.isSetElementTyp()) {
            DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
            DataArrayType xbDataArray = xbDataArrayDoc.addNewDataArray1();
            // set element count
            if (sosDataArray.isSetElementCount()) {
                xbDataArray.addNewElementCount().addNewCount().set(createCount(sosDataArray.getElementCount()));
            }
            if (sosDataArray.isSetElementTyp()) {
                DataComponentPropertyType xbElementType = xbDataArray.addNewElementType();
                xbElementType.setName("Components");
                // FIXME use visitor pattern
                if (sosDataArray.getElementType() instanceof SweBoolean) {
                    xbElementType.addNewBoolean().set(createSimpleType((SweBoolean) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCategory) {
                    xbElementType.addNewCategory().set(createSimpleType((SweCategory) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweCount) {
                    xbElementType.addNewCount().set(createSimpleType((SweCount) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweQuantity) {
                    xbElementType.addNewQuantity().set(createSimpleType((SweQuantity) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweText) {
                    xbElementType.addNewText().set(createSimpleType((SweText) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTimeRange) {
                    xbElementType.addNewTimeRange().set(createSimpleType((SweTimeRange) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweTime) {
                    xbElementType.addNewTime().set(createSimpleType((SweTime) sosDataArray.getElementType()));
                } else if (sosDataArray.getElementType() instanceof SweEnvelope) {
                    xbElementType.addNewAbstractDataRecord().set(createEnvelope((SweEnvelope) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataRecord) {
                    xbElementType.addNewAbstractDataRecord().set(createDataRecord((SweDataRecord) sosDataArray.getElementType()));
                    xbElementType.getAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
                } else if (sosDataArray.getElementType() instanceof SweDataArray) {
                    xbElementType.addNewAbstractDataArray1().set(createDataArray((SweDataArray) sosDataArray.getElementType()).getDataArray1());
                    xbElementType.getAbstractDataArray1().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
                } else {
                    throw new UnsupportedEncoderInputException(this, sosDataArray.getElementType());
                }
            }
            if (sosDataArray.isSetEncoding()) {
                BlockEncodingPropertyType xbEncoding = xbDataArray.addNewEncoding();
                xbEncoding.set(createBlockEncoding(sosDataArray.getEncoding()));
            // xbDataArray.getEncoding().substitute(
            // new QName(SWEConstants.NS_SWE_101,
            // SWEConstants.EN_TEXT_ENCODING,
            // SWEConstants.NS_SWE_PREFIX), TextBlock.type);
            }
            // }
            if (sosDataArray.isSetValues()) {
                xbDataArray.addNewValues().set(createValues(sosDataArray.getValues(), sosDataArray.getEncoding()));
            }
            return xbDataArrayDoc;
        } else if (sosDataArray.isSetXml()) {
            try {
                XmlObject xmlObject = XmlObject.Factory.parse(sosDataArray.getXml().trim());
                if (xmlObject instanceof DataArrayDocument) {
                    return (DataArrayDocument) xmlObject;
                } else {
                    DataArrayDocument xbDataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
                    xbDataArrayDoc.setDataArray1(DataArrayType.Factory.parse(sosDataArray.getXml().trim()));
                    return xbDataArrayDoc;
                }
            } catch (XmlException e) {
                throw new EncodingException("Error while encoding SweDataArray!", e);
            }
        }
    }
    return null;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) BlockEncodingPropertyType(net.opengis.swe.x101.BlockEncodingPropertyType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DataArrayDocument(net.opengis.swe.x101.DataArrayDocument) DataArrayType(net.opengis.swe.x101.DataArrayType)

Aggregations

SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)5 XmlObject (org.apache.xmlbeans.XmlObject)4 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)3 DataArrayType (net.opengis.swe.x101.DataArrayType)2 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)2 DataRecordType (net.opengis.swe.x101.DataRecordType)2 EnvelopeType (net.opengis.swe.x101.EnvelopeType)2 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)2 Test (org.junit.Test)2 Envelope (org.locationtech.jts.geom.Envelope)2 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)2 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)2 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)2 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)2 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)2 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)2