[OpenLayers-Dev] Fwd: Help to create FeatureId filter & OpenLayers.Filter.Logical.NOT

Ivan Grcic ivan.grcic at geofoto.hr
Thu Dec 10 12:38:13 EST 2009


Hi devs,

before opening ticket i want to confirm that im right about this issue

Currently its not possible to make filter like this:
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<And>
<Not><ogc:FeatureId fid="Feature.1"/></Not>
<Not><ogc:FeatureId fid="Feature.2"/></Not>
</And>
</Filter>

I trace the source of it, in Format/Filter/v1.js writers&readers for
AND,OR, NOT do not handle FeatureIds seperatly as root "Filter" does.

line: 296

            "Not": function(filter) {
                var node = this.createElementNSPlus("ogc:Not");
                var childFilter = filter.filters[0];
                this.writeNode(
                    this.getFilterType(childFilter), childFilter, node
                );
                return node;
            },

That happens because FeatureId doesnt have type and getFilterType
method throws "Filter writing not supported for rule type: undefined"
if we try to encapsulate FeatureId with Logical.Not

Its neccesary to check if filter is of FeatureId type and treat it
differently, like the root Filter element does

            "Not": function(filter) {
                var node = this.createElementNSPlus("ogc:Not");
                var childFilter = filter.filters[0];

                var sub = childFilter.CLASS_NAME.split(".").pop();
                if(sub === "FeatureId") {
                    for(var i=0; i<childFilter.fids.length; ++i) {
                        this.writeNode("FeatureId", childFilter.fids[i], node);
                    }
                } else {
                    this.writeNode(
                        this.getFilterType(childFilter), childFilter, node
                    );
                }
                return node;
            }

Please can anyone confirm this?

Tnx

---------- Forwarded message ----------
From: Ivan Grcic <ivan.grcic at geofoto.hr>
Date: Thu, Dec 10, 2009 at 2:10 PM
Subject: Help to create FeatureId filter & OpenLayers.Filter.Logical.NOT
To: users at openlayers.org


Hi,

I need to make a filter that combines Layers.Filter.Logical.NOT with FeatureId.
Filter structure  should  be like:

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<And>
<Not><ogc:FeatureId fid="Feature.1"/></Not>
<Not><ogc:FeatureId fid="Feature.2"/></Not>
</And>
...
...
</Not>
</ogc:Filter>


I tried creating one like this:

var filter_1_1 = new OpenLayers.Format.Filter({version: "1.1.0"});
var xml = new OpenLayers.Format.XML();

var featIdsFilter = [];

//iterate trough features and make  arrays of <Not><ogc:FeatureId
fid="Feature.1"/></Not> filters
for(var i=0, len=wfsLayer.features.length; i<len; i++){
   featIdsFilter.push(
       new OpenLayers.Filter.Logical({
           type: OpenLayers.Filter.Logical.NOT,
           filters: [new OpenLayers.Filter.FeatureId({fids:
[wfsLayer.features[i].fid]})]
       })
   );
}

//combines previous array with AND filter
var filterObj = new OpenLayers.Filter.Logical({
   type: OpenLayers.Filter.Logical.AND,
   filters: featIdsFilter
});

try{
   var filter = xml.write(filter_1_1.write(filterObj));
} catch(err) {
   alert(err);
}


filterObj gets created but when I try to write filter I get error:
Filter writing not supported for rule type: undefined

I used FIlters a lot before but for some reason I cant make Logical.NOT to work.
Apparently im not using OpenLayers.Filter.Logical.NOT in the right way...

Anybody had case like this?

Thanx,

Cheers

--
Ivan Grcic



-- 
Ivan Grcic



More information about the Dev mailing list