【发布时间】:2021-12-06 01:25:58
【问题描述】:
在下面的代码中,我想计算一个点到多边形最近边缘的距离。如下面的结果部分所示,提供了坐标。下面发布的代码显示了我如何找到一个点的距离到多边形的最整齐的边缘。 在运行时,如下面的结果部分所示,对于给定点和几何图形,与 postgis 的距离等于 4.32797817574802,而从 geopandas 计算得到的距离为 3.8954865274727614e-05
请告诉我如何求一个点到多边形最近边的距离。
代码
poly = wkt.loads(fieldCoordinatesAsTextInWKTInEPSG25832)
pt = wkt.loads(centerPointointAsTextInWKTInEPSG25832)
print(poly.distance(pt)))
结果:
queryPostgreSQLForDistancesFromPointsToPolygon:4.32797817574802#result from postgis using st_distance operator
centerPointointAsTextInWKTInEPSG4326:POINT(6.7419520458647835 51.08427961641239)
centerPointointAsTextInWKTInEPSG25832:POINT(341849.5 5661622.5)
centerPointointAsTextInWKTInEPSG4326:POINT(6.7419520458647835 51.08427961641239)
fieldCoordinatesAsTextInWKTInEPSG25832:POLYGON ((5622486.93624152 1003060.89945681,5622079.52632924 1003170.95198635,5622126.00418918 1003781.73122161,5622444.73987453 1003694.55868486,5622486.93624152 1003060.89945681))
fieldCoordinatesAsTextInWKTInEPSG4326:POLYGON((6.741879696309871 51.08423775429969,6.742907378503366 51.08158745820981,6.746964018740842 51.08233499299334,6.746152690693346 51.08440763989611,6.741879696309871 51.08423775429969))
poly.distance(pt):3.8954865274727614e-05#result from geopandas
【问题讨论】:
-
请编辑您的问题中的代码,简化为minimal reproducible example - 任何人都应该能够复制/粘贴到文件中并不添加任何内容运行它看到与您相同的问题,因此请确保代码包含所有需要的导入和一些简单多边形的数据初始化以及显示问题的点坐标。
标签: python pandas geopandas shapely