diff --git a/src/geographies/district_boundaries.py b/src/geographies/district_boundaries.py index 202b16be..5b8b80cc 100644 --- a/src/geographies/district_boundaries.py +++ b/src/geographies/district_boundaries.py @@ -6,6 +6,9 @@ from src.base import Base from src.data.scout_census import ScoutCensus +WGS_84 = 4326 +BNG = 27700 + # noinspection PyUnresolvedReferences # To solve warnings for shapely methods @@ -44,11 +47,11 @@ def create_district_boundaries(self): # Uses the lat and long co-ordinates from above to create a GeoDataFrame all_points = gpd.GeoDataFrame(all_locations, geometry=gpd.points_from_xy(all_locations.long, all_locations.lat)) - all_points.crs = {"init": "epsg:4326"} + all_points.crs = f"epsg:{WGS_84}" # Converts the co-ordinate reference system into OS36 which uses # (x-y) coordinates in metres, rather than (long, lat) coordinates. - all_points = all_points.to_crs({"init": "epsg:27700"}) + all_points = all_points.to_crs(f"epsg:{BNG}") all_points.reset_index(inplace=True) self.logger.info(f"Found {len(all_points.index)} different Section points") @@ -102,10 +105,10 @@ def create_district_boundaries(self): data_df = gpd.GeoDataFrame(data, columns=output_columns, geometry=[district_polygon]) output_gpd = gpd.GeoDataFrame(pd.concat([output_gpd, data_df], axis=0, sort=False)) - output_gpd.crs = {"init": "epsg:27700"} + output_gpd.crs = f"epsg:{BNG}" # Convert co-ordinates back to WGS84, which uses latitude and longitude - output_gpd = output_gpd.to_crs({"init": "epsg:4326"}) + output_gpd = output_gpd.to_crs(f"epsg:{WGS_84}") output_gpd.reset_index(drop=True, inplace=True) self.logger.debug(f"output gpd\n{output_gpd}") diff --git a/src/geographies/geography.py b/src/geographies/geography.py index bdccbf36..0033c942 100644 --- a/src/geographies/geography.py +++ b/src/geographies/geography.py @@ -11,6 +11,9 @@ from src.data.ons_pd import ONSPostcodeDirectory from src.data.scout_data import ScoutData +WGS_84 = 4326 +BNG = 27700 + # noinspection PyUnresolvedReferences class Geography(Base): @@ -177,8 +180,8 @@ def filter_boundaries_near_scout_area(self, scout_data: ScoutData, boundary: str # Pivots the co-ordinate reference system into OS36 which uses # (x-y) coordinates in metres, rather than (long, lat) coordinates. - data_with_points.crs = {"init": "epsg:4326"} - data_with_points = data_with_points.to_crs({"init": "epsg:27700"}) + data_with_points.crs = f"epsg:{WGS_84}" + data_with_points = data_with_points.to_crs(f"epsg:{BNG}") # TODO work out way to avoid co-ordinate pivot (i.e. convert 3km into GPS co-ordinates) self.logger.info(f"Filters for records that satisfy {field} in {value_list}") diff --git a/src/maps/map.py b/src/maps/map.py index d1f4c7bf..fe04439e 100644 --- a/src/maps/map.py +++ b/src/maps/map.py @@ -15,6 +15,8 @@ from typing import Dict, Union +WGS_84 = 4326 + class Map(Base): def __init__(self, scout_data_object: ScoutData, map_name: str): @@ -275,15 +277,15 @@ def add_custom_data(self, csv_file_path: Path, layer_name: str, location_cols, m # Merge with ONS Postcode Directory to obtain dataframe with lat/long ons_pd_data = self.scout_data.ons_pd.data custom_data = pd.merge(custom_data, ons_pd_data, how="left", left_on=location_cols, right_index=True, sort=False) - location_cols = {"crs": 4326, "x": "long", "y": "lat"} + location_cols = {"crs": WGS_84, "x": "long", "y": "lat"} # Create geo data frame with points generated from lat/long or OS custom_data = gpd.GeoDataFrame(custom_data, geometry=gpd.points_from_xy(x=custom_data[location_cols["x"]], y=custom_data[location_cols["y"]]),) # Convert the 'Co-ordinate reference system' (crs) to WGS_84 (i.e. lat/long) if not already - if location_cols["crs"] != 4326: - custom_data.crs = {"init": f"epsg:{location_cols['crs']}"} - custom_data = custom_data.to_crs({"init": "epsg:4326"}) + if location_cols["crs"] != WGS_84: + custom_data.crs = f"epsg:{location_cols['crs']}" + custom_data = custom_data.to_crs(f"epsg:{WGS_84}") self._map_plotter.add_layer(layer_name, markers_clustered) diff --git a/src/maps/map_plotter.py b/src/maps/map_plotter.py index a7d199bf..5be52956 100644 --- a/src/maps/map_plotter.py +++ b/src/maps/map_plotter.py @@ -16,7 +16,7 @@ # WGS_84 (World Geodetic System 1984) is a system for global positioning used in GPS. # It is used by folium to plot the data. -WGS_84 = "4326" +WGS_84 = 4326 class MapPlotter(Base): @@ -114,7 +114,7 @@ def _filter_shape_file(self, shape_file_path: Path): self.logger.info(f"Resulting in {len(all_shapes.index)} shapes") # Covert shape file to world co-ordinates - self.geo_data = all_shapes.to_crs({"init": f"epsg:{WGS_84}"}) + self.geo_data = all_shapes.to_crs(f"epsg:{WGS_84}") # self.logger.debug(f"geo_data\n{self.geo_data}") def add_areas(self, name: str, show: bool, boundary_name: str, colourmap: colormap.ColorMap):