Skip to main content
4 of 4
edited tags
Timeless
  • 37.6k
  • 6
  • 27
  • 48

How to overlap a geopandas dataframe with basemap?

I have a shapefile that I read as a geopandas dataframe

import geopandas as gpd
gdf = gpd.read_file('myfile.shp')
gdf.plot()

enter image description here

where gdf.crs

<Projected CRS: ESRI:54009>
Name: World_Mollweide
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: World.
- bounds: (-180.0, -90.0, 180.0, 90.0)
Coordinate Operation:
- name: World_Mollweide
- method: Mollweide
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

and gdf.total_bounds

array([-17561329.90352868,  -6732161.66088735,  17840887.22672861,
         8750122.26961274])

I would like to use basemap to plot the lat/lon grid on top of it. This is what I am doing

from mpl_toolkits.basemap import Basemap
# Create a Basemap instance with the same projection as the GeoDataFrame
map = Basemap(projection='moll', lon_0=-0, lat_0=-0, resolution='c')


# Create a figure and axis
fig, ax = plt.subplots(figsize=(10, 6))
# Plot the basemap
map.drawcoastlines()
map.drawcountries()
map.drawparallels(range(-90, 91, 30), labels=[1,0,0,0], fontsize=10)
map.drawmeridians(range(-180, 181, 60), labels=[0,0,0,1], fontsize=10)
# Plot the GeoDataFrame on top of the basemap
gdf.plot(ax=ax, color='red', markersize=5)

but this is what I get

enter image description here

emax
  • 7.2k
  • 22
  • 86
  • 153