Sunday, 14 June 2015

geoserver - Passing selected polygon to INTERSECTS filter in a WFS request


In the code below,


   


the_geom

sf:restricted
the_geom
cat = 3





I'd like to replace


   sf:restricted
the_geom
cat = 3

with a polygon selected by a user. I get the polygon from a selection event. I've tried a number of options, but none is working, yet. Any assistance will be highly appreciated.


My environment: GeoServer 2.1.3, OpenLayers 2.11.




I've transformed my geometry to EPSG:4326, the one used by my layers in GeoServer:


var geometry = event.feature.geometry.transform(new OpenLayers.Projection("900913"), new OpenLayers.Projection("EPSG:4326"));


The event.feature.geometry represents a polygon selected by a user. I've also converted the geometry to WKT format as shown below:


var wktParser = new OpenLayers.Format.WKT();
var feature = new OpenLayers.Feature.Vector();
feature.geometry = geometry;

var wktGeom = wktParser.write(feature);

I've then passed the geometry in WKT format to the filter as shown below:


'' +

'' +
'the_geom' +
'' +
'ws:layer_2' +
'the_geom' +
'INTERSECTS(the_geom,' + wktGeom + ')' +
'
' +
'
' +
'
';


But when I send a request, the following error is returned:


Process failed during execution java.lang.ClassCastException: org.geotools.filter.AttributeExpressionImpl cannot be cast to org.opengis.filter.Filter org.geotools.filter.AttributeExpressionImpl cannot be cast to org.opengis.filter.Filter.


Any idea on what I may be doing wrong?



Answer



http://docs.geotools.org/latest/userguide/library/cql/cql.html


So the third parameter would be something like:


INTERSECTS(ATTR1, POLYGON((... )) )


The polygon has to be expressed in the WKT syntax and be in the same SRS as the layer being queried. Either that, or get a recent GeoServer version and call setSRS(POLYGON(...), 'EPSG:xywz') around the WKT (that function has been added May 27 so it should be in 2.1.4 but not earlier versions)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...