-1

I am trying to create a script that identifies the closest point on a line to point. I did a lot of research and landed on the shapely module to complete this.

I use the example code

from shapely.geometry import Point, LineString
from shapely.ops import nearest_points
line = LineString([(0, 0), (1, 1), (2, 2)])
point = Point(0.3, 0.7)
np = nearest_points(line, point)[0]

I want to print np to get my answer and all I get get in my kernel is a picture of a dot. Can someone tell me what I am missing to print out the coordinate. The examples I see print the coordinates.

I am using anaconda with spyder. I do have to use anaconda due to the base program at work I have to use.

soMario
  • 22,501
  • 7
  • 19
  • 38
Jake
  • 143
  • 4
  • 13

1 Answers1

0

According to the official documentation this will give you the coordinates of the points:

p1,p2 = nearest_points(line, point)
print(p1.wkt,p2.wkt)

Therefore, the solution would be:

from shapely.geometry import Point, LineString
from shapely.ops import nearest_points
line = LineString([(0, 0), (1, 1), (2, 2)])
p1,p2 = nearest_points(line, point)
print(p1.wkt,p2.wkt)
soMario
  • 22,501
  • 7
  • 19
  • 38