I have 2 shapefiles for the UK:
In [3]: # SHAPEFILE 1:
...: # WESTMINISTER PARLIAMENTARY CONSTITUENCY UK SHAPEFILE
My issue turned out to be caused by my reprojection step from OSGB to WGS 84.
# THE ORIGINAL PROJECTION ON THE SHAPEFILE
In [16]: lad19.crs
Out[16]: {'init': 'epsg:27700'}
While the result of the following command would suggest that the reprojection step worked
In [17]: lad19.crs = {'init': 'epsg:4326'}
...: lad19.crs
Out[17]: {'init': 'epsg:4326'}
if you look at the geometry attribute you can see that it is still made up of eastings and northings and not longitudes and latitudes as you would expect after reprojecting:
In [8]: lad19["geometry"].head()
Out[8]:
0 POLYGON ((448986.025 536729.674, 453194.600 53...
1 POLYGON ((451752.698 520561.900, 452424.399 52...
2 POLYGON ((451965.636 521061.756, 454348.400 52...
3 POLYGON ((451965.636 521061.756, 451752.698 52...
4 POLYGON ((419709.299 515678.298, 419162.998 51...
Name: geometry, dtype: geometry
The solution was to instead reproject from the original to the desired projection using this method, with the key part being to include inplace=True
:
In [11]: lad19.to_crs({'init': 'epsg:4326'},inplace=True)
...: lad19.crs
Out[11]: {'init': 'epsg:4326'}
The eastings and northings contained in the geometry
column have now been converted to longitudes and latitudes
In [12]: lad19["geometry"].head()
Out[12]:
0 POLYGON ((-1.24098 54.72318, -1.17615 54.69768...
1 POLYGON ((-1.20088 54.57763, -1.19055 54.57496...
2 POLYGON ((-1.19750 54.58210, -1.16017 54.60449...
3 POLYGON ((-1.19750 54.58210, -1.20088 54.57763...
4 POLYGON ((-1.69692 54.53600, -1.70526 54.54916...
Name: geometry, dtype: geometry
and now gv.Polygons can use this shapefile to successfully produce a choropleth map:
In [13]: gv.Polygons(lad19, vdims='lad19nm',
...: ).opts(tools=['hover','tap'],
...: width=450, height=600
...: )
Out[13]: :Polygons [Longitude,Latitude] (lad19nm)