add format for Sensor Observation Service GetObservation operation, r=ahocevar (closes #2372)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9898 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -267,6 +267,7 @@
|
|||||||
"OpenLayers/Format/OWSCommon/v1_1_0.js",
|
"OpenLayers/Format/OWSCommon/v1_1_0.js",
|
||||||
"OpenLayers/Format/SOSCapabilities.js",
|
"OpenLayers/Format/SOSCapabilities.js",
|
||||||
"OpenLayers/Format/SOSCapabilities/v1_0_0.js",
|
"OpenLayers/Format/SOSCapabilities/v1_0_0.js",
|
||||||
|
"OpenLayers/Format/SOSGetObservation.js",
|
||||||
"OpenLayers/Layer/WFS.js",
|
"OpenLayers/Layer/WFS.js",
|
||||||
"OpenLayers/Control/GetFeature.js",
|
"OpenLayers/Control/GetFeature.js",
|
||||||
"OpenLayers/Control/MouseToolbar.js",
|
"OpenLayers/Control/MouseToolbar.js",
|
||||||
|
|||||||
254
lib/OpenLayers/Format/SOSGetObservation.js
Normal file
254
lib/OpenLayers/Format/SOSGetObservation.js
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
|
||||||
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class: OpenLayers.Format.SOSGetObservation
|
||||||
|
* Read and write SOS GetObersation (to get the actual values from a sensor)
|
||||||
|
* version 1.0.0
|
||||||
|
*
|
||||||
|
* Inherits from:
|
||||||
|
* - <OpenLayers.Format.XML>
|
||||||
|
*/
|
||||||
|
OpenLayers.Format.SOSGetObservation = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: namespaces
|
||||||
|
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||||
|
*/
|
||||||
|
namespaces: {
|
||||||
|
ows: "http://www.opengis.net/ows",
|
||||||
|
gml: "http://www.opengis.net/gml",
|
||||||
|
sos: "http://www.opengis.net/sos/1.0",
|
||||||
|
ogc: "http://www.opengis.net/ogc",
|
||||||
|
om: "http://www.opengis.net/om/1.0",
|
||||||
|
xlink: "http://www.w3.org/1999/xlink",
|
||||||
|
xsi: "http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: regExes
|
||||||
|
* Compiled regular expressions for manipulating strings.
|
||||||
|
*/
|
||||||
|
regExes: {
|
||||||
|
trimSpace: (/^\s*|\s*$/g),
|
||||||
|
removeSpace: (/\s*/g),
|
||||||
|
splitSpace: (/\s+/),
|
||||||
|
trimComma: (/\s*,\s*/g)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: VERSION
|
||||||
|
* {String} 1.0.0
|
||||||
|
*/
|
||||||
|
VERSION: "1.0.0",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: schemaLocation
|
||||||
|
* {String} Schema location
|
||||||
|
*/
|
||||||
|
schemaLocation: "http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: defaultPrefix
|
||||||
|
*/
|
||||||
|
defaultPrefix: "sos",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor: OpenLayers.Format.SOSGetObservation
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* options - {Object} An optional object whose properties will be set on
|
||||||
|
* this instance.
|
||||||
|
*/
|
||||||
|
initialize: function(options) {
|
||||||
|
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: read
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* data - {String} or {DOMElement} data to read/parse.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} An object containing the measurements
|
||||||
|
*/
|
||||||
|
read: function(data) {
|
||||||
|
if(typeof data == "string") {
|
||||||
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||||
|
}
|
||||||
|
if(data && data.nodeType == 9) {
|
||||||
|
data = data.documentElement;
|
||||||
|
}
|
||||||
|
var info = {measurements: []};
|
||||||
|
this.readNode(data, info);
|
||||||
|
return info;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: write
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* options - {Object} Optional object.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {String} An SOS GetObservation request XML string.
|
||||||
|
*/
|
||||||
|
write: function(options) {
|
||||||
|
var node = this.writeNode("sos:GetObservation", options);
|
||||||
|
this.setAttributeNS(
|
||||||
|
node, this.namespaces.xsi,
|
||||||
|
"xsi:schemaLocation", this.schemaLocation
|
||||||
|
);
|
||||||
|
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: readers
|
||||||
|
* Contains public functions, grouped by namespace prefix, that will
|
||||||
|
* be applied when a namespaced node is found matching the function
|
||||||
|
* name. The function will be applied in the scope of this parser
|
||||||
|
* with two arguments: the node being read and a context object passed
|
||||||
|
* from the parent.
|
||||||
|
*/
|
||||||
|
readers: {
|
||||||
|
"om": {
|
||||||
|
"ObservationCollection": function(node, obj) {
|
||||||
|
obj.id = this.getAttributeNS(node, this.namespaces.gml, "id");
|
||||||
|
this.readChildNodes(node, obj);
|
||||||
|
},
|
||||||
|
"member": function(node, observationCollection) {
|
||||||
|
this.readChildNodes(node, observationCollection);
|
||||||
|
},
|
||||||
|
"Measurement": function(node, observationCollection) {
|
||||||
|
var measurement = {};
|
||||||
|
observationCollection.measurements.push(measurement);
|
||||||
|
this.readChildNodes(node, measurement);
|
||||||
|
},
|
||||||
|
"samplingTime": function(node, measurement) {
|
||||||
|
var samplingTime = {};
|
||||||
|
measurement.samplingTime = samplingTime;
|
||||||
|
this.readChildNodes(node, samplingTime);
|
||||||
|
},
|
||||||
|
"observedProperty": function(node, measurement) {
|
||||||
|
measurement.observedProperty =
|
||||||
|
this.getAttributeNS(node, this.namespaces.xlink, "href");
|
||||||
|
this.readChildNodes(node, measurement);
|
||||||
|
},
|
||||||
|
"procedure": function(node, measurement) {
|
||||||
|
measurement.procedure =
|
||||||
|
this.getAttributeNS(node, this.namespaces.xlink, "href");
|
||||||
|
this.readChildNodes(node, measurement);
|
||||||
|
},
|
||||||
|
"result": function(node, measurement) {
|
||||||
|
var result = {};
|
||||||
|
measurement.result = result;
|
||||||
|
if (this.getChildValue(node) !== '') {
|
||||||
|
result.value = this.getChildValue(node);
|
||||||
|
result.uom = node.getAttribute("uom");
|
||||||
|
} else {
|
||||||
|
this.readChildNodes(node, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gml": OpenLayers.Util.applyDefaults({
|
||||||
|
"TimeInstant": function(node, samplingTime) {
|
||||||
|
var timeInstant = {};
|
||||||
|
samplingTime.timeInstant = timeInstant;
|
||||||
|
this.readChildNodes(node, timeInstant);
|
||||||
|
},
|
||||||
|
"timePosition": function(node, timeInstant) {
|
||||||
|
timeInstant.timePosition = this.getChildValue(node);
|
||||||
|
}
|
||||||
|
}, OpenLayers.Format.GML.v3.prototype.readers.gml)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: writers
|
||||||
|
* As a compliment to the readers property, this structure contains public
|
||||||
|
* writing functions grouped by namespace alias and named like the
|
||||||
|
* node names they produce.
|
||||||
|
*/
|
||||||
|
writers: {
|
||||||
|
"sos": {
|
||||||
|
"GetObservation": function(options) {
|
||||||
|
var node = this.createElementNSPlus("GetObservation", {
|
||||||
|
attributes: {
|
||||||
|
version: this.VERSION,
|
||||||
|
service: 'SOS'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.writeNode("offering", options, node);
|
||||||
|
this.writeNode("eventTime", options, node);
|
||||||
|
this.writeNode("procedure", options, node);
|
||||||
|
this.writeNode("observedProperty", options, node);
|
||||||
|
this.writeNode("responseFormat", options, node);
|
||||||
|
this.writeNode("resultModel", options, node);
|
||||||
|
this.writeNode("responseMode", options, node);
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
"responseFormat": function(options) {
|
||||||
|
return this.createElementNSPlus("responseFormat",
|
||||||
|
{value: options.responseFormat});
|
||||||
|
},
|
||||||
|
"procedure": function(options) {
|
||||||
|
return this.createElementNSPlus("procedure",
|
||||||
|
{value: options.procedure});
|
||||||
|
},
|
||||||
|
"offering": function(options) {
|
||||||
|
return this.createElementNSPlus("offering", {value:
|
||||||
|
options.offering});
|
||||||
|
},
|
||||||
|
"observedProperty": function(options) {
|
||||||
|
return this.createElementNSPlus("observedProperty",
|
||||||
|
{value: options.observedProperty});
|
||||||
|
},
|
||||||
|
"eventTime": function(options) {
|
||||||
|
var node = this.createElementNSPlus("eventTime");
|
||||||
|
if (options.eventTime === 'latest') {
|
||||||
|
this.writeNode("ogc:TM_Equals", options, node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
"resultModel": function(options) {
|
||||||
|
return this.createElementNSPlus("resultModel", {value:
|
||||||
|
options.resultModel});
|
||||||
|
},
|
||||||
|
"responseMode": function(options) {
|
||||||
|
return this.createElementNSPlus("responseMode", {value:
|
||||||
|
options.responseMode});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ogc": {
|
||||||
|
"TM_Equals": function(options) {
|
||||||
|
var node = this.createElementNSPlus("ogc:TM_Equals");
|
||||||
|
this.writeNode("ogc:PropertyName", {property:
|
||||||
|
"urn:ogc:data:time:iso8601"}, node);
|
||||||
|
if (options.eventTime === 'latest') {
|
||||||
|
this.writeNode("gml:TimeInstant", {value: 'latest'}, node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
"PropertyName": function(options) {
|
||||||
|
return this.createElementNSPlus("ogc:PropertyName",
|
||||||
|
{value: options.property});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gml": {
|
||||||
|
"TimeInstant": function(options) {
|
||||||
|
var node = this.createElementNSPlus("gml:TimeInstant");
|
||||||
|
this.writeNode("gml:timePosition", options, node);
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
"timePosition": function(options) {
|
||||||
|
var node = this.createElementNSPlus("gml:timePosition",
|
||||||
|
{value: options.value});
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
CLASS_NAME: "OpenLayers.Format.SOSGetObservation"
|
||||||
|
|
||||||
|
});
|
||||||
68
tests/Format/SOSGetObservation.html
Normal file
68
tests/Format/SOSGetObservation.html
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function test_read_SOSGetObservation(t) {
|
||||||
|
t.plan(7);
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_write_SOSGetObservation(t) {
|
||||||
|
t.plan(1);
|
||||||
|
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'});
|
||||||
|
t.xml_eq(output, expect, "Request XML is written out correctly");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -86,6 +86,7 @@
|
|||||||
<li>Format/CSWGetRecords.html</li>
|
<li>Format/CSWGetRecords.html</li>
|
||||||
<li>Format/CSWGetRecords/v2_0_2.html</li>
|
<li>Format/CSWGetRecords/v2_0_2.html</li>
|
||||||
<li>Format/SOSCapabilities/v1_0_0.html</li>
|
<li>Format/SOSCapabilities/v1_0_0.html</li>
|
||||||
|
<li>Format/SOSGetObservation.html</li>
|
||||||
<li>Format/XML.html</li>
|
<li>Format/XML.html</li>
|
||||||
<li>Geometry.html</li>
|
<li>Geometry.html</li>
|
||||||
<li>Geometry/Collection.html</li>
|
<li>Geometry/Collection.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user