我有一个 shapefile,我将其读取为 geopandas 数据框
import geopandas as gpd
gdf = gpd.read_file('myfile.shp')
gdf.plot()
哪里
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
和
gdf.total_bounds
array([-17561329.90352868, -6732161.66088735, 17840887.22672861,
8750122.26961274])
我想使用
basemap
在其顶部绘制纬度/经度网格。这就是我正在做的事情
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)
但这就是我得到的
这是因为Basemap
使用的Mollweide投影的参数(即
proj-string)与您的GeoDataFrame的参数(即ESRI:54009)不同:
>>> gdf.crs.srs
'esri:54009'
>>> map.srs
'+proj=moll +R=6370997.0 +units=m +lat_0=0.0 +lon_0=0.0 +x_0=18019900...'
to_crs
之前调用 plot
(使用底图的 srs):
gdf.plot(ax=ax, color='red', markersize=5)
gdf.to_crs(map.srs).plot(ax=ax, color='red')
map
作为变量名,因为它是内置的。