Shapely打印点的图片而不是坐标

2024-05-16 05:51:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个脚本,用于标识直线上最接近的点。我做了很多研究,并在shapely模块上完成了这项工作

我使用示例代码

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]

我想打印np来得到我的答案,我在内核中得到的只是一个点的图片。有人能告诉我打印坐标时遗漏了什么吗。我看到的示例打印坐标

我在用Python和spyder。我必须使用anaconda,因为我必须使用工作中的基本程序


Tags: 模块fromimport脚本示例npline标识
1条回答
网友
1楼 · 发布于 2024-05-16 05:51:09

根据official documentation这将为您提供点的坐标:

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

因此,解决办法是:

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)

相关问题 更多 >