use of org.geotoolkit.swe.xml.v101.DataArrayType in project arctic-sea by 52North.
the class OmEncoderv100Test method testMetadataEncoding.
@Test
public void testMetadataEncoding() throws EncodingException, XmlException {
XmlObject encode = encoder.encode(createResponse());
assertThat(encode, instanceOf(ObservationCollectionDocument.class));
ObservationCollectionDocument ocd = (ObservationCollectionDocument) encode;
assertThat(ocd.getObservationCollection().getMetaDataPropertyArray().length, is(1));
XmlObject parse = XmlObject.Factory.parse(ocd.getObservationCollection().getMetaDataPropertyArray(0).xmlText());
assertThat(parse, instanceOf(DataArrayDocument.class));
DataArrayDocument dad = (DataArrayDocument) parse;
assertThat(dad.getAbstractDataArray1(), instanceOf(DataArrayType.class));
DataArrayType dat = (DataArrayType) dad.getAbstractDataArray1();
assertThat(dat.getElementType().isSetAbstractDataRecord(), is(true));
assertThat(dat.getElementType().getAbstractDataRecord(), instanceOf(SimpleDataRecordType.class));
}
use of org.geotoolkit.swe.xml.v101.DataArrayType in project arctic-sea by 52North.
the class AbstractMetadataTest method checkMetadataResponse.
protected void checkMetadataResponse(XmlObject[] extensionArray) throws XmlException {
assertThat(extensionArray != null, is(true));
assertThat(extensionArray.length, is(1));
XmlObject parse = XmlObject.Factory.parse(extensionArray[0].xmlText());
assertThat(parse, instanceOf(DataArrayPropertyType.class));
DataArrayPropertyType dad = (DataArrayPropertyType) parse;
assertThat(dad.getDataArray1(), instanceOf(DataArrayType.class));
DataArrayType dat = dad.getDataArray1();
assertThat(dat.getElementType().isSetAbstractDataComponent(), is(true));
assertThat(dat.getElementType().getAbstractDataComponent(), instanceOf(DataRecordType.class));
}
use of org.geotoolkit.swe.xml.v101.DataArrayType in project geotoolkit by Geomatys.
the class ObservationXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws java.lang.Exception
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
PointType location = new PointType("point-ID", pos);
SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
TimePeriodType samplingTime = new TimePeriodType("t1", "2007-01-01", "2008-09-09");
TextBlockType encoding = new TextBlockType("encoding-001", ",", "@@", ".");
List<AnyScalarPropertyType> fields = new ArrayList<>();
AnyScalarPropertyType field = new AnyScalarPropertyType("text-field-001", new Text("urn:something", "some value"));
fields.add(field);
SimpleDataRecordType record = new SimpleDataRecordType(fields);
DataArrayType array = new DataArrayType("array-001", 1, "array-001", record, encoding, "somevalue", null);
DataArrayPropertyType arrayProp = new DataArrayPropertyType(array);
ObservationType obs = new ObservationType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
StringWriter sw = new StringWriter();
marshaller.marshal(obs, sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<om:Observation xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod gml:id=\"t1\">" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"swe:DataArrayPropertyType\" >" + '\n' + " <swe:DataArray gml:id=\"array-001\">" + '\n' + " <swe:elementCount>" + '\n' + " <swe:Count>" + '\n' + " <swe:value>1</swe:value>" + '\n' + " </swe:Count>" + '\n' + " </swe:elementCount>" + '\n' + " <swe:elementType name=\"array-001\">" + '\n' + " <swe:SimpleDataRecord>" + '\n' + " <swe:field name=\"text-field-001\">" + '\n' + " <swe:Text definition=\"urn:something\">" + '\n' + " <swe:value>some value</swe:value>" + '\n' + " </swe:Text>" + '\n' + " </swe:field>" + '\n' + " </swe:SimpleDataRecord>" + '\n' + " </swe:elementType>" + '\n' + " <swe:encoding>" + '\n' + " <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-001\"/>" + '\n' + " </swe:encoding>" + '\n' + " <swe:values>somevalue</swe:values>" + '\n' + " </swe:DataArray>" + '\n' + " </om:result>" + '\n' + "</om:Observation>\n";
assertXmlEquals(expResult, result, "xmlns:*");
UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", "meters", "distance", "meters");
MeasureType meas = new MeasureType(uom, 7);
MeasurementType measmt = new MeasurementType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", meas, samplingTime);
sw = new StringWriter();
marshaller.marshal(measmt, sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<om:Measurement xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + " <gml:name>urn:Observation-007</gml:name>" + '\n' + " <om:samplingTime>" + '\n' + " <gml:TimePeriod gml:id=\"t1\">" + '\n' + " <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + " </gml:TimePeriod>" + '\n' + " </om:samplingTime>" + '\n' + " <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + " <om:observedProperty>" + '\n' + " <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + " <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + " </swe:Phenomenon>" + '\n' + " </om:observedProperty>" + '\n' + " <om:featureOfInterest>" + '\n' + " <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + " <gml:description>a sampling Test</gml:description>" + '\n' + " <gml:name>urn:sampling:test:007</gml:name>" + '\n' + " <gml:boundedBy>" + '\n' + " <gml:Null>not_bounded</gml:Null>" + '\n' + " </gml:boundedBy>" + '\n' + " <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + " <sampling:position>" + '\n' + " <gml:Point gml:id=\"point-ID\">" + '\n' + " <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </sampling:position>" + '\n' + " </sampling:SamplingPoint>" + '\n' + " </om:featureOfInterest>" + '\n' + " <om:result xsi:type=\"om:MeasureType\" uom=\"meters\">7.0</om:result>" + '\n' + "</om:Measurement>\n";
assertXmlEquals(expResult, result, "xmlns:*");
ObservationCollectionType collection = new ObservationCollectionType();
collection.add(measmt);
sw = new StringWriter();
marshaller.marshal(collection, sw);
result = sw.toString();
// System.out.println(result);
collection = new ObservationCollectionType();
collection.add(obs.getTemporaryTemplate("temporaryName", samplingTime));
sw = new StringWriter();
marshaller.marshal(collection, sw);
result = sw.toString();
}
use of org.geotoolkit.swe.xml.v101.DataArrayType in project geotoolkit by Geomatys.
the class OMXmlFactory method convertTo100.
private static AbstractObservation convertTo100(final Observation observation) {
final String name = (observation.getName() != null) ? observation.getName().getCode() : "";
final String definition = observation.getDefinition();
final org.geotoolkit.gml.xml.v311.AbstractTimeGeometricPrimitiveType time;
if (observation.getSamplingTime() instanceof Period) {
final Period p = (Period) observation.getSamplingTime();
String dateBegin = null;
if (p.getBeginning() != null && p.getBeginning().getDate() != null) {
dateBegin = p.getBeginning().getDate().toString();
}
String dateEnd = null;
if (p.getEnding() != null && p.getEnding().getDate() != null) {
dateEnd = p.getEnding().getDate().toString();
}
time = (org.geotoolkit.gml.xml.v311.AbstractTimeGeometricPrimitiveType) GMLXmlFactory.createTimePeriod("3.1.1", null, dateBegin, dateEnd);
} else if (observation.getSamplingTime() instanceof Instant) {
final Instant p = (Instant) observation.getSamplingTime();
String date = null;
if (p.getDate() != null) {
date = p.getDate().toString();
}
time = (org.geotoolkit.gml.xml.v311.AbstractTimeGeometricPrimitiveType) GMLXmlFactory.createTimeInstant("3.1.1", null, date);
} else if (observation.getSamplingTime() != null) {
throw new IllegalArgumentException("Unexpected samplingTime type:" + observation.getSamplingTime().getClass().getName());
} else {
time = null;
}
final String procedure = ((org.geotoolkit.observation.xml.Process) observation.getProcedure()).getHref();
final Identifier idName = ((org.geotoolkit.swe.xml.Phenomenon) observation.getObservedProperty()).getName();
final String phenomenonName = (idName != null) ? idName.getCode() : "";
// extract id
final String phenId;
if (phenomenonName.indexOf(':') != -1) {
phenId = phenomenonName.substring(phenomenonName.lastIndexOf(':') + 1, phenomenonName.length());
} else {
phenId = phenomenonName;
}
final org.geotoolkit.swe.xml.v101.PhenomenonType observedProperty = new PhenomenonType(phenId, phenomenonName);
final org.geotoolkit.sampling.xml.v100.SamplingFeatureType sf = (org.geotoolkit.sampling.xml.v100.SamplingFeatureType) convertTo100((SamplingFeature) observation.getFeatureOfInterest());
final Object result;
if (observation.getResult() instanceof org.geotoolkit.swe.xml.v200.DataArrayPropertyType) {
final org.geotoolkit.swe.xml.v200.DataArrayPropertyType resultv200 = (org.geotoolkit.swe.xml.v200.DataArrayPropertyType) observation.getResult();
final org.geotoolkit.swe.xml.v200.TextEncodingType encodingV200 = (org.geotoolkit.swe.xml.v200.TextEncodingType) resultv200.getDataArray().getEncoding();
final int count = resultv200.getDataArray().getElementCount().getCount().getValue();
final String id = resultv200.getDataArray().getId();
final org.geotoolkit.swe.xml.v101.TextBlockType enc = new org.geotoolkit.swe.xml.v101.TextBlockType(encodingV200.getId(), encodingV200.getDecimalSeparator(), encodingV200.getTokenSeparator(), encodingV200.getBlockSeparator());
final String values = resultv200.getDataArray().getValues();
List<Object> dataValues = null;
final EncodedValuesPropertyType dataValues200 = resultv200.getDataArray().getDataValues();
if (dataValues200 != null) {
dataValues = dataValues200.getAny();
}
final org.geotoolkit.swe.xml.v200.DataRecordType recordv200 = (org.geotoolkit.swe.xml.v200.DataRecordType) resultv200.getDataArray().getElementType().getAbstractRecord();
final List<org.geotoolkit.swe.xml.v101.AnyScalarPropertyType> fields = new ArrayList<org.geotoolkit.swe.xml.v101.AnyScalarPropertyType>();
for (org.geotoolkit.swe.xml.v200.Field scalar : recordv200.getField()) {
fields.add(new org.geotoolkit.swe.xml.v101.AnyScalarPropertyType(scalar));
}
final org.geotoolkit.swe.xml.v101.SimpleDataRecordType record = new org.geotoolkit.swe.xml.v101.SimpleDataRecordType(null, recordv200.getId(), recordv200.getDefinition(), recordv200.isFixed(), fields);
final org.geotoolkit.swe.xml.v101.DataArrayType array = new org.geotoolkit.swe.xml.v101.DataArrayType(id, count, null, record, enc, values, dataValues);
final org.geotoolkit.swe.xml.v101.DataArrayPropertyType resultv100 = new org.geotoolkit.swe.xml.v101.DataArrayPropertyType(array);
result = resultv100;
} else {
result = observation.getResult();
}
if (observation instanceof Measurement) {
return new org.geotoolkit.observation.xml.v100.MeasurementType(name, definition, sf, observedProperty, procedure, (org.geotoolkit.observation.xml.v100.MeasureType) result, time);
} else {
return new org.geotoolkit.observation.xml.v100.ObservationType(name, definition, sf, observedProperty, procedure, result, time);
}
}
use of org.geotoolkit.swe.xml.v101.DataArrayType in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createField.
private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
SweAbstractDataComponent element = sweField.getElement();
DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
if (element instanceof SweBoolean) {
xbField.addNewBoolean().set(createSimpleType((SweBoolean) element));
} else if (element instanceof SweCategory) {
xbField.addNewCategory().set(createSimpleType((SweCategory) element));
} else if (element instanceof SweCount) {
xbField.addNewCount().set(createSimpleType((SweCount) element));
} else if (element instanceof SweCountRange) {
xbField.addNewCount().set(createSimpleType((SweCountRange) element));
} else if (element instanceof SweQuantity) {
xbField.addNewQuantity().set(createSimpleType((SweQuantity) element));
} else if (element instanceof SweQuantityRange) {
xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) element));
} else if (element instanceof SweText) {
xbField.addNewText().set(createSimpleType((SweText) element));
} else if (element instanceof SweTimeRange) {
xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) element));
} else if (element instanceof SweTime) {
xbField.addNewTime().set(createSimpleType((SweTime) element));
} else if (element instanceof SweEnvelope) {
EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
xbEnvelope.set(createEnvelope((SweEnvelope) element));
} else if (element instanceof SweDataRecord) {
DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
xbEnvelope.set(createDataRecord((SweDataRecord) element));
} else if (element instanceof SweDataArray) {
DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
xbEnvelope.set(createDataArray((SweDataArray) element).getDataArray1());
} else {
throw new EncodingException("The element type '%s' of the received '%s' is not supported by this encoder '%s'.", new Object[] { element != null ? element.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
}
return xbField;
}
Aggregations