【问题标题】:Flipping longitude and latitude coordinates in GeoPandas在 GeoPandas 中翻转经纬度坐标
【发布时间】:2018-07-16 21:43:41
【问题描述】:

我正在处理纬度和经度有时被错误标记的数据集,我需要翻转经度和纬度。我能想出的最佳解决方案是使用df.geometry.xdf.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 的经纬度坐标?

【问题讨论】:

  • 我认为没有更简单的方法,我认为您所拥有的超出了明智的解决方案。

标签: python python-3.x latitude-longitude shapely geopandas


【解决方案1】:

您可以直接创建几何列:

df['geometry'] = df.apply(lambda row: Point(row['y'], row['x']), axis=1)
df = gpd.GeoDataFrame(df, crs=4326)

【讨论】:

    【解决方案2】:

    它适用于点和多边形:

    gpd.GeoSeries(gdf['coordinates']).map(lambda polygon: shapely.ops.transform(lambda x, y: (y, x), polygon))
    

    【讨论】:

      猜你喜欢
      • 2021-05-23
      • 1970-01-01
      • 2011-12-05
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 2019-11-18
      相关资源
      最近更新 更多