2017-08-25 17 views
1

私は、それぞれの行に、各行ごとに異なるAREAに対応するLon/Lat座標の配列を持つPANDAsデータフレームを持っています。私は各行の座標の配列から境界を持つポリゴンのマップされたグループを作成したいと思います。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 ']カラムで機能しました。しかし、ポリゴンをPANDAsデータフレームの別の列に基づいて塗りつぶした色にしたい場合は、 'crs = dict ...'部分を変更するだけですか? – PR102012

関連する問題