I have two Layers which I added to the map using WMS service. Is there a way to perform spatial queries using Lealflet, for example; Intersection, Distance...?

2 Answers 2


As far as I know, you can't. WMS layers are images(pixels). Points, Polygons, and lines can be spatially queried. If you can retrieve the layer as a WFS or geojson file then you have objects to query.


Correct me if I am wrong. You can't perform that analysis on WMS.

For doing the above-mentioned task you must be bringing those layers from a database which many times may be postgis. Try to work with leaflet Geojson. For example

select ST_AsText(ST_Intersection(linestring, polygon)) As wkt from ST_GeomFromText('LINESTRING Z (2 2 6,1.5 1.5 7,1 1 8,0.5 0.5 8,0 0 10)') AS linestring CROSS JOIN ST_GeomFromText('POLYGON((0 0 8, 0 1 8, 1 1 8, 1 0 8, 0 0 8))') AS polygon;

Bring these results as geojson and show it on your map.

  • Why st_astext() and not st_asgeojson()?
    – Iamlukesky
    Sep 22, 2017 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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