Geopandas - 计算 x,y 对数量的简单方法
Geopandas - Simply way to count number of x,y pairs
我有一个 geopandas 数据框:
import geopandas as gp
shp = gp.GeoDataFrame.from_file('example_file.shp')
shp.head(1)
SHAPE_LEN, SHAPE_AREA, geometry
21685 1.400 POLYGON ((-94.56994242128158 39.0135784915016, -94.56996218461458 39.01306817553366, -94.57042915800061 39.0130911485529, -94.57226806507019 39.01315884549675, -94.57342610723566 39.0132037014107, -94.57455413213843 39.01325045956409, -94.5744687494557 39.0149606326803, -94.57438658848373 39.01662549877073, -94.57429668454471 39.01829429564054, -94.57420188567131 39.01996471505225, -94.57409920172726 39.02177363299919, -94.57399716984756 39.02357145717905, -94.57389471998749 39.02537842422011, -94.57379374134878 39.02718338530785, -94.5736922385682 39.02899696762881, -94.57358427357126 39.03083007540815, -94.57347404106743 39.03265453494053, -94.5733651179229 39.03445691515196))
有没有一种简单的方法可以获取 'geometry' 字段中 x,y 坐标对的数量?像使用 len() 这样简单的事情会引发以下错误:
print (len(shp.geometry.iloc[0])) throws the following error:
TypeError: object of type 'Polygon' has no len()
是否需要转换'geometry'列的类型?
非常感谢任何帮助
获取(x,y)坐标对的数量:
import geopandas as gp
shp = gp.GeoDataFrame.from_file('example_file.shp')
def get_coord(coord):
return (coord.x, coord.y)
centroidseries = shp['geometry'].centroid
xycoords = map(get_coord, centroidseries)
或者如果您想要两个单独的 x 和 y 坐标列表:
x,y = [list(t) for t in zip(*map(get_coord, centroidseries))]
我有一个 geopandas 数据框:
import geopandas as gp
shp = gp.GeoDataFrame.from_file('example_file.shp')
shp.head(1)
SHAPE_LEN, SHAPE_AREA, geometry
21685 1.400 POLYGON ((-94.56994242128158 39.0135784915016, -94.56996218461458 39.01306817553366, -94.57042915800061 39.0130911485529, -94.57226806507019 39.01315884549675, -94.57342610723566 39.0132037014107, -94.57455413213843 39.01325045956409, -94.5744687494557 39.0149606326803, -94.57438658848373 39.01662549877073, -94.57429668454471 39.01829429564054, -94.57420188567131 39.01996471505225, -94.57409920172726 39.02177363299919, -94.57399716984756 39.02357145717905, -94.57389471998749 39.02537842422011, -94.57379374134878 39.02718338530785, -94.5736922385682 39.02899696762881, -94.57358427357126 39.03083007540815, -94.57347404106743 39.03265453494053, -94.5733651179229 39.03445691515196))
有没有一种简单的方法可以获取 'geometry' 字段中 x,y 坐标对的数量?像使用 len() 这样简单的事情会引发以下错误:
print (len(shp.geometry.iloc[0])) throws the following error:
TypeError: object of type 'Polygon' has no len()
是否需要转换'geometry'列的类型?
非常感谢任何帮助
获取(x,y)坐标对的数量:
import geopandas as gp
shp = gp.GeoDataFrame.from_file('example_file.shp')
def get_coord(coord):
return (coord.x, coord.y)
centroidseries = shp['geometry'].centroid
xycoords = map(get_coord, centroidseries)
或者如果您想要两个单独的 x 和 y 坐标列表:
x,y = [list(t) for t in zip(*map(get_coord, centroidseries))]