0

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:\Users\Downloads\Countries__December_2017__Boundaries-shp\Countries__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
  • 1
    Epsg:4326 is lat/long – nmtoken Aug 25 '20 at 12:02
  • if you run, UK_map.crs what is the result? – sutan Aug 26 '20 at 6:24
1

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:\Users\x\Downloads\Countries__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...
3
  • Thank you for your answer. I was optimistic that this would solve my problem, however, I still get the same error for England. UK_map.crs gives me the same as you got and for UK_map2.crs, i.e., after re-projection, I get the correct output for EPSG: 4326. I noticed that I have geopandas 0.8.1, maybe it's worth downgrading to 0.8.0?! – Carolin Aug 27 '20 at 12:33
  • UPDATE: Downgrading did not solve the problem. – Carolin Aug 27 '20 at 12:53
  • @Carolin I am using geopandas 0.7.0. – sutan Aug 29 '20 at 5:53
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.