Problems with Openlayers.Filter.Function in WFS

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with Openlayers.Filter.Function in WFS

brking
I think maybe I don't understand how OpenLayers.Filter.Function can be used at all. How can it be use in conjunction with either a Comparison or Logical filter ?

When used with comparison:

"Uncaught TypeError: undefined is not a function "

Code:
                var subFilter = new OpenLayers.Filter.Function({
                    type: OpenLayers.Filter.Function,
                    name: 'MyFunction',
                    params: [1.23, 4.56, 'param3']
                });

                var timeFilter = new OpenLayers.Filter.Comarison({
                        type: OpenLayers.Filter.Comparison.EQUAL_TO,
                        property: 'startdate',
                        value: subFilter
                });

                var layer = map.getLayersByName("NYC")[0];
                layer.filter = timeFilter;
                layer.refresh({force: true});

So a function cannot be used as a comparison value ?

Then with a Logical I get:

"Uncaught Filter writing not supported for rule type: function (){b.prototype.initialize.apply(this,arguments)} "

                var subFilter = new OpenLayers.Filter.Function({
                    type: OpenLayers.Filter.Function,
                    name: 'MyFunction',
                    params: [1.23, 4.56, 'param3']
                });

                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
                        ]
                    }
                );

This one I really don't get. Clearly this second argument is a filter, so why is it not accepted by the AND function ? I've been struggling trying to figure this out but I don't know what is wrong. Thanks for any help.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with Openlayers.Filter.Function in WFS

brking
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>
Reply | Threaded
Open this post in threaded view
|

Re: Problems with Openlayers.Filter.Function in WFS

Bart van den Eijnden
Thanks for your work (and perseverance) on this, any chance you can open up a github pull request for this? TIA.

Best regards,
Bart

-- 
Bart van den Eijnden
OpenGeo - http://opengeo.org
Expert service straight from the developers.



On Jul 14, 2013, at 12:38 AM, brking <[hidden email]> wrote:

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&lt;len; i++){
                   var propNode =
this.createElementNSPlus(&quot;ogc:PropertyName&quot;, { 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:

&lt;wfs:GetFeature xmlns:wfs=&quot;http://www.opengis.net/wfs&quot;
service=&quot;WFS&quot; version=&quot;1.0.0&quot;
xsi:schemaLocation=&quot;http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;>
<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.
_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: Problems with Openlayers.Filter.Function in WFS

brking
Sure I can give it a shot. I've not been using GIT but I've been wanting to set it up anyway.