Search in sources :

Example 1 with ObservationCollectionType

use of org.geotoolkit.observation.xml.v100.ObservationCollectionType in project arctic-sea by 52North.

the class OmEncoderv100 method createObservationCollection.

private XmlObject createObservationCollection(ObservationStream sosObservationCollectionIterable, String resultModel) throws EncodingException {
    ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
    ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
    xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
    if (sosObservationCollectionIterable != null) {
        List<OmObservation> sosObservationCollection = new LinkedList<>();
        try {
            sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
            ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
            Encoder<XmlObject, ReferencedEnvelope> envEncoder = getEncoder(GmlConstants.NS_GML, sosEnvelope);
            xbObservationCollection.addNewBoundedBy().addNewEnvelope().set(envEncoder.encode(sosEnvelope));
            for (OmObservation sosObservation : sosObservationCollection) {
                String observationType = checkObservationType(sosObservation);
                if (Strings.isNullOrEmpty(resultModel) || (!Strings.isNullOrEmpty(resultModel) && observationType.equals(resultModel))) {
                    if (sosObservation.getValue() instanceof StreamingValue) {
                        StreamingValue<?> streamingValue = (StreamingValue<?>) sosObservation.getValue();
                        while (streamingValue.hasNext()) {
                            xbObservationCollection.addNewMember().set(createObservation(streamingValue.next(), null));
                        }
                    } else {
                        xbObservationCollection.addNewMember().set(createObservation(sosObservation, null));
                    }
                } else {
                    throw new EncodingException("The requested resultModel '%s' is invalid for the resulting observations!", OMHelper.getEncodedResultModelFor(resultModel));
                }
            }
        } catch (OwsExceptionReport owse) {
            throw new EncodingException(owse);
        }
    } else {
        ObservationPropertyType xbObservation = xbObservationCollection.addNewMember();
        xbObservation.setHref(GmlConstants.NIL_INAPPLICABLE);
    }
    XmlHelper.makeGmlIdsUnique(xbObservationCollectionDoc.getDomNode());
    N52XmlHelper.setSchemaLocationsToDocument(xbObservationCollectionDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100(), N52XmlHelper.getSchemaLocationForOM100(), N52XmlHelper.getSchemaLocationForSA100()));
    return xbObservationCollectionDoc;
}
Also used : StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) OmObservation(org.n52.shetland.ogc.om.OmObservation) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) XmlString(org.apache.xmlbeans.XmlString) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 2 with ObservationCollectionType

use of org.geotoolkit.observation.xml.v100.ObservationCollectionType 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();
}
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) DataArrayPropertyType(org.geotoolkit.swe.xml.v101.DataArrayPropertyType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) StringWriter(java.io.StringWriter) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) MeasurementType(org.geotoolkit.observation.xml.v100.MeasurementType) 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 3 with ObservationCollectionType

use of org.geotoolkit.observation.xml.v100.ObservationCollectionType in project arctic-sea by 52North.

the class OmEncoderv100 method createObservationCollection.

private XmlObject createObservationCollection(AbstractObservationResponse response) throws EncodingException {
    ObservationStream sosObservationCollectionIterable = response.getObservationCollection();
    String resultModel = response.getResultModel();
    ObservationCollectionDocument xbObservationCollectionDoc = ObservationCollectionDocument.Factory.newInstance(getXmlOptions());
    ObservationCollectionType xbObservationCollection = xbObservationCollectionDoc.addNewObservationCollection();
    xbObservationCollection.setId(SosConstants.OBS_COL_ID_PREFIX + new DateTime().getMillis());
    if (response.hasExtensions()) {
        createMetadataProperty(xbObservationCollection, response.getExtensions());
    }
    if (sosObservationCollectionIterable != null) {
        List<OmObservation> sosObservationCollection = new LinkedList<>();
        try {
            sosObservationCollectionIterable.forEachRemaining(sosObservationCollection::add);
            ReferencedEnvelope sosEnvelope = getEnvelope(sosObservationCollection);
            if (sosEnvelope.isSetEnvelope()) {
                Encoder<XmlObject, ReferencedEnvelope> envEncoder = getEncoder(GmlConstants.NS_GML, sosEnvelope);
                xbObservationCollection.addNewBoundedBy().addNewEnvelope().set(envEncoder.encode(sosEnvelope));
            }
            for (OmObservation sosObservation : sosObservationCollection) {
                String observationType = checkObservationType(sosObservation);
                if (Strings.isNullOrEmpty(resultModel) || (!Strings.isNullOrEmpty(resultModel) && observationType.equals(resultModel))) {
                    if (sosObservation.getValue() instanceof StreamingValue) {
                        StreamingValue<?> streamingValue = (StreamingValue<?>) sosObservation.getValue();
                        while (streamingValue.hasNext()) {
                            xbObservationCollection.addNewMember().set(createObservation(streamingValue.next(), null));
                        }
                    } else {
                        xbObservationCollection.addNewMember().set(createObservation(sosObservation, null));
                    }
                } else {
                    throw new EncodingException("The requested resultModel '%s' is invalid for the resulting observations!", OMHelper.getEncodedResultModelFor(resultModel));
                }
            }
        } catch (OwsExceptionReport owse) {
            throw new EncodingException(owse);
        }
    } else {
        ObservationPropertyType xbObservation = xbObservationCollection.addNewMember();
        xbObservation.setHref(GmlConstants.NIL_INAPPLICABLE);
    }
    XmlHelper.makeGmlIdsUnique(xbObservationCollectionDoc.getDomNode());
    N52XmlHelper.setSchemaLocationsToDocument(xbObservationCollectionDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOS100(), N52XmlHelper.getSchemaLocationForOM100(), N52XmlHelper.getSchemaLocationForSA100()));
    return xbObservationCollectionDoc;
}
Also used : StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationPropertyType(net.opengis.om.x10.ObservationPropertyType) OmObservation(org.n52.shetland.ogc.om.OmObservation) ObservationCollectionType(net.opengis.om.x10.ObservationCollectionType) XmlString(org.apache.xmlbeans.XmlString) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) ObservationCollectionDocument(net.opengis.om.x10.ObservationCollectionDocument) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 4 with ObservationCollectionType

