-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_footprints.py
59 lines (48 loc) · 1.46 KB
/
add_footprints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
A script for downloading building footprints and other useful shapefiles.
"""
import wget
import zipfile
import os
import shutil
import argparse
DATA_DIR = 'cycsat/data/'
TEMP_DIR = 'cycsat/data/footprints_temp/'
SHAPE_DIR = DATA_DIR + 'footprints/'
if not os.path.isdir(DATA_DIR):
os.mkdir(DATA_DIR)
if not os.path.isdir(SHAPE_DIR):
os.mkdir(SHAPE_DIR)
def reset_dir(DIR):
if os.path.isdir(DIR):
shutil.rmtree(DIR)
os.mkdir(DIR)
def get_dataset(dataset_url):
print('Downloading {} footprint shapefiles'.format(dataset_url))
reset_dir(TEMP_DIR)
url = 'http://download.geofabrik.de/{}-latest-free.shp.zip'.format(
dataset_url)
filename = DATA_DIR + 'footprints_temp.zip'
filename = wget.download(url, filename)
print('')
print('Unpacking...')
zip_ref = zipfile.ZipFile(filename, 'r')
zip_ref.extractall(TEMP_DIR)
zip_ref.close()
os.remove(filename)
for f in os.listdir(TEMP_DIR):
if 'gis.osm_buildings_a_free_1' in f:
filename, ext = os.path.splitext(f)
shutil.copyfile(TEMP_DIR + f, SHAPE_DIR +
dataset_url.replace('/', '-') + ext)
shutil.rmtree(TEMP_DIR)
def main(args):
if args.wipe:
reset_dir(SHAPE_DIR)
get_dataset(args.ds)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--ds')
parser.add_argument('--wipe', default=False)
args = parser.parse_args()
main(args)