Dum*_*urr 6 distance geopandas
我有两点如下。我需要以米为单位获得它们之间的距离。
POINT (80.99456 7.86795)
POINT (80.97454 7.872174)
Run Code Online (Sandbox Code Playgroud)
如何通过 GeoPandas 做到这一点?
小智 8
你点在经度,纬度坐标系(EPSG:4326或WGS 84)。要计算以米为单位的距离,您需要使用大圆距离或将它们投影到局部坐标系中以高精度近似距离。
对于斯里兰卡,您可以使用EPSG:5234,而在 GeoPandas 中,您可以使用两个 GeoDataFrame 之间的距离函数。
from shapely.geometry import Point
import geopandas as gpd
pnt1 = Point(80.99456, 7.86795)
pnt2 = Point(80.97454, 7.872174)
points_df = gpd.GeoDataFrame({'geometry': [pnt1, pnt2]}, crs='EPSG:4326')
points_df = points_df.to_crs('EPSG:5234')
points_df2 = points_df.shift() #We shift the dataframe by 1 to align pnt1 with pnt2
points_df.distance(points_df2)
Run Code Online (Sandbox Code Playgroud)
结果应该是 2261.92843 m