![Image showing reference line (red) and polyline (yellow)](https://i.stack.imgur.com/qwDK0.png)
The image shows (1) a red line which I am calling my reference line, and (2) a yellow polyline. Each line feature consists of thousands of points of x,y coordinate pairs. I would like to incrementally move along the red reference line, and calculate the orthogonal distance (with respect to the red line) to each coordinate pair point of the yellow polyline. I am working in python 3.
Here are the first 25 coordinate pairs for the red reference line:
Here are the first 25 coordinate pairs for the yellow polyline:
I have been trying a few approaches based on здесь , здесь и здесь . Я тестирую ответ, рассмотренный в последней гиперссылке , чтобы попытаться создать рабочий процесс:
import numpy as np
from shapely.geometry import LineString, Point
x1 = 457508.40746964136
x2 = 457508.5456318401
y1 = 8872649.617776532
y2 = 8872649.773129418
dist = np.sqrt((x2 - x1)**2 + (y2 - y1)**2)
centerX = (x2 - x1) / 2 + x1
centerY = (y2 - y1) / 2 + y1
test_x = centerX - dist/4
test_y = centerY + dist
line = LineString([(x1, y1), (x2, y2)])
print(list(line.coords))
p = Point(test_x,test_y)
print(list(p.coords))
print(p.distance(line))
p.distance (line) возвращает: 0,17780 ... Вот изображение того, что этот конкретный тест выглядит так:
введите описание изображения здесь * +1019 *
* * 1 021 Черные точки являются две последовательные пары координат на красной линии отсчета. Красная точка - это тестовая пара координат, которая используется для расчета ортогонального расстояния от черной точки до голубого отрезка линии. Мне кажется, что приведенный выше результат p.distance слишком короткий для ортогонального расстояния. Буду признателен за любую помощь в решении этой проблемы. Заранее спасибо.