Skip to content

Commit

Permalink
adding ms roads scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ramSeraph committed Dec 17, 2023
0 parents commit 724f972
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions ms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
32 changes: 32 additions & 0 deletions ms/clip_roads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import csv
import json
from pathlib import Path

from shapely.geometry import shape
from shapely.prepared import prep



def load_india_shape():
data = json.loads(Path('data/india-composite.geojson').read_text())
geom = data['features'][0]['geometry']
return prep(shape(geom))


if __name__ == '__main__':
india_shape = load_india_shape()

with open(f'data/ms_roads_india.geojsonl', 'w') as outf:
with open(f'data/AsiaSouth-Full.tsv', 'r') as f:
reader = csv.reader(f, delimiter='\t')
for r in reader:
feat = json.loads(r[1])
geom = feat['geometry']
s = shape(geom)
if not india_shape.intersects(s):
continue
outf.write(r[1])
outf.write('\n')



21 changes: 21 additions & 0 deletions ms/steps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

mkdir data

wget -O data/india-composite.geojson https://raw.githubusercontent.com/datameet/maps/master/Country/india-composite.geojson

wget -O data/roads.zip https://usaminedroads.blob.core.windows.net/road-detections/AsiaSouth-Full.zip

cd data
unzip roads.zip
cd -

pip install shapely
python clip_roads.py

cat data/AsiaSouth-Full.tsv | grep "^IND" | cut -f2 > data/ms_roads_india.geojsonl

tippecanoe -P -zg -o data/ms_roads_india.mbtiles --drop-densest-as-needed --extend-zooms-if-still-dropping -l ms_roads_india -n ms_roads_india -A '<a href="https://github.com/microsoft/RoadDetections" target="_blank" rel="noopener noreferrer">MS Roads</a> - <a href="https://opendatacommons.org/licenses/odbl/" target="_blank" rel="noopener noreferrer">ODbl</a>' data/ms_roads_india.geojsonl

pmtiles convert data/ms_roads_india.mbtiles data/ms_roads_india.pmtiles

0 comments on commit 724f972

Please sign in to comment.