use of org.geotoolkit.observation.xml.v100.ObservationCollectionType in project geotoolkit by Geomatys.

the class SOSClientDemo method main.

public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException, JAXBException {
    Demos.init();
    final MarshallerPool pool = SOSMarshallerPool.getInstance();
    final Unmarshaller um = pool.acquireUnmarshaller();
    // build a new SOS client
    final SensorObservationServiceClient sosServer = new SensorObservationServiceClient(new URL("http://test.geomatys.com/swe_TS/WS/sos?"), "1.0.0");
    /**
     * make a getCapabilities request
     */
    final GetCapabilitiesRequest getCapa = sosServer.createGetCapabilities();
    InputStream is = getCapa.getResponseStream();
    // unmarshall the response
    Capabilities capabilities = (Capabilities) um.unmarshal(is);
    // print the title of the server
    System.out.println(capabilities.getServiceIdentification().getTitle());
    // extract a sensorML identifier and outputFormat to make a describeSensor request
    Operation describeSensorOperation = capabilities.getOperationsMetadata().getOperation("DescribeSensor");
    String sensorID = ((ValueType) describeSensorOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String outputFormat = ((ValueType) describeSensorOperation.getParameter("outputFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    // extract a all the parameters necessary to make a getObservation request
    Operation getObservationOperation = capabilities.getOperationsMetadata().getOperation("GetObservation");
    String offering = ((ValueType) getObservationOperation.getParameter("offering").getAllowedValues().getValueOrRange().get(0)).getValue();
    String responseFormat = ((ValueType) getObservationOperation.getParameter("responseFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    String phenomenon = ((ValueType) getObservationOperation.getParameter("observedProperty").getAllowedValues().getValueOrRange().get(0)).getValue();
    String procedure = ((ValueType) getObservationOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String featureOfInterest = ((ValueType) getObservationOperation.getParameter("featureOfInterest").getAllowedValues().getValueOrRange().get(0)).getValue();
    /**
     * make a DescribeSensor request
     */
    final DescribeSensorRequest descSensor = sosServer.createDescribeSensor();
    descSensor.setSensorId(sensorID);
    descSensor.setOutputFormat(outputFormat);
    is = descSensor.getResponseStream();
    // unmarshall the response
    AbstractSensorML sensorMLResponse = (AbstractSensorML) um.unmarshal(is);
    System.out.println(sensorMLResponse);
    /**
     * make a GetObservation request
     */
    final GetObservationRequest getObs = sosServer.createGetObservation();
    getObs.setOffering(offering);
    getObs.setObservedProperties(phenomenon);
    getObs.setProcedures(procedure);
    getObs.setResponseFormat(responseFormat);
    getObs.setFeatureOfInterest(new FeatureOfInterest(Arrays.asList(featureOfInterest)));
    is = getObs.getResponseStream();
    // unmarshall the response
    ObservationCollectionType getObsResponse = (ObservationCollectionType) um.unmarshal(is);
    System.out.println(getObsResponse);
    pool.recycle(um);
}
Also used : GetCapabilitiesRequest(org.geotoolkit.sos.GetCapabilitiesRequest) ValueType(org.geotoolkit.ows.xml.v110.ValueType) InputStream(java.io.InputStream) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) MarshallerPool(org.apache.sis.xml.MarshallerPool) SOSMarshallerPool(org.geotoolkit.sos.xml.SOSMarshallerPool) Operation(org.geotoolkit.ows.xml.v110.Operation) URL(java.net.URL) AbstractSensorML(org.geotoolkit.sml.xml.AbstractSensorML) GetObservationRequest(org.geotoolkit.sos.GetObservationRequest) FeatureOfInterest(org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest) Capabilities(org.geotoolkit.sos.xml.v100.Capabilities) Unmarshaller(javax.xml.bind.Unmarshaller) DescribeSensorRequest(org.geotoolkit.sos.DescribeSensorRequest) SensorObservationServiceClient(org.geotoolkit.sos.SensorObservationServiceClient)

Example 5 with ObservationCollectionType

use of org.geotoolkit.observation.xml.v100.ObservationCollectionType 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)

Aggregations

ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ObservationCollectionDocument (net.opengis.om.x10.ObservationCollectionDocument)2 ObservationCollectionType (net.opengis.om.x10.ObservationCollectionType)2 ObservationPropertyType (net.opengis.om.x10.ObservationPropertyType)2 XmlObject (org.apache.xmlbeans.XmlObject)2 XmlString (org.apache.xmlbeans.XmlString)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 ObservationType (org.geotoolkit.observation.xml.v100.ObservationType)2 SamplingPointType (org.geotoolkit.sampling.xml.v100.SamplingPointType)2 AnyScalarPropertyType (org.geotoolkit.swe.xml.v101.AnyScalarPropertyType)2 DataArrayPropertyType (org.geotoolkit.swe.xml.v101.DataArrayPropertyType)2 DataArrayType (org.geotoolkit.swe.xml.v101.DataArrayType)2