![](/img/trans.png)
[英]Use GeoPandas / Shapely to find intersection area of polygons defined by latitude and longitude coordinates
[英]Flipping longitude and latitude coordinates in GeoPandas
我正在處理緯度和經度有時被錯誤標記的數據集,我需要翻轉經度和緯度。 我能想到的最佳解決方案是使用df.geometry.x
和df.geometry.y
提取 x 和 y 坐標,創建一個新的幾何列,並使用新的幾何列重建 GeoDataFrame。 或者代碼形式:
import geopandas
from shapely.geometry import Point
gdf['coordinates'] = list(zip(gdf.geometry.y, gdf.geometry.x))
gdf['coordinates'] = gdf['coordinates'].apply(Point)
gdf= gpd.GeoDataFrame(point_data, geometry='coordinates', crs = 4326)
這非常難看,需要創建一個新列並且對於大型數據集效率不高。 有沒有更簡單的方法來翻轉 GeoSeries/ GeoDataFrame 的經緯度坐標?
您可以直接創建幾何列:
df['geometry'] = df.apply(lambda row: Point(row['y'], row['x']), axis=1)
df = gpd.GeoDataFrame(df, crs=4326)
它適用於點和多邊形:
gpd.GeoSeries(gdf['coordinates']).map(lambda polygon: shapely.ops.transform(lambda x, y: (y, x), polygon))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.