-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_dataset.py
150 lines (112 loc) · 4.65 KB
/
clean_dataset.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#%%
from pathlib import Path
import geopandas as gpd
from LBLWebAssets.create_static_assets import CreateAssets
import os
import pandas as pd
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
raw = Path('data/raw')
static_asset_path = Path('static_assets')
#%%
lbl_boundaries = raw.joinpath('lbl_wd22_full_shp/lbl_wd22_full.shp')
gdf = gpd.read_file(lbl_boundaries)
#%%
print(gdf)
lbl = gdf.dissolve(by='LAD22NM')
print(lbl)
#%%
lbl.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(lbl)
asset.output_static_files(Path('council boundary/geojson/lewisham.geojson'), bypass=True)
asset.output_static_files(Path('council boundary/shapefile/lewisham.shp'))
asset.output_static_files(Path('council boundary/json/lewisham.json'), bypass=True)
# %%
wards = []
for ward in list(gdf['WD22NM'].unique()):
ward_poly = gdf[gdf['WD22NM'] == ward]
ward_poly = ward_poly.dissolve(by='WD22NM')
wards.append(ward_poly)
ward_geo = pd.concat(wards)
ward_geo = gpd.GeoDataFrame(ward_geo, geometry='geometry')
ward_geo.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(ward_geo)
asset.output_static_files(Path(f'ward boundaries/geojsons/wards_2022.geojson'), bypass=True)
asset.output_static_files(Path(f'ward boundaries/shapefiles/wards_2022.shp'))
asset.output_static_files(Path(f'ward boundaries/json/wards_2022.json'))
# %%
lbl_lsoas = raw.joinpath('Lewisham LSOAs/lsoas.shp')
lsoas_gdf = gpd.read_file(lbl_lsoas)
lsoa_poly = lsoas_gdf.dissolve(by='LSOA21NM')
#%%
print(lsoa_poly.crs)
print(lsoa_poly)
lsoa_poly.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(lsoa_poly)
asset.output_static_files(Path(f'lsoa boundaries/geojsons/lsoas.geojson'), bypass=True)
asset.output_static_files(Path(f'lsoa boundaries/shapefiles/lsoas.shp'))
asset.output_static_files(Path(f'lsoa boundaries/json/lsoas.json'))
# %%
lbl_oas = raw.joinpath('Lewisham OAs/lewisham oas.shp')
oas_gdf = gpd.read_file(lbl_oas)
oa_poly = oas_gdf.dissolve(by='OA21CD')
#%%
print(oa_poly.crs)
print(oa_poly)
oa_poly.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(oa_poly)
asset.output_static_files(Path(f'oa boundaries/geojsons/oas.geojson'), bypass=True)
asset.output_static_files(Path(f'oa boundaries/shapefiles/oas.shp'))
asset.output_static_files(Path(f'oa boundaries/json/oas.json'))
# %%
lbl_oas = raw.joinpath('Lewisham 2011 OAs/OA 2011.shp')
oas_gdf = gpd.read_file(lbl_oas)
oa_poly = oas_gdf.dissolve(by='OA11CD')
oa_poly.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(oa_poly)
asset.output_static_files(Path(f'oa 2011 boundaries/geojsons/oas.geojson'), bypass=True)
asset.output_static_files(Path(f'oa 2011 boundaries/shapefiles/oas.shp'))
asset.output_static_files(Path(f'oa 2011 boundaries/json/oas.json'))
# %%
lbl_lsoas = raw.joinpath('Lewisham 2011 LSOAs/lsoa 2011.shp')
lsoas_gdf = gpd.read_file(lbl_lsoas)
lsoa_poly = lsoas_gdf.dissolve(by='LSOA11NM')
#%%
print(lsoa_poly.crs)
print(lsoa_poly)
lsoa_poly.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(lsoa_poly)
asset.output_static_files(Path(f'lsoa 2011 boundaries/geojsons/lsoas.geojson'), bypass=True)
asset.output_static_files(Path(f'lsoa 2011 boundaries/shapefiles/lsoas.shp'))
asset.output_static_files(Path(f'lsoa 2011 boundaries/json/lsoas.json'))
# %%
lbl_msoas_2011 = raw.joinpath('Lewisham 2011 MSOAs/MSOA_2011_EW_BFC_V3.shp')
msoas__2011_gdf = gpd.read_file(lbl_msoas_2011)
msoa_poly_2011 = msoas__2011_gdf.dissolve(by='MSOA11NM')
#%%
print(msoa_poly_2011.crs)
print(msoa_poly_2011)
msoa_poly_2011.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(msoa_poly_2011)
asset.output_static_files(Path(f'msoa 2011 boundaries/geojsons/msoas.geojson'), bypass=True)
asset.output_static_files(Path(f'msoa 2011 boundaries/shapefiles/msoas.shp'))
asset.output_static_files(Path(f'msoa 2011 boundaries/json/msoas.json'))
# %%
lbl_msoas = raw.joinpath('Lewisham MSOAs/MSOA_2021_EW_BFC_V6.shp')
msoas_gdf = gpd.read_file(lbl_msoas)
msoa_poly = msoas_gdf.dissolve(by='MSOA21NM')
#%%
print(msoa_poly.crs)
print(msoa_poly)
msoa_poly.reset_index(inplace=True)
asset = CreateAssets(static_asset_path=static_asset_path)
asset.assets_from_geopandas(msoa_poly)
asset.output_static_files(Path(f'msoa boundaries/geojsons/msoas.geojson'), bypass=True)
asset.output_static_files(Path(f'msoa boundaries/json/msoas.json'))
#%%