TransWikia.com

Re-projection from BNG to WSG84 consistently fails using geopandas' .to_crs

Geographic Information Systems Asked by Carolin on December 19, 2020

I am trying to use a shapefile of Great Britain to display some heatmap results on top of it. My data is in EPSG 4326 (longitude, latitude), but the shapefile is in EPSG 27700. I tried re-projecting it, but somehow this goes wrong for England. I have only just started working with geopandas (and spatial data), so maybe this is an obvious mistake.

Shapefile from https://data.gov.uk/dataset/3fd8d2d2-b591-42ff-b333-c53a6a513e96/countries-december-2017-full-clipped-boundaries-in-great-britain

Code:

import pandas as pd
import numpy as np
import geopandas as gpd

UK_map = gpd.read_file(r'C:UsersDownloadsCountries__December_2017__Boundaries-shpCountries__December_2017__Boundaries.shp')

UK_map = UK_map.to_crs(epsg=4326)

When I check UK_map with UK_map.crs and UK_map.plot() before transformation, everything seems fine.

But after transformation, England has lots of "inf" in geometry:

enter image description here

Can anyone help?

2 Answers

try assigning it to a different variable.
for instance, change UK_map = UK_map.to_crs(epsg=4326) into UK_Map2 = UK_map.to_crs(epsg=4326). This works fine to me.

>>> gdf = gpd.read_file(r"C:UsersxDownloadsCountries__December_2017__Boundaries.shp")
>>> gdf.head()
   objectid   ctry17cd  ctry17nm  ...    st_areasha    st_lengths                                           geometry
0         1  E92000001   England  ...  1.304619e+11  1.078377e+07  MULTIPOLYGON (((443836.203 113176.903, 443836....
1         2  S92000003  Scotland  ...  7.881099e+10  1.892438e+07  MULTIPOLYGON (((320364.698 976785.497, 320370....
2         3  W92000004     Wales  ...  2.078213e+10  3.082432e+06  MULTIPOLYGON (((312098.398 385255.901, 312105....

[3 rows x 11 columns]

>>> gdf.crs
<Projected CRS: EPSG:27700>
Name: OSGB 1936 / British National Grid
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: UK - Britain and UKCS 49°46'N to 61°01'N, 7°33'W to 3°33'E
- bounds: (-9.2, 49.75, 2.88, 61.14)
Coordinate Operation:
- name: British National Grid
- method: Transverse Mercator
Datum: OSGB 1936
- Ellipsoid: Airy 1830
- Prime Meridian: Greenwich

>>> gdf_transformed= gdf.to_crs(epsg=4326)
>>> gdf_transformed.head()[['ctry17nm','objectid','geometry']]
   ctry17nm  objectid                                           geometry
0   England         1  MULTIPOLYGON (((-1.37778 50.91639, -1.37777 50...
1  Scotland         2  MULTIPOLYGON (((-3.37480 58.67152, -3.37469 58...
2     Wales         3  MULTIPOLYGON (((-3.32218 53.35687, -3.32207 53...

Answered by sutan on December 19, 2020

Try explicitly setting

import os
os.environ['PROJ_NETWORK'] = 'OFF'

in the preamble as per comments to this question. This looks like it could be the same problem.

Answered by Vitaliy on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP