-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeojsonBuilding.py
39 lines (30 loc) · 1.3 KB
/
GeojsonBuilding.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
from FileManager import FileManager
import os
import sys
import json
class GeojsonBuilding:
def __init__(self, logger, source, geojson_builder):
self.logger = logger
self.source = source
self.builder = geojson_builder
def build(self):
fileManager = FileManager()
cities = [dir for dir in os.listdir(self.source) if os.path.isdir(os.path.join(self.source, dir))]
for city in cities:
city_path = os.path.join(self.source, city)
self.logger.info("%s ..."% city)
files = [os.path.splitext(os.path.normcase(file))[0] for file in os.listdir(city_path) if os.path.splitext(file)[1] == '.json']
for file in files:
json_file = os.path.join(city_path, "%s.json"% file)
geojson_file = os.path.join(city_path, "%s.geojson"% file)
js_geojson_file = os.path.join(city_path, "%s.js"% file)
self.logger.info("%s.json"% file)
if not os.path.isfile(geojson_file) or not os.path.isfile(js_geojson_file):
f = open(json_file, 'r')
loaded_json = json.load(f)
f.close()
loaded_geojson = self.builder.build_geojson(loaded_json)
fileManager.write_geojson(loaded_geojson, self.source, city, file)
self.logger.info(" => %s.geojson"% file)
fileManager.write_js_geojson(loaded_geojson, self.source, city, file)
self.logger.info(" => %s.js"% file)