Search in sources :

Example 1 with GetObservationRequest

use of org.geotoolkit.sos.GetObservationRequest 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)

Aggregations

InputStream (java.io.InputStream)1 URL (java.net.URL)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)1 Operation (org.geotoolkit.ows.xml.v110.Operation)1 ValueType (org.geotoolkit.ows.xml.v110.ValueType)1 AbstractSensorML (org.geotoolkit.sml.xml.AbstractSensorML)1 DescribeSensorRequest (org.geotoolkit.sos.DescribeSensorRequest)1 GetCapabilitiesRequest (org.geotoolkit.sos.GetCapabilitiesRequest)1 GetObservationRequest (org.geotoolkit.sos.GetObservationRequest)1 SensorObservationServiceClient (org.geotoolkit.sos.SensorObservationServiceClient)1 SOSMarshallerPool (org.geotoolkit.sos.xml.SOSMarshallerPool)1 Capabilities (org.geotoolkit.sos.xml.v100.Capabilities)1 FeatureOfInterest (org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest)1