Skip to content Skip to sidebar Skip to footer

Gv.polygons Dataerror When Using Osgb Projection

I have 2 shapefiles for the UK: In [3]: # SHAPEFILE 1: ...: # WESTMINISTER PARLIAMENTARY CONSTITUENCY UK SHAPEFILE ...: shapefile1 = '../Westminster_Parliamentary_Constitu

Solution 1:

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.025536729.674, 453194.60053...
1    POLYGON ((451752.698520561.900, 452424.39952...
2    POLYGON ((451965.636521061.756, 454348.40052...
3    POLYGON ((451965.636521061.756, 451752.69852...
4    POLYGON ((419709.299515678.298, 419162.99851...
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.2409854.72318, -1.1761554.69768...
1    POLYGON ((-1.2008854.57763, -1.1905554.57496...
2    POLYGON ((-1.1975054.58210, -1.1601754.60449...
3    POLYGON ((-1.1975054.58210, -1.2008854.57763...
4    POLYGON ((-1.6969254.53600, -1.7052654.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)

enter image description here

Post a Comment for "Gv.polygons Dataerror When Using Osgb Projection"