Search in sources :

Example 16 with AnyScalarPropertyType

use of org.geotoolkit.swe.xml.v101.AnyScalarPropertyType in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_simpleDataRecordWithFields.

@Test
public void should_encode_simpleDataRecordWithFields() throws EncodingException {
    final String field0Value = "field-0-value";
    final String field0Name = "field-0";
    final String field1Name = "field-1";
    final Boolean field1Value = Boolean.TRUE;
    final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(field0Name, new SweText().setValue(field0Value))).addField(new SweField(field1Name, new SweBoolean().setValue(field1Value))));
    assertThat(encode, instanceOf(SimpleDataRecordType.class));
    final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
    final AnyScalarPropertyType field0 = xbSimpleDataRecord.getFieldArray(0);
    final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(1);
    assertThat(xbSimpleDataRecord.getFieldArray().length, is(2));
    assertThat(field0.isSetText(), is(TRUE));
    assertThat(field0.getName(), is(field0Name));
    assertThat(field0.getText().getValue(), is(field0Value));
    assertThat(field1.isSetBoolean(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    assertThat(field1.getBoolean().getValue(), is(field1Value));
}
Also used : SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.jupiter.api.Test)

Example 17 with AnyScalarPropertyType

use of org.geotoolkit.swe.xml.v101.AnyScalarPropertyType in project geotoolkit by Geomatys.

