(LAT,LON)坐标的两个点元组之间的地质距离

发布于 2025-01-26 06:51:53 字数 776 浏览 3 评论 0原文

我一直在尝试测量地理框架(gdb ['几何'])中点之间的地理距离,并且一个特定的点,例如,b_xy。

GDB ['几何形状']是一个地质塔布酶,其中包含LON/LAT坐标的元素:

几何
点(-73.958 40.685)
点(-73.995 40.663)
点(-73.982 40.756)

,而B_xy是简单的LON/LAT/LAT坐标: (40.7572805500004,-73.985855503545917)

他声称在此示例中使用的教科书/教程给我的教授的代码是这样的:

'd2b = lambda pt:cdist:cdist: [b_xy])[0] [0]*10 #hasilnya学位/弧度 gdb ['d2tsquare'] = gdb ['几何']。to_crs(tgt_crs)

​www.section.io/eendineering-education/using-eepopy-to-to-calculate-the-distance-betance-betance-bet---------------仪表。但是,地理距离无法从元组中计算出来,只能执行单数输入。它不能接受GeodataFrame的数据。

对于一种有效的方法,我在这里不知所措。一直在考虑为此循环,但不确定从哪里开始。

I've been trying to measure geographic distance between points in a GeoDataframe (gdb['geometry']) and one specific point, let's say, b_xy.

gdb['geometry'] is a geodatabase containing tuples of lon/lat coordinates as such:

geometry
POINT (-73.958 40.685)
POINT (-73.995 40.663)
POINT (-73.982 40.756)

Whereas b_xy is a simple lon/lat coordinate:
(40.757280550000004, -73.98585503545917)

The code given to my professor from the textbook/tutorial he claims to be using for this example, is as such:

'd2b = lambda pt: cdist([(pt.x, pt.y)], [b_xy])[0][0]*10 #hasilnya degrees/radians
gdb['d2tsquare'] = gdb['geometry'].to_crs(tgt_crs)
.apply(d2b)'

which gives out a weird output that is presumably in degrees/radians, despite using a projected crs for tgt_crs

I've been trying to use this tutorial on measuring distances between two points, in meters. However, geopy.distance is unable to calculate from a tuple and can only perform singular inputs; it cannot accept data from a geodataframe.

I'm at a loss here for a method that works. Been thinking about making a loop for it but not sure where to start.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅气称霸 2025-02-02 06:51:53

这个问题被部分回答在这里。但是在这里添加一些价值是您要做的。

import geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

print (geopy.distance.geodesic(coords_1, coords_2).km)

输出为:279.35290160430094
这是公里的距离

This question is partially answered here. but to add some value here is what you want to do.

import geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

print (geopy.distance.geodesic(coords_1, coords_2).km)

Output is : 279.35290160430094
which is the distance in km

亚希 2025-02-02 06:51:53

您可以使用UTM CRS将EPSG转换为4386坐标为米,因此距离计算将是仪表。

import geopandas as gpd
import shapely.geometry
import pandas as pd
import io

gdb = gpd.GeoDataFrame(
    geometry=gpd.GeoSeries.from_wkt(
        pd.read_csv(
            io.StringIO(
                """geometry
POINT (-73.958 40.685)
POINT (-73.995 40.663)
POINT (-73.982 40.756)"""
            )
        )["geometry"],
        crs="epsg:4386",
    )
)

p = shapely.geometry.Point(
    -73.98585503545917,
    40.757280550000004,
)

gdb["distance"] = gdb.to_crs(gdb.estimate_utm_crs())["geometry"].distance(
    gpd.GeoSeries([p for _ in range(len(gdb))], crs=gdb.crs).to_crs(
        gdb.estimate_utm_crs()
    )
)

gdb
几何距离
0点(-73.958 40.685)8361.98
1点(-73.995 40.663)10494.9
2点(-73.982 40.756)355.129

You can use UTM CRS to transform epsg:4386 co-ordinates into meters so distance calculation will be meters.

import geopandas as gpd
import shapely.geometry
import pandas as pd
import io

gdb = gpd.GeoDataFrame(
    geometry=gpd.GeoSeries.from_wkt(
        pd.read_csv(
            io.StringIO(
                """geometry
POINT (-73.958 40.685)
POINT (-73.995 40.663)
POINT (-73.982 40.756)"""
            )
        )["geometry"],
        crs="epsg:4386",
    )
)

p = shapely.geometry.Point(
    -73.98585503545917,
    40.757280550000004,
)

gdb["distance"] = gdb.to_crs(gdb.estimate_utm_crs())["geometry"].distance(
    gpd.GeoSeries([p for _ in range(len(gdb))], crs=gdb.crs).to_crs(
        gdb.estimate_utm_crs()
    )
)

gdb
geometrydistance
0POINT (-73.958 40.685)8361.98
1POINT (-73.995 40.663)10494.9
2POINT (-73.982 40.756)355.129
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文