Skip to content

Instantly share code, notes, and snippets.

@bharathkumar-gopalan
Last active January 13, 2025 13:30
Show Gist options
  • Save bharathkumar-gopalan/494c7aa1126ef1ac131a2ca328f3d5a1 to your computer and use it in GitHub Desktop.
Save bharathkumar-gopalan/494c7aa1126ef1ac131a2ca328f3d5a1 to your computer and use it in GitHub Desktop.

Disclaimer :

This gist is provided solely for educational and informational purposes. The content shared here is intended to demonstrate technical concepts and does not imply any legally binding commitments or opinions of the author.

Users are responsible for ensuring compliance with applicable laws, regulations, and standards in their respective jurisdictions. This material is shared in good faith for learning purposes only, and any misuse or misrepresentation of this information is strictly discouraged.

Stage 1 (extract the boundaries)

Step 1: Get the geojson file To begin with we need a Geojson representing the boundaries - For this example I am using the one present at https://github.com/datameet/maps/blob/b3fbbde595310b397a55d718e0958ce249a4fa1f/Country/india-soi.geojson- Download this file (Note : This file may possibly not be accurate - Please do thorough research before putting this in prod) - Replace the properties with "properties": { "name": "India", "admin_level": 2 } under the features json array

Step 2: Extract the admin boundaries- You can use mapshaper mapshaper india-osm.geojson -filter 'admin_level == 2' -lines -o boundaries.geojson - This extracts the boundaries where admin_level = 2 (Admin boundaries) - This will extract the boundaries to boundaries.geojson file

Step 3: Convert this to mbtiles using tippecanoe tippecanoe -o india_boundary.mbtiles boundaries.geojson

Step 4: Convert this mbtiles to pmtiles pmtiles convert india_boundary.mbtiles india_boundary.pmtiles

You will need to co-host this pmtiles along with the other pmtile that you have.

Stage 2 (Modify the style json file)

Host this in a server (Martin or something similar)

Step 1: Add a new source to your style spec (a.k.a style.json) file - Lets call it indiaosm

{ "indiaosm": { "type": "vector", "attribution": "<a href=\"https://github.com/protomaps/basemaps\">Protomaps</a> © <a href=\"https://openstreetmap.org\">OpenStreetMap</a>", "tiles": [ "https://<your-pm-tile-server>/path/{z}/{x}/{y}" ], "minzoom": 0, "maxzoom": 15 } }

Step 2: Update the borders with id "boundaries_country" to make sure that we ignore disputed territories

{ "id": "boundaries_country", "type": "line", "source": "protomaps", "source-layer": "boundaries", "filter": [ "all", [ "<=", "pmap:min_admin_level", 2 ], [ "!=", "disputed", true ] ], "paint": { "line-color": "#9e9e9e", "line-width": 1, "line-dasharray": [ 3, 2 ] } }

Step 3: Add a new layer that reads from indiaosm to style spec (a.k.a style.json) file

        "id": "boundaries_india",
        "type": "line",
        "source": "indiaosm",
        "source-layer": "boundaries",
        "filter": [
            "==",
            "admin_level",
            2
        ],
        "paint": {
            "line-color": "#9e9e9e", // Whatever color you want the border to be 
            "line-width": 1
        }
    }```






@devdattaT
Copy link

Only change I would suggest, is to download the official boundaries from Survey Of India's website and use those, instead of the Datameet Boundaries. The SOI boundaries are more accurate.

@bharathkumar-gopalan
Copy link
Author

Hey @devdattaT Thanks - I will update this document with the SOI boundaries when I get time , And thanks for the boundaries in Datameet , Without this the solution would not have been possible !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment