Skip to content

Commit

Permalink
fix: #114
Browse files Browse the repository at this point in the history
  • Loading branch information
Clarmy committed May 13, 2024
1 parent 442621b commit 3706cdb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cnmaps/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ def draw_maps(maps: Union[list, GeoDataFrame], ax=None, **kwargs):
2 中华人民共和国 北京市 北京市 朝阳区 区县 高德 陆地 MULTIPOLYGON (((116.55172 40.05812, 116.55132 ...
"""
if isinstance(maps, list):
geometries = [m["geometry"] for m in maps]
try:
geometries = [m["geometry"] for m in maps]
except TypeError:
geometries = maps

elif isinstance(maps, GeoDataFrame):
geometries = [m["geometry"] for _, m in maps.iterrows()]

Expand Down
29 changes: 29 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import numpy as np

from cnmaps import get_adm_maps, clip_contours_by_map, draw_maps, MapPolygon
from cnmaps.sample import load_temp
from cnmaps.sample import load_dem
from shapely.geometry import Polygon


Expand Down Expand Up @@ -35,5 +37,32 @@ def test_issue97():
os.remove("./test.png")


def test_issue114():
# https://github.com/cnmetlab/cnmaps/issues/114
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)


if __name__ == "__main__":
test_issue85()

0 comments on commit 3706cdb

Please sign in to comment.