Steps to convert boundaries shapefiles into usable common ways for adding to Openstreetmap

Posted by Answerquest on 9/15/2023

Assumptions: - You’re working with a district shapefile having village polygons, and you want to add the village boundaries to OSM. (Find+replace the terms as appropriate for your use case) - Instead of separate polygons, you want each shared boundary between say 2 villages to be loaded on JOSM as a LINE shape, so that you can add it as a Way and then include it in the respective Relations of each village - So this process will help you convert those polygons into these common boundary lines

  1. Load shapefile zip (having .shp etc) on mapshaper.org
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-1-mapshaper.webp

  2. console -> type “innerlines”, press enter. Shape changes to just the inner common boundaries
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-2-innerlines.webp

  3. export, choose shapefile format (not geojson, that’s useless). rename it to “innerlines”
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-3-mapshaper-save.webp

  4. open QGIS, load both the original shapefile and this innerlines shapefile there
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-4-qgis.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-4b-qgis.webp

  5. original shapefile : Dissolve (vector -> geoprocessing tools -> dissolve)
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-5-dissolve.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-6-dissolve.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-7-dissolved.webp

  6. On the dissolved layer: Menu -> Vector -> Geometry Tools -> Polygons to Lines
    Now we have the external boundary of the district.
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-8-poly2line.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-9-poly2line.webp

  7. Processing Toolbox -> Split with lines ::
    input layer: external boundary, split layer: innerlines
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-10-splitlines.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-11-splitlines.webp

  8. We can verify that the single outer boundary line of the district has been split up into chunks along where inner boundaries meet it, by selecting features along it. Instead of the entire line, only a few chunks get selected. https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-12-splitlines.webp

  9. Now let’s merge the inner boundaries and the split-up outer boundary layers.
    Menu -> Vector -> Data Management Tools -> Merge vector layers
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-13-merge.webp
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-14-merge.webp

  10. choose the split-up external boundary, and the innerlines layer in input field
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-15-merge.webp

  11. Set the merged output to save as file, save as a geojson. Make sure you change Destination CRS to EPSG:4326
    https://server.nikhilvj.co.in/dump/img/common-boundaries-guide/cb-16-merge.webp

  12. Now you have a .geojson file having all boundaries in neat segments that you can add directly as Way in JOSM