12
12
13
13
14
14
def edit_boundary_resolution (
15
- study_area : gpd .GeoDataFrame , geography : str
15
+ study_area : gpd .GeoDataFrame , geography : str , zone_id : str
16
16
) -> gpd .GeoDataFrame :
17
17
"""
18
18
This function takes a GeoDataFrame and a geography resolution as input and returns
@@ -26,6 +26,8 @@ def edit_boundary_resolution(
26
26
A GeoDataFrame containing the study area boundaries
27
27
geography : str
28
28
A string specifying the geography resolution. It can be either "OA" or "MSOA"
29
+ zone_id : str
30
+ The column name of the zone identifier in the study_area GeoDataFrame
29
31
30
32
Returns
31
33
-------
@@ -36,20 +38,16 @@ def edit_boundary_resolution(
36
38
# Dissolve based on the specified geography
37
39
if geography == "MSOA" :
38
40
# Drop unnecessary columns (they are lower level than MSOA)
39
- columns_to_drop = ["GlobalID" , "OA21CD" , "LSOA21CD" , "LSOA21NM" ]
40
- study_area = study_area .drop (
41
- columns = [col for col in columns_to_drop if col in study_area .columns ]
42
- )
41
+ study_area = study_area [[zone_id , "geometry" ]]
43
42
44
43
print ("converting from OA to MSOA" )
45
44
study_area = study_area .dissolve (by = "MSOA21CD" ).reset_index ()
46
45
47
46
elif geography == "OA" :
48
47
# Drop unnecessary columns
49
- columns_to_drop = ["GlobalID" ]
50
- study_area = study_area .drop (
51
- columns = [col for col in columns_to_drop if col in study_area .columns ]
52
- )
48
+ study_area = study_area [
49
+ [zone_id , "MSOA21CD" , "geometry" ]
50
+ ] # we always need MSOA21CD to filter to study area
53
51
print ("keeping original OA boundaries" )
54
52
55
53
# Ensure all geometries are MultiPolygon
0 commit comments