0

So, I have a geoserver layer with point markers (POI) in several category such as ATMs, churches, government buildings, parks, etc. Is there a way to filter this layer via URL parameters so I don't have to define a new layer for each category? also, I am using openlayers-3 as the frontend interface.

To complete the question, I have a request URL like this:

http://localhost:8080/geoserver/gis_localhost/wms?service=WMS&version=1.1.0&request=GetMap&layers=gis_localhost:table_location&styles=&bbox=95.282956,5.517893,95.374536,5.60221&width=768&height=707&srs=EPSG:4326&format=application/openlayers

with the result similar to this: enter image description here

where each of category is saved as category in postgis table_location. Now I want to filter based on category, for example I want to use filter to only show police stations

  • openlayers 2 like the tag, or openlayers 3 like the question? – BradHards Aug 23 '16 at 7:33
  • This is what WFS CQL/ECQL queries do. Have you looked at the filter options in docs.geoserver.org/latest/en/user/filter/syntax.html ? – BradHards Aug 23 '16 at 7:36
  • CMIIW, as long as my understanding, what CQL do in geoserver is creating a query from available layer, and save it as new layer. so, if I have 20 categories, it will create 20 new layers that I can use later. What I am asking is, is there a way to filter from Url without defining a new layer. I read the documentation, but all of example there is confusing for a beginner like me and does not fit to my case. – Zuzu Softman Aug 23 '16 at 7:56
  • 1
    You don't need to create a layer, and normally wouldn't. You can pass the filter as a vendor argument in the WMS URL, or as the filter in WFS. If you show an example of your URL, and the filter you want to use, I might have a chance to provide an answer. – BradHards Aug 23 '16 at 8:05
  • I edited the question – Zuzu Softman Aug 23 '16 at 8:30
2

CQL_FILTER is documented in http://docs.geoserver.org/stable/en/user/tutorials/cql/cql_tutorial.html.

Make a test request without CQL_FILTER

http://demo.opengeo.org/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp:states&styles=&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG:4326&format=image/png

enter image description here

Make a new request with CQL_FILTER

http://demo.opengeo.org/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp:states&styles=&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG:4326&format=image/png&CQL_FILTER=STATE_NAME=%27Texas%27

enter image description here

All you need to do is to make sure that your OpenLayers application adds a CQL_FILTER that fulfills your needs.

  • I see... I can directly input cql in preview and see the difference in requested URL. thank you :) – Zuzu Softman Aug 24 '16 at 7:21

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.