summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Format/SOSGetObservation.html
blob: 3256d5a52f6c8fb911701c3fb3d78050b636c187 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<html>
<head>
    <script src="../OLLoader.js"></script>
    <script type="text/javascript">

    function test_read_SOSGetObservation(t) {
        t.plan(13);

        var parser = new OpenLayers.Format.SOSGetObservation();
        var text =
            '<?xml version="1.0" encoding="UTF-8"?>' +
            '<om:ObservationCollection xmlns:om="http://www.opengis.net/om/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:sa="http://www.opengis.net/sampling/1.0" gml:id="oc_0" xsi:schemaLocation="http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/om.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd">' +
            '<gml:boundedBy>' +
            '<gml:Envelope srsName="urn:ogc:def:crs:EPSG:4326">' +
            '<gml:lowerCorner>52.1524 5.3722</gml:lowerCorner>' +
            '<gml:upperCorner>52.1524 5.3722</gml:upperCorner>' +
            '</gml:Envelope>' +
            '</gml:boundedBy>' +
            '<om:member>' +
            '<om:Measurement gml:id="o_51082">' +
            '<om:samplingTime>' +
            '<gml:TimeInstant xsi:type="gml:TimeInstantType">' +
            '<gml:timePosition>2009-12-02T10:35:00.000+01:00</gml:timePosition>' +
            '</gml:TimeInstant>' +
            '</om:samplingTime>' +
            '<om:procedure xlink:href="urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56"/>' +
            '<om:observedProperty xlink:href="urn:x-ogc:def:property:OGC::Temperature"/>' +
            '<om:featureOfInterest>' +
            '<sa:SamplingPoint gml:id="urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56">' +
            '<gml:name>Roof of the IfGI</gml:name>' +
            '<sa:position>' +
            '<gml:Point>' +
            '<gml:pos srsName="urn:ogc:def:crs:EPSG:4326">52.1524 5.3722</gml:pos>' +
            '</gml:Point>' +
            '</sa:position>' +
            '</sa:SamplingPoint>' +
            '</om:featureOfInterest>' +
            '<om:result uom="Cel">4.9</om:result>' +
            '</om:Measurement>' +
            '</om:member>' +
            '</om:ObservationCollection>';

        var res = parser.read(text);
        t.eq(res.measurements.length, 1, "One measurement parsed");
        t.eq(res.id, "oc_0", "Observation collection id correctly parsed");
        var measurement = res.measurements[0];
        t.eq(measurement.observedProperty, "urn:x-ogc:def:property:OGC::Temperature", "Observed property correctly parsed");
        t.eq(measurement.procedure, "urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56", "Procedure correctly parsed");
        t.eq(measurement.result.uom, "Cel", "Units of measurement correctly parsed");
        t.eq(measurement.result.value, "4.9", "Value correctly parsed");
        t.eq(measurement.samplingTime.timeInstant.timePosition, "2009-12-02T10:35:00.000+01:00", "Sampling time correctly parsed");

        var response = [];
        response.push('<?xml version="1.0" encoding="UTF-8"?>',
'<om:ObservationCollection gml:id="oc_0" xsi:schemaLocation="http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/om.xsd http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd" xmlns:om="http://www.opengis.net/om/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" xmlns:sa="http://www.opengis.net/sampling/1.0">',
'  <gml:boundedBy>',
'    <gml:Envelope srsName="urn:ogc:def:crs:EPSG:4326">',
'      <gml:lowerCorner>46.611644 7.6103</gml:lowerCorner>',
'      <gml:upperCorner>51.9412 13.883498</gml:upperCorner>',
'    </gml:Envelope>',
'  </gml:boundedBy>',
'  <om:member>',
'    <om:Observation gml:id="ot_583227">',
'      <om:samplingTime>',
'        <gml:TimePeriod xsi:type="gml:TimePeriodType">',
'          <gml:beginPosition>2009-09-28T13:45:00.000+02:00</gml:beginPosition>',
'          <gml:endPosition>2009-09-28T13:45:00.000+02:00</gml:endPosition>',
'        </gml:TimePeriod>',
'      </om:samplingTime>',
'      <om:procedure xlink:href="urn:ogc:object:feature:OSIRIS-HWS:efeb807b-bd24-4128-a920-f6729bcdd111"/>',
'      <om:observedProperty>',
'        <swe:CompositePhenomenon gml:id="cpid0" dimension="1">',
'          <gml:name>resultComponents</gml:name>',
'          <swe:component xlink:href="urn:ogc:data:time:iso8601"/>',
'          <swe:component xlink:href="urn:ogc:def:property:OGC::Precipitation1Hour"/>',
'        </swe:CompositePhenomenon>',
'      </om:observedProperty>',
'      <om:featureOfInterest>',
'        <gml:FeatureCollection>',
'          <gml:featureMember>',
'            <sa:SamplingPoint gml:id="urn:ogc:object:feature:OSIRIS-HWS:efeb807b-bd24-4128-a920-f6729bcdd111" xsi:schemaLocation=" http://www.opengis.net/sampling/1.0 http://schemas.opengis.net/sampling/1.0.0/sampling.xsd">',
'              <gml:name>waether @ roof of the FH Kaernten, Villach, Austria</gml:name>',
'              <sa:sampledFeature xlink:href="urn:ogc:def:nil:OGC:unknown"/>',
'              <sa:position>',
'                <gml:Point>',
'                  <gml:pos srsName="urn:ogc:def:crs:EPSG:4326">46.611644 13.883498</gml:pos>',
'                </gml:Point>',
'              </sa:position>',
'            </sa:SamplingPoint>',
'          </gml:featureMember>',
'        </gml:FeatureCollection>',
'      </om:featureOfInterest>',
'      <om:result>',
'        <swe:DataArray>',
'          <swe:elementCount>',
'            <swe:Count>',
'              <swe:value>1</swe:value>',
'            </swe:Count>',
'          </swe:elementCount>',
'          <swe:elementType name="Components">',
'            <swe:DataRecord>',
'              <swe:field name="Time">',
'                <swe:Time definition="urn:ogc:data:time:iso8601"/>',
'              </swe:field>',
'              <swe:field name="feature">',
'                <swe:Text definition="urn:ogc:data:feature"/>',
'              </swe:field>',
'              <swe:field name="urn:ogc:def:property:OGC::Precipitation1Hour">',
'                <swe:Quantity definition="urn:ogc:def:property:OGC::Precipitation1Hour">',
'                  <swe:uom code="mm"/>',
'                </swe:Quantity>',
'              </swe:field>',
'            </swe:DataRecord>',
'          </swe:elementType>',
'          <swe:encoding>',
'            <swe:TextBlock decimalSeparator="." tokenSeparator="," blockSeparator=";"/>',
'          </swe:encoding>',
'          <swe:values>2009-09-28T13:45:00.000+02:00,urn:ogc:object:feature:OSIRIS-HWS:efeb807b-bd24-4128-a920-f6729bcdd111,0.0;</swe:values>',
'        </swe:DataArray>',
'      </om:result>',
'    </om:Observation>',
'  </om:member>',
'</om:ObservationCollection>');
        text = response.join("");
        var res = parser.read(text);
        t.eq(res.observations.length, 1, "1 observation parsed");
        var observation = res.observations[0];
        t.eq(observation.procedure, "urn:ogc:object:feature:OSIRIS-HWS:efeb807b-bd24-4128-a920-f6729bcdd111", "procedure parsed correctly");
        t.eq(observation.fois.length, 1, "One foi parsed for the observation");
        var foi = observation.fois[0];
        var feature = foi.features[0];
        t.eq(feature.attributes.id, "urn:ogc:object:feature:OSIRIS-HWS:efeb807b-bd24-4128-a920-f6729bcdd111", "Foi id correctly parsed");
        t.eq(feature.attributes.name, "waether @ roof of the FH Kaernten, Villach, Austria", "Foi name correctly parsed");
        t.ok(feature.geometry instanceof OpenLayers.Geometry.Point, "Geometry correctly parsed");
    }

    function test_write_SOSGetObservation(t) {
        t.plan(2);
        var expect = '<GetObservation xmlns="http://www.opengis.net/sos/1.0" version="1.0.0" service="SOS" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><offering>TEMPERATURE</offering><eventTime><ogc:TM_Equals xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName><gml:TimeInstant xmlns:gml="http://www.opengis.net/gml"><gml:timePosition>latest</gml:timePosition></gml:TimeInstant></ogc:TM_Equals></eventTime><procedure>urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56</procedure><observedProperty>urn:x-ogc:def:property:OGC::Temperature</observedProperty><responseFormat>text/xml;subtype="om/1.0.0"</responseFormat><resultModel>Measurement</resultModel><responseMode>inline</responseMode></GetObservation>';
        var format = new OpenLayers.Format.SOSGetObservation();
        var output = format.write({eventTime: 'latest', resultModel: 'Measurement', responseMode: 'inline',
            procedures: ['urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56'], responseFormat: 'text/xml;subtype="om/1.0.0"',
            offering: 'TEMPERATURE', observedProperties: ['urn:x-ogc:def:property:OGC::Temperature']});
        t.xml_eq(output, expect, "Request XML is written out correctly");

        var expected = [];

        expected.push('<?xml version="1.0" encoding="UTF-8"?>',
'<GetObservation xmlns="http://www.opengis.net/sos/1.0"',
'  xmlns:gml="http://www.opengis.net/gml"',
'  xmlns:om="http://www.opengis.net/om/1.0"',
'  xmlns:ogc="http://www.opengis.net/ogc"',
'  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"',
'  xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd"',
'  service="SOS" version="1.0.0">',
'  <offering>RAIN_GAUGE</offering>',
'  <eventTime>',
'    <ogc:TM_Equals>',
'      <ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName>',
'      <gml:TimeInstant>',
'        <gml:timePosition>latest</gml:timePosition>',
'      </gml:TimeInstant>',
'    </ogc:TM_Equals>',
'  </eventTime>',
'  <observedProperty>urn:ogc:def:property:OGC::Precipitation1Hour</observedProperty>',
'  <featureOfInterest>',
'    <ObjectID>urn:ogc:object:feature:OSIRIS-HWS:3d3b239f-7696-4864-9d07-15447eae2b93</ObjectID>',
'  </featureOfInterest>',
'  <responseFormat>text/xml;subtype="om/1.0.0"</responseFormat>',
'</GetObservation>');
        expect = expected.join("");
        var output = format.write({eventTime: 'latest', offering: 'RAIN_GAUGE',
            observedProperties: ['urn:ogc:def:property:OGC::Precipitation1Hour'],
            responseFormat: 'text/xml;subtype="om/1.0.0"',
            foi: {objectId: 'urn:ogc:object:feature:OSIRIS-HWS:3d3b239f-7696-4864-9d07-15447eae2b93'}});
        t.xml_eq(output, expect, "Request XML is written out correctly");
    }

    </script>
</head>
<body>
</body>
</html>