Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

裁剪地图无法显示市级边界 #114

Closed
xq33118 opened this issue May 13, 2024 · 0 comments
Closed

裁剪地图无法显示市级边界 #114

xq33118 opened this issue May 13, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@xq33118
Copy link

xq33118 commented May 13, 2024

python版本3.11.5
代码:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cnmaps import get_adm_maps, clip_contours_by_map, draw_map
from cnmaps.sample import load_dem

lons, lats, data = load_dem()

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
map_polygon = get_adm_maps(country='中华人民共和国',province='山东省',level='市', record='all', only_polygon=True)

cs = ax.contourf(lons, lats, data,
                cmap=plt.cm.terrain,
                levels=np.linspace(-2800, data.max(), 10),
                transform=ccrs.PlateCarree())

clip_contours_by_map(cs, map_polygon)
draw_maps(map_polygon, color='black', linewidth=1)

plt.show()

报错如下:

TypeError                                 Traceback (most recent call last)
Cell In[8], line 19
     13 cs = ax.contourf(lons, lats, data,
     14                 cmap=plt.cm.terrain,
     15                 levels=np.linspace(-2800, data.max(), 10),
     16                 transform=ccrs.PlateCarree())
     18 clip_contours_by_map(cs, map_polygon)
---> 19 draw_maps(map_polygon, color='black', linewidth=1)
     21 plt.show()

File D:\anaconda3\envs\grib\Lib\site-packages\cnmaps\drawing.py:312, in draw_maps(maps, ax, **kwargs)
    290 """
    291 绘制多个地图边界
    292 
   (...)
    309     2  中华人民共和国   北京市  北京市  朝阳区  区县  高德  陆地  MULTIPOLYGON (((116.55172 40.05812, 116.55132 ...
    310 """
    311 if isinstance(maps, list):
--> 312     geometries = [m["geometry"] for m in maps]
    313 elif isinstance(maps, GeoDataFrame):
    314     geometries = [m["geometry"] for _, m in maps.iterrows()]

File D:\anaconda3\envs\grib\Lib\site-packages\cnmaps\drawing.py:312, in <listcomp>(.0)
    290 """
    291 绘制多个地图边界
    292 
   (...)
    309     2  中华人民共和国   北京市  北京市  朝阳区  区县  高德  陆地  MULTIPOLYGON (((116.55172 40.05812, 116.55132 ...
    310 """
    311 if isinstance(maps, list):
--> 312     geometries = [m["geometry"] for m in maps]
    313 elif isinstance(maps, GeoDataFrame):
    314     geometries = [m["geometry"] for _, m in maps.iterrows()]

File D:\anaconda3\envs\grib\Lib\site-packages\shapely\geometry\base.py:1011, in BaseMultipartGeometry.__getitem__(self, index)
   1006 warn(
   1007     "__getitem__ for multi-part geometries is deprecated and will be removed in "
   1008     "Shapely 2.0. Use the `geoms` property to access the constituent parts of "
   1009     "a multi-part geometry.", ShapelyDeprecationWarning, stacklevel=2)
   1010 if not self.is_empty:
-> 1011     return self.geoms[index]
   1012 else:
   1013     return ()[index]

File D:\anaconda3\envs\grib\Lib\site-packages\shapely\geometry\base.py:1113, in GeometrySequence.__getitem__(self, key)
   1111     return type(self.__p__)(res or None)
   1112 else:
-> 1113     raise TypeError("key must be an index or slice")

TypeError: key must be an index or slice

image

Clarmy added a commit that referenced this issue May 13, 2024
@Clarmy Clarmy mentioned this issue May 13, 2024
@Clarmy Clarmy self-assigned this May 13, 2024
@Clarmy Clarmy added the bug Something isn't working label May 13, 2024
@Clarmy Clarmy closed this as completed in a2c473e May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants