簡體   English   中英

如何在 python 中找到離坐標最近的 LineString 點

[英]How to find closest point of LineString to a coordinate in python

我有以下代碼...

import osmnx as ox
latitude = 51.217220
longitude = 4.418535

p = ox.Point(latitude, longitude)
line = ox.LineString([(4.4203843 , 51.2154117), (4.420431, 51.2159018), (4.4204697, 51.2163913), (4.4204833, 51.2166588),  (4.4204243, 51.2168076), (4.4203641, 51.2169564), (4.4203409, 51.2170063), (4.4202929 ,51.2171074), (4.4202355 ,51.2171806), (4.420205, 51.2172067), (4.4201654, 51.2172246), (4.4201077 ,51.2172411), (4.4200562 ,51.2172511), (4.4194807 ,51.217338), (4.4190475 ,51.2174025), (4.4179023 ,51.2175729), (4.4178548 ,51.21758), (4.4177154 ,51.2176008)])
np = nearest_points(line, p)[0]
print(np)

然而output變成

點 (4.4203843 51.2154117)

這顯然不是離我這個 LineString 點最近的點。 我究竟做錯了什么?

什么是nearest_points 您的代碼片段不可重現,但這是一個很好的猜測:您的 LineString 中的坐標表示為(經度,緯度),但您的點表示為(緯度,經度)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM