Reputation: 39
I have a shapefile on a train track going through the UK and want to plot it to see through where it is going
I have read this from the geopandas documentation and applied the same code: https://geopandas.org/gallery/create_geopandas_from_pandas.html#sphx-glr-gallery-create-geopandas-from-pandas-py
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
#world = world.to_crs({'init': 'epsg:3857'})
# We restrict to the UK
nation = world[world.name == 'United Kingdom']
ax = nation.plot(
color='white', edgecolor='black', figsize=(10, 10), alpha=0)
#ctx.add_basemap(ax)
# We can now plot our ``GeoDataFrame``.
shp.plot(ax=ax, color='red')
plt.show()
shp is the .SHP shape file I've uploaded onto Python and gpd is short for geopandas
Unlike the example in the documentation, I can't see any borders and so have no sense of where the shape is
Some of the commented code is for adding a background to plots:
world = world.to_crs({'init': 'epsg:3857'})
ctx.add_basemap(ax)
This produces an output like this:
Totally opposite problem - can see the borders but not the shape. Also in case you're thinking perhaps the problem is that the shape isn't on the UK, when I plot the whole world I still don't see the shape.
Upvotes: 0
Views: 838
Reputation: 7804
Your shp
has a different CRS than world
. You can check that as shp.crs
and world.crs
. If you want to plot both at the same figure, you need to re-project one to the projection of the other.
world = world.to_crs(shp.crs)
Upvotes: 1