1

Given a point layer and a polygon layer (P1) in GeoServer, the following CQL Filter selects points which intersect the polygon P1:

CQL_FILTER = "Within(geom,POLYGON((P1_coordinates)))";

The resulting point features are shown in yellow in the left-hand diagram:

enter image description here

Given a second polygon layer (P2) which overlaps the first layer (P1), is there a CQL Filter expression which will select the points which intersect P1 but do not intersect P2? The desired result is shown in yellow in the right-hand diagram.

(In effect I want to treat P1 like a donut with P2 representing the hole, but this is not how the geometries are stored in the database).

Based on the page at http://docs.geoserver.org/latest/en/user/filter/ecql_reference.html#spatial-predicate it seems like I should be using a combination of within and disjoint but I'm not sure how to string them together.

Edit: The database is PostgreSQL and I'm using GeoServer 2.10.1. I'm sending the CQL filter as parameter in an AJAX query from a JavaScript app. Assume for the purposes of this question that I can't access the database, ie I'm hoping for an answer from the GeoServer side, rather than creating a view on the database, etc.

  • 1
    In ArcMap or QGIS I would first select the points which intersect P1 then unselect the points which intersect P2. Is that possible using CQL? If it makes a difference I'm sending the CQL_FILTER in an AJAX request – Stephen Lead May 30 '18 at 21:30
  • What is your back-end data system? If you can do this in QGIS or ArcMap, you can certainly do this in PostGIS, and wondering if the better approach would be to feed this into a parameterized SQL view that can do the processing instead of the "limited" CQL filter (Limited by some documentation I read...) – DPSSpatial May 30 '18 at 23:43
  • @DPSSpatial assume for the sake of this question that I can't access the database and need to solve it via CQL filter. Is that possible? (it's fine if the answer is no) – Stephen Lead May 30 '18 at 23:50
  • I figured that might be the case... – DPSSpatial May 31 '18 at 13:10
1

I would try something like:

CQL_FILTER = "Within(geom,POLYGON((P1_coordinates))) AND NOT Within(geom,POLYGON((P2...)))";
  • So simple, I feel stoopid for not trying it. SQL is definitely an area I need to work on! – Stephen Lead May 31 '18 at 13:54

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.