the class ObservationXMLBindingTest method UnmarshalingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void UnmarshalingTest() throws Exception {
    /*
         * Test Unmarshalling observation
         */
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Observation xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + "    <gml:name>urn:Observation-007</gml:name>" + '\n' + "    <om:samplingTime>" + '\n' + "        <gml:TimePeriod>" + '\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=\"urn:sampling:sampledFeature\"/>" + '\n' + "            <sampling:position gml:id=\"point-ID\">" + '\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\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\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";
    StringReader sr = new StringReader(xml);
    JAXBElement jb = (JAXBElement) unmarshaller.unmarshal(sr);
    ObservationType result = (ObservationType) jb.getValue();
    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("urn:sampling:sampledFeature"), location);
    PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
    TimePeriodType samplingTime = new TimePeriodType(null, "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 expResult = new ObservationType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
    assertEquals(expResult.getFeatureOfInterest(), result.getFeatureOfInterest());
    assertEquals(expResult.getDefinition(), result.getDefinition());
    assertEquals(expResult.getName(), result.getName());
    assertEquals(expResult.getObservationMetadata(), result.getObservationMetadata());
    assertEquals(expResult.getObservedProperty(), result.getObservedProperty());
    assertEquals(expResult.getProcedure(), result.getProcedure());
    assertEquals(expResult.getProcedureParameter(), result.getProcedureParameter());
    assertEquals(expResult.getProcedureTime(), result.getProcedureTime());
    assertEquals(expResult.getPropertyFeatureOfInterest(), result.getPropertyFeatureOfInterest());
    assertEquals(expResult.getPropertyObservedProperty(), result.getPropertyObservedProperty());
    assertEquals(expResult.getQuality(), result.getQuality());
    assertEquals(expResult.getResult(), result.getResult());
    assertEquals(expResult.getSamplingTime(), result.getSamplingTime());
    assertEquals(expResult, result);
    /*
         * Test Unmarshalling measurement
         */
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:Measurement xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:sampling=\"http://www.opengis.net/sampling/1.0\" " + " xmlns:gml=\"http://www.opengis.net/gml\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\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=\"urn:sampling:sampledFeature\"/>" + '\n' + "            <sampling:position gml:id=\"point-ID\">" + '\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";
    sr = new StringReader(xml);
    jb = (JAXBElement) unmarshaller.unmarshal(sr);
    MeasurementType result2 = (MeasurementType) jb.getValue();
    UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", null, null, "meters");
    MeasureType meas = new MeasureType(uom, 7);
    MeasurementType expResult2 = new MeasurementType("urn:Observation-007", null, sp, observedProperty, "urn:sensor:007", meas, samplingTime);
    assertEquals(expResult2.getFeatureOfInterest(), result2.getFeatureOfInterest());
    assertEquals(expResult2.getDefinition(), result2.getDefinition());
    assertEquals(expResult2.getName(), result2.getName());
    assertEquals(expResult2.getObservationMetadata(), result2.getObservationMetadata());
    assertEquals(expResult2.getObservedProperty(), result2.getObservedProperty());
    assertEquals(expResult2.getProcedure(), result2.getProcedure());
    assertEquals(expResult2.getProcedureParameter(), result2.getProcedureParameter());
    assertEquals(expResult2.getProcedureTime(), result2.getProcedureTime());
    assertEquals(expResult2.getPropertyFeatureOfInterest(), result2.getPropertyFeatureOfInterest());
    assertEquals(expResult2.getPropertyObservedProperty(), result2.getPropertyObservedProperty());
    assertEquals(expResult2.getQuality(), result2.getQuality());
    assertEquals(expResult2.getResult(), result2.getResult());
    assertEquals(expResult2.getSamplingTime(), result2.getSamplingTime());
    assertEquals(expResult2, result2);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<om:ObservationCollection xmlns:swe=\"http://www.opengis.net/swe/1.0.1\" 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\">" + '\n' + "    <gml:boundedBy>" + '\n' + "        <gml:Envelope srsName=\"urn:ogc:crs:espg:4326\">" + '\n' + "            <gml:lowerCorner>-180.0 -90.0</gml:lowerCorner>" + '\n' + "            <gml:upperCorner>180.0 90.0</gml:upperCorner>" + '\n' + "        </gml:Envelope>" + '\n' + "    </gml:boundedBy>" + '\n' + "    <om:member>" + '\n' + "        <om:Measurement>" + '\n' + "            <gml:name>urn:ogc:object:observationTemplate:SunSpot:0014.4F01.0000.2626-12</gml:name>" + '\n' + "            <om:samplingTime>" + '\n' + "                <gml:TimePeriod>" + '\n' + "                    <gml:beginPosition>2009-08-03 11:18:06</gml:beginPosition>" + '\n' + "                    <gml:endPosition indeterminatePosition=\"now\"></gml:endPosition>" + '\n' + "                </gml:TimePeriod>" + '\n' + "            </om:samplingTime>" + '\n' + "            <om:procedure xlink:href=\"urn:ogc:object:sensor:SunSpot:0014.4F01.0000.2626\"/>" + '\n' + "            <om:observedProperty>" + '\n' + "                <swe:Phenomenon gml:id=\"temperature\">" + '\n' + "                    <gml:name>urn:phenomenon:temperature</gml:name>" + '\n' + "                </swe:Phenomenon>" + '\n' + "            </om:observedProperty>" + '\n' + "            <om:featureOfInterest>" + '\n' + "                <sampling:SamplingPoint gml:id=\"sampling-point-001\">" + '\n' + "                    <gml:name>sampling-point-001</gml:name>" + '\n' + "                    <gml:boundedBy>" + '\n' + "                        <gml:Null>not_bounded</gml:Null>" + '\n' + "                    </gml:boundedBy>" + '\n' + "                <sampling:sampledFeature>sampling-point-001</sampling:sampledFeature>" + '\n' + "                    <sampling:position>" + '\n' + "                        <gml:Point gml:id=\"point-ID\">" + '\n' + "                            <gml:pos srsDimension=\"0\">0.0 0.0</gml:pos>" + '\n' + "                        </gml:Point>" + '\n' + "                    </sampling:position>" + '\n' + "                </sampling:SamplingPoint>" + '\n' + "            </om:featureOfInterest>" + '\n' + "            <om:result xsi:type=\"om:Measure\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + "                <om:name>mesure-027</om:name>" + '\n' + "                <om:value>0.0</om:value>" + '\n' + "            </om:result>" + '\n' + "        </om:Measurement>" + '\n' + "    </om:member>" + '\n' + "</om:ObservationCollection>" + '\n';
    sr = new StringReader(xml);
    ObservationCollectionType result3 = (ObservationCollectionType) unmarshaller.unmarshal(sr);
}
Also used : ObservationType(org.geotoolkit.observation.xml.v100.ObservationType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) AnyScalarPropertyType(org.geotoolkit.swe.xml.v101.AnyScalarPropertyType) ArrayList(java.util.ArrayList) MeasureType(org.geotoolkit.observation.xml.v100.MeasureType) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) Text(org.geotoolkit.swe.xml.v101.Text) JAXBElement(javax.xml.bind.JAXBElement) DataArrayPropertyType(org.geotoolkit.swe.xml.v101.DataArrayPropertyType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) MeasurementType(org.geotoolkit.observation.xml.v100.MeasurementType) StringReader(java.io.StringReader) TextBlockType(org.geotoolkit.swe.xml.v101.TextBlockType) UnitOfMeasureEntry(org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry) PointType(org.geotoolkit.gml.xml.v311.PointType) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) FeaturePropertyType(org.geotoolkit.gml.xml.v311.FeaturePropertyType) SimpleDataRecordType(org.geotoolkit.swe.xml.v101.SimpleDataRecordType) DataArrayType(org.geotoolkit.swe.xml.v101.DataArrayType)

Example 18 with AnyScalarPropertyType

use of org.geotoolkit.swe.xml.v101.AnyScalarPropertyType in project geotoolkit by Geomatys.

