【问题标题】:pint: convert geographic CRS degrees to nautical milespint:将地理 CRS 度数转换为海里
【发布时间】:2021-12-11 03:52:00
【问题描述】:

我想使用品脱将度数(地理 CRS 中的距离)转换为海里。

https://geopandas.org/docs/reference/api/geopandas.GeoDataFrame.sjoin_nearest.html 以度为单位输出 epsg:4326 的距离。

鉴于赤道到两极的距离(以纳米为单位)不同,我不确定这是否可行。

我可以使用 1 度 ~= 111 公里 ~= 60 海里的经验法则。

也许可以使用起点和距离来计算,例如:https://github.com/anitagraser/movingpandas/blob/master/movingpandas/geometry_utils.py#L38

这段代码也很有用:https://geopy.readthedocs.io/en/stable/#module-geopy.distance

这里有一些代码要测试:

import pandas as pd
import geopandas as gpd

df = pd.DataFrame({"lon": [0], "lat": [0]})
gdf_pt = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df["lon"], df["lat"]), crs="epsg:4326")

df2 = pd.DataFrame({"lon": [1, 2], "lat": [0, 0]})
gdf_pts = gpd.GeoDataFrame(df2, geometry=gpd.points_from_xy(df2["lon"], df2["lat"]), crs="epsg:4326")

value = gdf_pt.sjoin_nearest(gdf_pts, distance_col="distances")["distances"].values[0]


import pint

l = value * ureg.arcdegree

【问题讨论】:

标签: python geopandas pint


【解决方案1】:

如果可以的话,最好把它扔给墨卡托并使用它

import pint_pandas

gdf = gdf_pt.to_crs("EPSG:3395").sjoin_nearest(gdf_pts.to_crs("EPSG:3395"), distance_col="distances")
gdf["distance"] = gdf["distance"].astype("pint[meter]").pint.to("nautical_mile")

【讨论】:

    【解决方案2】:

    我从现有代码中提取的这个函数计算两个纬度/经度集之间的距离(以米为单位)。 “rlat”和“rlong”以弧度表示;您必须从度数进行转换。要获取 nm 而不是米,只需将 R 设置为 3440。

    from math import *
    
    # Radius of the earth, in meters.
    
    R = 6371000
    
    # Return distance between two lat/longs.
    
    def distance( pt1, pt2 ):
        rlat1 = pt1.rlat
        rlat2 = pt2.rlat
        dlat = pt2.rlat - pt1.rlat
        dlong = pt2.rlong - pt1.rlong
    
        a = sin(dlat/2) * sin(dlat/2) + cos(rlat1) * cos(rlat2) * sin(dlong/2) * sin(dlong/2)
        c = 2 * atan2(sqrt(a), sqrt(1-a))
        return R * c
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多