2017-05-09 25 views
0

我有一個geopandas數據幀:Geopandas - 簡單的方法來計算數x,y對

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)) 

有沒有一種簡單的方法來得到的x,y座標對在「幾何」字段中輸入金額?作爲東西使用LEN(簡單)引發以下錯誤:

print (len(shp.geometry.iloc[0])) throws the following error: 

TypeError: object of type 'Polygon' has no len() 

我需要轉換的「幾何」列的類型?

任何幫助非常讚賞

回答

1

要獲得的量(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))] 
相關問題