首页 文章

使用python将lat lon几何投影到utm

提问于
浏览
0

我有一个名为eq的地震数据的数据框,其中包含列出纬度和经度的列 . 使用geopandas我创建了一个点列,其中包含以下内容:

from geopandas import GeoSeries, GeoDataFrame
from shapely.geometry import Point
s = GeoSeries([Point(x,y) for x, y in zip(df['longitude'], df['latitude'])])
eq['geometry'] = s
eq.crs = {'init': 'epsg:4326', 'no_defs': True}
eq

现在我有一个带有lat lon坐标的几何列,但我想将投影更改为UTM . 任何人都可以帮助改造吗?

1 回答

  • 2

    纬度/经度不是真正的投影,而是一种默认的"unprojection" . 请参阅this page for more details,但这可能意味着您的数据使用 WGS84epsg:4326 .

    设's build a dataset and, before we do any reprojection, we' ll将 crs 定义为 epsg:4326

    import geopandas as gpd
    import pandas as pd
    from shapely.geometry import Point
    df = pd.DataFrame({'id': [1, 2, 3], 'population' : [2, 3, 10], 'longitude': [-80.2, -80.11, -81.0], 'latitude': [11.1, 11.1345, 11.2]})
    s = gpd.GeoSeries([Point(x,y) for x, y in zip(df['longitude'], df['latitude'])])
    
    geo_df = gpd.GeoDataFrame(df[['id', 'population']], geometry=s)
    # Define crs for our geodataframe:
    geo_df.crs = {'init': 'epsg:4326'}
    

    我不确定你的意思"UTM projection" . 从wikipedia page我看到有60种不同的UTM投影取决于世界的面积 . 你可以在网上找到合适的 epsg 代码,但我只想给你一个随机 epsg 代码的例子 . This is the one for zone 33N for example

    怎么做重投影?您可以轻松地从the geopandas docs on projection获取此信息 . 这只是一行:

    geo_df = geo_df.to_crs({'init': 'epsg:3395'})
    

    并且几何体不再编码为纬度/经度:

    id  population  geometry
    0   1   2   POINT (-8927823.161620541 1235228.11420853)
    1   2   3   POINT (-8917804.407449147 1239116.84994171)
    2   3   10  POINT (-9016878.754255159 1246501.097746004)
    

相关问题