- 积分
- 226
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-4-23
- 最后登录
- 1970-1-1
![[用户dyk1zxttvm] 粉丝数:9 微博数:227 新浪微博达人勋](source/plugin/sina_login/img/light.png)
|
发表于 2023-3-21 23:07:10
|
显示全部楼层
您好 请教一下为什么我加了print(shape_rec.record)运行以后没有任何反映呢,还需要修改哪里吗。
import shapefile
from matplotlib.path import Path
from matplotlib.patches import PathPatch
def shp2clip(originfig,ax,m,shpfile,region):
sf = shapefile.Reader(shpfile)
vertices = []
codes = []
for shape_rec in sf.shapeRecords():
####这里需要找到和region匹配的唯一标识符,record[]中必有一项是对应的。
# if shape_rec.record[3] == region: #####在country1.shp上,对中国以外的其他国家或地区进行maskout
print(shape_rec.record)
if shape_rec.record[4] in region:#####在bou2_4p.shp上,对中国的某几个省份或地区之外的部分进行maskout
pts = shape_rec.shape.points
prt = list(shape_rec.shape.parts) + [len(pts)]
for i in range(len(prt) - 1):
for j in range(prt, prt[i+1]):
vertices.append(m(pts[j][0], pts[j][1]))
codes += [Path.MOVETO]
codes += [Path.LINETO] * (prt[i+1] - prt -2)
codes += [Path.CLOSEPOLY]
clip = Path(vertices, codes)
clip = PathPatch(clip, transform=ax.transData)
for contour in originfig.collections:
contour.set_clip_path(clip)
return clip
|
|