簡體   English   中英

基於Lon / Lat坐標數組創建多邊形進行映射-Python PANDA

[英]Create Polygons for Mapping based on array of Lon/Lat Coordinates--Python PANDAs

我有一個PANDAs數據幀,每行中都有一個Lon / Lat坐標數組,每行對應一個不同的AREA。 我想創建一個多邊形映射的組,其邊界來自每一行的坐標數組。

'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...

使用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()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM