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;
}
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));
}
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));
}
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);
}
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;
}
Aggregations