-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_kml.py
More file actions
36 lines (34 loc) · 1.3 KB
/
write_kml.py
File metadata and controls
36 lines (34 loc) · 1.3 KB
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
def make_file(county):
county_name = re.sub("/", " ", county.name)+" COUNTY"
county_geom = county.geom
os.mkdir(county_name)
os.chdir(county_name)
Consts = county.constituencies_set.all()
county_kml = county.make_kml()
county_raw = make_kml(county_kml + make_folder(Consts, "Consituencies"))
f = open(county_name+".kml", "w")
f.write(county_raw)
f.close()
for const in Consts:
const_name = re.sub("/", " ", const.name)+" CONSTITUENCY"
const_kml = const.make_kml()
os.mkdir(const_name)
os.chdir(const_name)
wards = const.wards_set.all()
const_raw = make_kml(const_kml+make_folder(wards, "Wards"))
f = open(const_name+".kml", "w")
f.write(const_raw)
f.close()
for ward in wards:
ward_kml = ward.make_kml()
ward_name = re.sub("/", " ", ward.name)+" WARD"
os.mkdir(ward_name)
os.chdir(ward_name)
stations = ward.stations_set.filter(geom__within=county_geom)
raw = make_kml(ward_kml+make_folder(stations, "Polling stations"))
f = open(ward_name+" PollingStations.kml", "w")
f.write(raw)
f.close()
os.chdir("..")
os.chdir("..")
os.chdir("..")