I have two vector layers in GeoServer.

  1. One is a polygon like; enter image description here

and another one is a polyline like; enter image description here

By cross-layer filtering, I want to select only those polygons from 1st layer which are crossed by any specifically chosen polyline from 2nd layer.

I have used the CQL_Filter as per the documentation as;

INCLUDE;WITHIN(geometry, collectGeometries(queryCollection('railway_shapefile', 'geometry', 'FROM=''DELHI'' AND TO=''AMBALA''')))

where FROM & TO are the attributes from polyline shapefile


enter image description here

Basically, what is want is that if a select a single line running between two stations, then only the polygons from/through which line is crossing should be selected/filtered/highlighted. The rest should be masked/not selected/not highlighted.

and The layer does not open if I delete INCLUDE from the CQL_FILTER

CQL_FILTER=WITHIN(geometry, collectGeometries(queryCollection('railway_shapefile', 'geometry', 'FROM=''DELHI'' AND TO=''AMBALA''')))

What would be the correct syntax for this?

1 Answer 1


Your query fails when you leave out the INCLUDE because with 2 layers you must have 2 filters. But you don't want the first one to be INCLUDE because that will draw all of your polygons. You want that one to be the cross layer query filter and the second one to select just the rail line you want. So I would expect something like this to work:

CQL_FILTER=WITHIN(geometry, collectGeometries(queryCollection('railway_shapefile', 'geometry', 'FROM=''DELHI'' AND TO=''AMBALA''')));FROM='DELHI' AND TO='AMBALA'
  • i tried this way http://localhost:8585/geoserver/aasdagrometgis/wms?service=WMS&version=1.1.0&request=GetMap&LAYERS=aasdagrometgis:INDIA_DIST_717_GCS,aasdagrometgis:railway_shapefile&%20CQL_FILTER=CQL_FILTER=WITHIN(geometry,%20collectGeometries(queryCollection(%27railway_shapefile%27,%20%27geometry%27,%20%27FROM=%27%27DELHI%27%27%20AND%20TO=%27%27AMBALA%27%27%27)));FROM=%27DELHI%27%20AND%20TO=%27AMBALA%27&bbox=68.18624877929688%2C6.755565643310547%2C97.41529846191406%2C37.07667922973633&width=740&height=768&srs=EPSG%3A4326&styles=&format=application/openlayers but it did not worked. Jan 30 at 11:54
  • It returned all the polygons from 1st layer and all the lines from second layer; Earlier I was getting all the polygons from 1st layer but only the selected line from second layer. @IanTurton Jan 30 at 11:55
  • you have two CQL_FILTERs in that URL
    – Ian Turton
    Jan 30 at 12:32
  • It worked well with CROSSES(geometry, collectGeometries(queryCollection('railway_shapefile', 'geometry', 'FROM=''DELHI'' AND TO=''SAHARANPUR''')));FROM='DELHI' AND TO='SAHARANPUR' Thanks a ton with the syntax. Jan 30 at 12:46
  • Final URL was something like http://localhost:8585/geoserver/aasdagrometgis/wms?service=WMS&version=1.1.0&request=GetMap&LAYERS=aasdagrometgis:INDIA_DIST_717_GCS,aasdagrometgis:railway_shapefile&CQL_FILTER=CROSSES(geometry,%20collectGeometries(queryCollection(%27railway_shapefile%27,%20%27geometry%27,%20%27FROM=%27%27DELHI%27%27%20AND%20TO=%27%27AMBALA%27%27%27)));FROM=%27DELHI%27%20AND%20TO=%27AMBALA%27&bbox=68.18624877929688%2C6.755565643310547%2C97.41529846191406%2C37.07667922973633&width=740&height=768&srs=EPSG%3A4326&styles=&format=application/openlayers Jan 30 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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