目标是读取shapefile,获取每个多边形的面积(市镇,并在名为'Area'的新列中添加该面积。
cs = gpd.read_file('munis.shp')
area_fd = []
area = cs['geometry'].map(lambda p: p.area / 10**6)
area_fd.append(area)
cs = cs.assign(Area = area_fd) #or cs['Area'] = area_fd
当我运行print(cs['NAME_2'].head)
时,它返回38个munis(0-38),print(area_fd)
也给出38个值。但是,当我运行代码时,它显示为ValueError: Length of values does not match length of index
。我已经查看过类似的GISSE和SO线程,但是没有解决方案。
您应该可以直接执行以下操作,