How to merge multiple polygons to one polygon in the shapefile using openlayers and geoserver.

ie in the portal if user selects the multiple polygons in the same boundary, it has to merge as a single polygon

As shown in the figure belowenter image description here


GeoServer has an extension that provides Web Processing Service (WPS) methods. One of these is the geo:union process which will do exactly what you need.

You need to construct some XML like this:

<?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/json"><![CDATA[Some JSON Here]]></wps:ComplexData>
    <wps:RawDataOutput mimeType="application/json">

With a JSON representation of your polygons in the CDATA block and POST it to GeoServer, it will return a JSON representation of the union of the polygons you sent.

  • Thanks for your reply. Can you please send me an example code. – user46218 Oct 24 '16 at 5:43
  • that is the example code that you need, just insert your JSON and post – Ian Turton Oct 24 '16 at 7:24
  • which json data i have to post? please mention that. when user selects the multiple polygons (selection may be rectangular select or by click) it has to merge as single polygon.so please tell me which data(json) i have to post. – user46218 Nov 2 '16 at 3:53
  • the JSON that represents the selected polygons – Ian Turton Nov 2 '16 at 8:43
  • how to call this service in openlayers 3 wfs-t – veena hosur Oct 23 '17 at 9:32

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.