[OpenLayers-Users] Problems with Openlayers.Filter.Function in WFS
brking
brking at gmail.com
Sat Jul 13 15:38:58 PDT 2013
If anyone is interested in how to make this work.
Format/Filter/v1.js:
add "FUNCTION" to the filter map
filterMap: {
"&&": "And",
...
"FID": "_featureIds",
"FUNCTION": "Function"
},
I also wanted to support PropertyName as an argument to a function, so
change the writer to add a "properties" collection:
"Function": function(filter) {
var node = this.createElementNSPlus("ogc:Function", {
attributes: {
name: filter.name
}
});
var params = filter.params;
for(var i=0, len=params.length; i<len; i++){
this.writeOgcExpression(params[i], node);
}
var properties = filter.properties;
for(var i=0, len=properties.length; i<len; i++){
var propNode =
this.createElementNSPlus("ogc:PropertyName", { value:
properties[i] });
node.appendChild(propNode);
}
return node;
},
Now I can use it like this:
var subFilter = new OpenLayers.Filter.Function({
type: 'FUNCTION',
name: 'MyFunction',
params: [1.23, 4.56, 'param3'],
properties: ['Altitude', 'Heading']
});
var timeFilter = new OpenLayers.Filter.Logical( {
type: OpenLayers.Filter.Logical.AND,
filters: [
new OpenLayers.Filter.Comparison({
type:
OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
property: 'startdate',
value: startDate
}),
subFilter
]
}
);
and get OGC encoded like this:
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs"
service="WFS" version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="feature:nyc_buildings" xmlns:feature="ncr">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>startdate</ogc:PropertyName>
<ogc:Literal>"2003-04-12 04:00:00 z"</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:Function name="MyFunction">
<ogc:Literal>1.23</ogc:Literal>
<ogc:Literal>4.56</ogc:Literal>
<ogc:Literal>param3</ogc:Literal>
<ogc:PropertyName>Altitude</ogc:PropertyName>
<ogc:PropertyName>Heading</ogc:PropertyName>
</ogc:Function>
</ogc:And>
<ogc:BBOX>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:coordinates decimal="." cs="," ts=" ">-188.17578125,-2.275390625
-7.82421875,82.275390625</gml:coordinates>
</gml:Box>
</ogc:BBOX>
</ogc:And>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Problems-with-Openlayers-Filter-Function-in-WFS-tp5066248p5066253.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list