I have a working map that allows users to draw polygons and lines and then draw a buffer around them (using this: https://github.com/skeate/Leaflet.buffer).

The map also has some WFS data on the geoserver side. I was wondering if leaflet has the capability of calculating the total number of miles of road data that's within the shape, or how many sq miles of polygon that are within the shape, etc.

This would serve as a rudimentary buffer analysis. The buffer would be created and then a pop-up window would come up saying "X miles of 'road.data', X sq mi of 'polygon.data' in buffer." or whichever pieces of data are elected to be included in the analysis.

I've search for a bit and I can't find anything like this.

2 Answers 2


I was wondering if leaflet has the capability of calculating the total number of miles of road data that's within the shape

The answer is "no".

Leaflet is a map display library, not a geospatial analysis toolbox. You probably want to use Turf.js for these kind of tasks.


You could use the GeoServer WPS module which is designed to process these sorts of tasks on the server to save passing all the data to the client and then stressing the client by making it think too.

Your use case is quite simple so all you need is a intersects operation, so you could post some XML like (I've used WKT as the input but you could use JSON or GML as you wish):

<?xml version="1.0" encoding="UTF-8"?><wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
        <wps:ComplexData mimeType="application/wkt"><![CDATA[Your Buffer goes here!]]></wps:ComplexData>
      <wps:Reference mimeType="text/xml; subtype=gml/2.1.2" xlink:href="Insert your WFS URL here" method="GET"/>
    <wps:RawDataOutput mimeType="application/json">

If you'd like to make life even easier you could just send the point the user clicked on and then chain a buffer process to the input of the above XML and have everything done on the server.

And before you worry about how hard it is to right correct XML files and test this stuff out GeoServer provides a request builder that uses a wizard to help you build and test requests.

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.