Given a series of overlapping lines (MultiLineString) in Geojson how can I create polygons for those portions that form an enclosed a space?

Sample data - https://gist.github.com/maphew/7bb77059574ea714977edae41e4b114c a grid of overlapping lines

Operational environment is web browser and/or a server with Node.js. Desktop tools such as ArcGIS and QGIS are not available. Connection to a remote service API is acceptable but prefer to avoid. (Following principle of minimizing external dependencies.)

This is my first significant foray into javascript-land, some hand-holding may be needed. ;-)

What hasn't worked

Seeing OGR DXF Closed Polyline Conversion I tried to filter the geojson through DXF to shapefile polygons using command line ogr2ogr (v2.2.0). Thinking if I could get it to work there I could replicate in . A polygon shapefile is created but it has no features. -skipfailures didn't help.

  • Related gis.stackexchange.com/questions/58245/… – matt wilkie Jun 25 '17 at 3:53
  • I suppose you had better to use a ready solution to create polygons. For example PostGIS ST_Polygonize and ST_node or GRASS GIS. – Zoltan Jun 25 '17 at 11:58
  • 1
    There is a node module - turf/linestring-to-polygon which might do the trick. If you want to do it all in the browser then You can probably implement the algorithm described here using turf. (docs). – RoperMaps Jun 26 '17 at 8:35
  • 1
    Thanks @RoperMaps. Turf/linestring-to-polyon doesn't work, but in Turf I found another module, less than 1 month old, called Turf/polygonize. It reads like it should work, but doesn't. I filed a bug, hopefully it gets fixed soon. :-) – matt wilkie Jun 27 '17 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.