实现代码
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
1. cap_style-----端点扩展方式
line = wkt.loads("LINESTRING (116.23760690616871 40.17090730499467, 116.23760690616871 40.17091615348095)")
polygon = line.buffer(0.5/100000)
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-----折角连接方式
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)