获取GeoPandas中两点之间的距离 [英] Get Distance Between Two Points in GeoPandas

查看:271
本文介绍了获取GeoPandas中两点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两点.我需要得到它们之间的距离,以米为单位.

I have two points as below. I need to get the distance between them in meters.

POINT (80.99456 7.86795)
POINT (80.97454 7.872174)

如何通过GeoPandas完成此操作?

How can this be done via GeoPandas?

推荐答案

您的点位于经纬度坐标系中(EPSG:4326或WGS 84).要计算以米为单位的距离,您需要使用大圆距离或将它们投影到局部坐标系中以精确地估计距离.

Your points are in a lon, lat coordinate system (EPSG:4326 or WGS 84). To calculate a distance in meters, you would need to either use the Great-circle distance or project them in a local coordinate system to approximate the distance with a good precision.

对于斯里兰卡,您可以使用 EPSG:5234 ;在GeoPandas中,您可以使用两个GeoDataFrames.

For Sri Lanka, you can use EPSG:5234 and in GeoPandas, you can use the distance function between two GeoDataFrames.

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)

结果应该是2261.92843 m

The result should be 2261.92843 m

这篇关于获取GeoPandas中两点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