In the Site I am building a user can login and view a map that shows the Region under him (a GeoJSON layer). The user need to split this region into a number of subregions and assign it to some other users(sub users under him)to take care of the operations in that subregion and can view the map of that subregion when he logins. I want to add a page with map of the region under him to edit and split the region (the GeoJSON layer) into subregions and save those region layer data (as geojson data preferably) in DB to reassign. I tried Openlayers 3 and Google Maps javascript APIs and briefly went through leafletjs. But all of them does not seem to offer an option to divide a GeoJSON Layer into multiple layers (only draw and and reshape).

How can I achieve this?


There is a somehow "easy" solution using Turf.js:

  1. Duplicate the polygon you want to split.
  2. Edit one of them (e.g. using Leaflet.draw plugin).
  3. Once the edited polygon represents one of the "sub-regions", use turf.difference to exclude that sub-region from the initial region (i.e. the previously unchanged polygon).
  4. Start again from step 1 using the remaining "region" until it is split in all its child sub-regions.
  • Seems to be a brilliant solution ! Is it possible in Leaflet.draw or Leaflet.pm to split a polygon using a polyline.? – Johnson Jul 12 '17 at 11:42

To have a regions file, and every region is cut up into a sub-region. You basically need two different files. My sub-regions file also has a field showing it's region. If I use it as a region when I select it, I only get the sub-region. If I use the Region file and select on it I get the entire region.

If it was me, I'd save the regions file as a GeoJSON file, load it into QGIS, cut it up into sub_regions save that as a new GeoJSON file. Now just use each file in Leaflet as 2 different layers.

Basically since your assigning to sub-regions that's the file you will edit. You can put the GeoJSON into a database for the edits, or in my case I keep it as a GeoJSON file and link it to a database by the sub-region ID using a REST service and JavaScript.

  • is it possible to load regions file in the page and then allow the Gui user to split or divide it creating 2 new geoJSON layers. Not from any external software. Just like how you give draw option on map – Johnson Jul 11 '17 at 13:07
  • Ok, short answer is yes it can be done, however the method I found to do it would be using the spatial components of a database and using a query. So if my data was in sql-server I could use GeoJSON to draw the polyon in Leaflet. I would take something like the draw tool and capture it's coordinates and then use it for a new query on my database.(technicalitiesblog.blogspot.com/2010/03/…). I believe Oracle and PostGIS would be similar. So yes it can be done but not very easily. – Bill Chappell Jul 11 '17 at 13:36

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.