【问题标题】:Buffer line across lon=180 causes banding geopandas matplotlib跨越 lon=180 的缓冲线导致带状 geopandas matplotlib
【发布时间】:2021-05-29 06:10:11
【问题描述】:

当地图的 central_longitude = 180; 时,我试图在 180 经度上绘制多边形几何图形;但是会出现人工条带。

有没有办法阻止 matplotlib 出现红圈所示的条带?

import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs

lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
    crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
gdf = gdf.to_crs({'init': 'epsg:3174'})
gdf['geometry'] = gdf['geometry'].buffer(90000)
gdf['route'] = 0
gdf = gdf.to_crs({'init': 'EPSG:4326'})

ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf['geometry'], crs=ccrs.PlateCarree())
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()

【问题讨论】:

  • 我用gdf['geometry'].tail(40)检查了数据,看起来很奇怪。我不知道为什么会这样。

标签: python matplotlib geopandas shapely cartopy


【解决方案1】:

epsg:3174 重新投影到EPSG:4326 会混淆跨越日期线的几何图形。您可以使用epsg:3174 直接绘制地理数据框,如下代码所示:

import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs
import numpy as np

lats = np.linspace(-75, 75, 100)
lons = np.linspace(150, 190, 100)
gdf = gpd.GeoDataFrame(
    crs=4326, geometry=gpd.points_from_xy(lons, lats)
)
# gdf2 = gdf.to_crs({'init': 'epsg:3174'})
gdf2 = gdf.to_crs(epsg=3174)
gdf2['geometry'] = gdf2['geometry'].buffer(90000)
gdf2['route'] = 0

ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=180))
ax.add_geometries(gdf2['geometry'], crs=ccrs.epsg(3174))
ax.set_extent([120, 250, -75, 75], crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, xlocs=[180])
ax.coastlines()

plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2011-08-15
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    相关资源
    最近更新 更多