0


python使用shapely判断两条线是否相交

  • 安装shapely模块 pip install shapely

实现代码

import shapely.wkt as wkt

if __name__ =='__main__':
    line1 = wkt.loads("LINESTRING (116.23760690616871 40.17090730499467, 116.23760690616871 40.17091615348095)")
    line2 = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095)")# 判断线线是否相交print(line1.intersects(line2))# 增加0.3米的buffer, 这里0.3/100000后的单位是米
    polygon1 = line1.buffer(0.3/100000)
    polygon2 = line2.buffer(0.3/100000)# 判断线段扩展buffer后的范围是否相交print(polygon1.intersects(polygon2))

结果

False
True

在这里插入图片描述

BaseGeometry.buffer()方法参数说明

1. cap_style-----端点扩展方式

  • 1(CAP_STYLE.round) 默认,半圆形扩展
  • 2(CAP_STYLE.flat) 不扩展
  • 3(CAP_STYLE.square) 方形扩展

端点按半圆形扩展

line = wkt.loads("LINESTRING (116.23760690616871 40.17090730499467, 116.23760690616871 40.17091615348095)")
polygon = line.buffer(0.5/100000)

![在这里插入图片描述](https://img-blog.csdnimg.cn/20210702164347601.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0MTA2OTc=,size_16,color_FFFFFF,t_70

端点不扩展

line = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095)")
polygon = line.buffer(0.2/100000, cap_style=2)

在这里插入图片描述

端点按方形扩展

line = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095)")
polygon = line.buffer(0.2/100000, cap_style=3)

在这里插入图片描述

2. join_style-----折角连接方式

  • 1(JOIN_STYLE.round) 默认,圆弧连接
  • 2(JOIN_STYLE.mitre) 折角连接
  • 3(JOIN_STYLE.bevel)斜面连接

圆弧连接

line = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095, 116.23759890616871 40.17091530499467)")
polygon = line.buffer(0.2/100000, join_style=1)

在这里插入图片描述

折角连接

line = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095, 116.23759890616871 40.17091530499467)")
polygon = line.buffer(0.2/100000, join_style=2)

在这里插入图片描述

斜面连接

line = wkt.loads("LINESTRING (116.23761690616871 40.17092015348095, 116.23760690616871 40.17092015348095, 116.23759890616871 40.17091530499467)")
polygon = line.buffer(0.2/100000, join_style=3)

在这里插入图片描述

标签: python

本文转载自: https://blog.csdn.net/u010410697/article/details/118418932
版权归原作者 tumenooe 所有, 如有侵权,请联系我们删除。

“python使用shapely判断两条线是否相交”的评论:

还没有评论