2017-08-25 62 views
1

我有一個PANDA數據框,每行有一個Lon/Lat座標數組,每個行對應一個不同的AREA。我想創建一個帶有每行的座標陣列邊界的多邊形映射組。基於Lon/Lat座標陣列創建多邊形 - Python PANDA

的 'COORDS' 列的行看起來是這樣每個邊界座標用逗號隔開......

coords 
0 -88.12166374975578 42.13019789209025, -88.12166297898594 42.130077282796826, -88.12166229779616 42.12997073740438, -88.12165682902426 42.129114208546525, -88.12165440666122 42.12867029753218, -88.12165409167278 42.12861210461891, -88.12165078955562 42.1280072560737, -88.1216505237599 42.127958648542936, -88.12164976861018 42.127820070569165, -88.12164950156834 42.127770730347784, -88.12164936198349 42.127745113495685, -88.12164631909246 42.12698047923614, -88.12164465148149 42.126561239318384, -88.12164441208937 42.126501380826646, -88.12165535387125 42.125918676152615, -88.12165901489989 42.1257236125411, -88.12166910482216 42.125179681003004, -88.12167046792653 42.12511347549821, -88.12168153859359 42.124574951678966, -88.12169213266428 42.12405994975595, -88.12169609920953 42.123867... 
1 -88.15806483536268 42.15423929791892, -88.15734814434225 42.15424023425998, -88.15692561771552 42.15424078182948, -88.15612280604331 42.15424182229812, -88.15570230201315 42.154247060953836, -88.15537304882349 42.15424548051985, -88.15424894139665 42.15424008174756, -88.15312432528388 42.15423466567452, -88.15200516375596 42.15422926640768, -88.15075402101326 42.1542232181898, -88.15074137162432 42.15422315689777, -88.15073738857417 42.15384470168878, -88.1507388608806 42.15329655518857, -88.15074017125366 42.15246856985761, -88.15074053615406 42.15224538180373, -88.15074152744889 42.151633597914206, -88.15074252669456 42.15055197422978, -88.15074334980639 42.15033614385567, -88.15074448165737 42.15003982848825, -88.15074567060333 42.14972749019171, -88.15074611950101 42.14952766024307... 
+2

嗯,你有沒有看這個? https://stackoverflow.com/q/45874339/4909087我已經給你處理這些數據的代碼,所以從這裏開始。 –

+1

我同意@ COLDSPEED的解決方案,但要進一步說明如何製作多邊形,您也可以參考此鏈接:https://gis.stackexchange.com/questions/92754/how-can-i-group-points-to-make -polygon-via-python – Mandy8055

回答

2

使用geopandas

import geopandas as gpd, pandas as pd 
from shapely.geometry import Point, MultiPoint 

def s2g(s): 
    return gpd.GeoSeries([ 
     Point(xy) for xy in [ 
      tuple(float(x) for x in t.split()) for t in s.split(',') 
     ] 
    ], crs=dict(init='epsg:4326')) 

gs = gpd.GeoSeries(pd.concat({r: s2g(v) for r, v in df.coords.items()})) 

gs.plot() 

enter image description here

+0

因此,我將'items()'改爲'iteritems(),它對我的​​'df ['coords']列'起作用。但是,如果我想根據PANDA數據框中的另一列使多邊形成爲填充顏色,那麼我會更改'crs = dict ...'部分嗎? – PR102012