Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In the code below,

   <ogc:Filter>
     <ogc:Intersects>
       <ogc:PropertyName>the_geom</ogc:PropertyName>
       <ogc:Function name="querySingle">
          <ogc:Literal>sf:restricted</ogc:Literal>
          <ogc:Literal>the_geom</ogc:Literal>
          <ogc:Literal>cat = 3</ogc:Literal>
       </ogc:Function>
     </ogc:Intersects>
   </ogc:Filter>

i'd like to replace

   <ogc:Literal>sf:restricted</ogc:Literal>
   <ogc:Literal>the_geom</ogc:Literal>
   <ogc:Literal>cat = 3</ogc:Literal>

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.

UPDATE: 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:

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:

'<ogc:Filter>' +
'<ogc:Intersects>' +
    '<ogc:PropertyName>the_geom</ogc:PropertyName>' +
    '<ogc:Function name="querySingle">' +
        '<ogc:Literal>ws:layer_2</ogc:Literal>' +
        '<ogc:Literal>the_geom</ogc:Literal>' +
        '<ogc:Literal>INTERSECTS(the_geom,' + wktGeom + ')</ogc:Literal>' +
    '</ogc:Function>' +
'</ogc:Intersects>' +
'</ogc:Filter>';

But when I send a request, the following error is returned: <ows:ExceptionText>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</ows:ExceptionText>.

Any idea on what I may be doing wrong.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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)

share|improve this answer
    
Thanks Andrea. I've tried your suggestion: I've transformed my projection and converted the polygon to wkt representation. Refer to the updated question above. But I get a ClassCastException when I send a request. Any idea on what I may be doing wrong? –  okello Jul 16 '12 at 13:41
    
You added single quotes around the geometry WTK, there should be none. Not sure this is the reason for the issue though –  Andrea Aime Jul 16 '12 at 21:28
    
Thanks for the response. Actually, its not a quote. Rather, I'm concatenating strings, and passing in the value of wktGeom. –  okello Jul 17 '12 at 6:01
    
Its now working. I was using the inbuilt toWKT() function. It worked when I manually did the conversion to WKT. Thanks. –  okello Jul 17 '12 at 8:04

I have been trying to figure out how to send a filter to geoserver using wfs.

The filter that I want to send is:

<ogc:Filter>
 <ogc:Intersects>
   <ogc:PropertyName>the_geom</ogc:PropertyName>
   <ogc:Function name="querySingle">
      <ogc:Literal>sf:restricted</ogc:Literal>
      <ogc:Literal>the_geom</ogc:Literal>
      <ogc:Literal>cat = 3</ogc:Literal>
   </ogc:Function>
 </ogc:Intersects>

I have a WFS protocol and i would like to attach that filter with this request:

                wfsProtocol = new OpenLayers.Protocol.WFS({
                            url: "http://localhost:8080/geoserver/wfs",
                            featureType: ["tasmania_water_bodies"],
                            featureNS: "http://www.openplans.org/topp"
                        });

            wfsLayer = new OpenLayers.Layer.Vector("LinesWFS", {
                        strategies: [new OpenLayers.Strategy.Fixed()],
                        protocol: wfsProtocol
                    });

I have tried converting it to a filter using this:

            parser = new OpenLayers.Format.Filter.v1_1_0 ();
            xml = new OpenLayers.Format.XML();
            my_filter_xml = fil; //your filter string

            var x = xml.read(my_filter_xml).documentElement
            var filter1 = parser.read(x);
            console.log(filter1)

That works for very basic xml filters, but not the one that I want to convert.

Am I doing it the wrong way?

share|improve this answer
    
I think you need to ask this as a separate question. From the outset, the filter is in GML/XML. So, you may need to convert your WFS request to GML/XML as well. Otherwise, convert the filter into a format compatible with the way your are constructing your WFS request. –  okello Jul 22 '12 at 7:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.