the class SweXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 */
@Test
public void marshallingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
    Text text = new Text("definition", "some value");
    StringWriter sw = new StringWriter();
    marshaller.marshal(text, sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    // we remove the xmlmns
    result = StringUtilities.removeXmlns(result);
    String expResult = "<swe:Text definition=\"definition\" >" + '\n' + "  <swe:value>some value</swe:value>" + '\n' + "</swe:Text>";
    assertEquals(expResult, result.trim());
    SimpleDataRecordType elementType = new SimpleDataRecordType();
    AnyScalarPropertyType any = new AnyScalarPropertyType("id-1", "any name", text);
    TextBlockType encoding = new TextBlockType("encoding-1", ",", "@@", ".");
    elementType.setField(Arrays.asList(any));
    DataArrayType array = new DataArrayType("array-id-1", 0, "array-id-1", elementType, encoding, null, null);
    sw = new StringWriter();
    marshaller.marshal(array, sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<swe:DataArray gml:id=\"array-id-1\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + "    <swe:elementCount>" + '\n' + "        <swe:Count>" + '\n' + "            <swe:value>0</swe:value>" + '\n' + "        </swe:Count>" + '\n' + "    </swe:elementCount>" + '\n' + "    <swe:elementType name=\"array-id-1\">" + '\n' + "        <swe:SimpleDataRecord>" + '\n' + "            <swe:field name=\"any name\">" + '\n' + "                <swe:Text definition=\"definition\">" + '\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-1\"/>" + '\n' + "    </swe:encoding>" + '\n' + "</swe:DataArray>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
    ObjectFactory factory = new ObjectFactory();
    final List<DataComponentPropertyType> fields = new ArrayList<DataComponentPropertyType>();
    fields.add(DataComponentPropertyType.LATITUDE_FIELD);
    fields.add(DataComponentPropertyType.LONGITUDE_FIELD);
    fields.add(DataComponentPropertyType.TIME_FIELD);
    final DataRecordType posRecord = new DataRecordType(null, fields);
    final DataBlockDefinitionType definition = new DataBlockDefinitionType(null, Arrays.asList((AbstractDataComponentType) posRecord), TextBlockType.DEFAULT_ENCODING);
    marshaller.marshal(factory.createDataBlockDefinition(definition), System.out);
    org.geotoolkit.swe.xml.v200.ObjectFactory factoryV200 = new org.geotoolkit.swe.xml.v200.ObjectFactory();
    org.geotoolkit.swe.xml.v200.DataArrayType arrayV200 = new org.geotoolkit.swe.xml.v200.DataArrayType("test-id", 2, null, "balbbla", "test-id", null, null);
    marshaller.marshal(factoryV200.createDataArray(arrayV200), System.out);
}
Also used : SimpleDataRecordType(org.geotoolkit.swe.xml.v101.SimpleDataRecordType) DataRecordType(org.geotoolkit.swe.xml.v101.DataRecordType) AnyScalarPropertyType(org.geotoolkit.swe.xml.v101.AnyScalarPropertyType) ArrayList(java.util.ArrayList) Text(org.geotoolkit.swe.xml.v101.Text) DataBlockDefinitionType(org.geotoolkit.swe.xml.v101.DataBlockDefinitionType) AbstractDataComponentType(org.geotoolkit.swe.xml.v101.AbstractDataComponentType) StringWriter(java.io.StringWriter) ObjectFactory(org.geotoolkit.swe.xml.v101.ObjectFactory) TextBlockType(org.geotoolkit.swe.xml.v101.TextBlockType) DataComponentPropertyType(org.geotoolkit.swe.xml.v101.DataComponentPropertyType) SimpleDataRecordType(org.geotoolkit.swe.xml.v101.SimpleDataRecordType) DataArrayType(org.geotoolkit.swe.xml.v101.DataArrayType)

Aggregations

AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)13 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)11 XmlObject (org.apache.xmlbeans.XmlObject)11 SweField (org.n52.shetland.ogc.swe.SweField)11 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)10 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)4 PhenomenonType (org.geotoolkit.swe.xml.v101.PhenomenonType)3 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)3 StringWriter (java.io.StringWriter)2 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)2 FeaturePropertyType (org.geotoolkit.gml.xml.v311.FeaturePropertyType)2 PointType (org.geotoolkit.gml.xml.v311.PointType)2 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)2 UnitOfMeasureEntry (org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry)2 MeasureType (org.geotoolkit.observation.xml.v100.MeasureType)2 MeasurementType (org.geotoolkit.observation.xml.v100.MeasurementType)2 ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)2 ObservationType (org.geotoolkit.observation.xml.v100.ObservationType)2 SamplingPointType (org.geotoolkit.sampling.xml.v100.SamplingPointType)2