目标是读取 shapefile,获取每个多边形(城市)的面积,并将该面积添加到名为“面积”的新列中。
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
Run Code Online (Sandbox Code Playgroud)
当我运行时,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 线程,但没有解决方案有效。