several improvement to the SOSGetObservation Format, p=sonxurxo, r=me (closes #2842)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10902 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2010-11-17 10:06:07 +00:00
parent 7608e867e9
commit 9a3ca5fa7e
4 changed files with 177 additions and 19 deletions

View File

@@ -133,7 +133,7 @@
responseMode: 'inline',
procedure: feature.attributes.id,
offering: name,
observedProperty: offering.observedProperties[0],
observedProperties: offering.observedProperties,
responseFormat: this.responseFormat
});
OpenLayers.Request.POST({

View File

@@ -287,8 +287,8 @@
"OpenLayers/Format/WMSGetFeatureInfo.js",
"OpenLayers/Format/SOSCapabilities.js",
"OpenLayers/Format/SOSCapabilities/v1_0_0.js",
"OpenLayers/Format/SOSGetObservation.js",
"OpenLayers/Format/SOSGetFeatureOfInterest.js",
"OpenLayers/Format/SOSGetObservation.js",
"OpenLayers/Format/OWSContext.js",
"OpenLayers/Format/OWSContext/v0_3_1.js",
"OpenLayers/Format/WMTSCapabilities.js",

View File

@@ -5,8 +5,7 @@
/**
* @requires OpenLayers/Format/XML.js
* @requires OpenLayers/Format/GML.js
* @requires OpenLayers/Format/GML/v3.js
* @requires OpenLayers/Format/SOSGetFeatureOfInterest.js
*/
/**
@@ -29,6 +28,7 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
sos: "http://www.opengis.net/sos/1.0",
ogc: "http://www.opengis.net/ogc",
om: "http://www.opengis.net/om/1.0",
sa: "http://www.opengis.net/sampling/1.0",
xlink: "http://www.w3.org/1999/xlink",
xsi: "http://www.w3.org/2001/XMLSchema-instance"
},
@@ -88,7 +88,7 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var info = {measurements: []};
var info = {measurements: [], observations: []};
this.readNode(data, info);
return info;
},
@@ -105,6 +105,7 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
write: function(options) {
var node = this.writeNode("sos:GetObservation", options);
node.setAttribute("xmlns:om", this.namespaces.om);
node.setAttribute("xmlns:ogc", this.namespaces.ogc);
this.setAttributeNS(
node, this.namespaces.xsi,
"xsi:schemaLocation", this.schemaLocation
@@ -134,6 +135,11 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
observationCollection.measurements.push(measurement);
this.readChildNodes(node, measurement);
},
"Observation": function(node, observationCollection) {
var observation = {};
observationCollection.observations.push(observation);
this.readChildNodes(node, observation);
},
"samplingTime": function(node, measurement) {
var samplingTime = {};
measurement.samplingTime = samplingTime;
@@ -149,6 +155,20 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
this.getAttributeNS(node, this.namespaces.xlink, "href");
this.readChildNodes(node, measurement);
},
"featureOfInterest": function(node, observation) {
var foi = {features: []};
observation.fois = [];
observation.fois.push(foi);
this.readChildNodes(node, foi);
// postprocessing to get actual features
var features = [];
for (var i=0, len=foi.features.length; i<len; i++) {
var feature = foi.features[i];
features.push(new OpenLayers.Feature.Vector(
feature.components[0], feature.attributes));
}
foi.features = features;
},
"result": function(node, measurement) {
var result = {};
measurement.result = result;
@@ -160,6 +180,7 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
}
}
},
"sa": OpenLayers.Format.SOSGetFeatureOfInterest.prototype.readers.sa,
"gml": OpenLayers.Util.applyDefaults({
"TimeInstant": function(node, samplingTime) {
var timeInstant = {};
@@ -169,7 +190,7 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
"timePosition": function(node, timeInstant) {
timeInstant.timePosition = this.getChildValue(node);
}
}, OpenLayers.Format.GML.v3.prototype.readers.gml)
}, OpenLayers.Format.SOSGetFeatureOfInterest.prototype.readers.gml)
},
/**
@@ -188,29 +209,51 @@ OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
}
});
this.writeNode("offering", options, node);
this.writeNode("eventTime", options, node);
this.writeNode("procedure", options, node);
this.writeNode("observedProperty", options, node);
if (options.eventTime) {
this.writeNode("eventTime", options, node);
}
for (var procedure in options.procedures) {
this.writeNode("procedure", options.procedures[procedure], node);
}
for (var observedProperty in options.observedProperties) {
this.writeNode("observedProperty", options.observedProperties[observedProperty], node);
}
if (options.foi) {
this.writeNode("featureOfInterest", options.foi, node);
}
this.writeNode("responseFormat", options, node);
this.writeNode("resultModel", options, node);
this.writeNode("responseMode", options, node);
if (options.resultModel) {
this.writeNode("resultModel", options, node);
}
if (options.responseMode) {
this.writeNode("responseMode", options, node);
}
return node;
},
"featureOfInterest": function(foi) {
var node = this.createElementNSPlus("featureOfInterest");
this.writeNode("ObjectID", foi.objectId, node);
return node;
},
"ObjectID": function(options) {
return this.createElementNSPlus("ObjectID",
{value: options});
},
"responseFormat": function(options) {
return this.createElementNSPlus("responseFormat",
{value: options.responseFormat});
},
"procedure": function(options) {
"procedure": function(procedure) {
return this.createElementNSPlus("procedure",
{value: options.procedure});
{value: procedure});
},
"offering": function(options) {
return this.createElementNSPlus("offering", {value:
options.offering});
},
"observedProperty": function(options) {
"observedProperty": function(observedProperty) {
return this.createElementNSPlus("observedProperty",
{value: options.observedProperty});
{value: observedProperty});
},
"eventTime": function(options) {
var node = this.createElementNSPlus("eventTime");

View File

@@ -4,7 +4,7 @@
<script type="text/javascript">
function test_read_SOSGetObservation(t) {
t.plan(7);
t.plan(13);
var parser = new OpenLayers.Format.SOSGetObservation();
var text =
@@ -49,15 +49,130 @@
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(1);
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',
procedure: 'urn:ogc:object:feature:OSIRIS-HWS:4fc335bc-06d7-4d5e-a72a-1ac73b9f3b56', responseFormat: 'text/xml;subtype="om/1.0.0"',
offering: 'TEMPERATURE', observedProperty: 'urn:x-ogc:def:property:OGC::Temperature'});
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");
}