Skip to content

Instantly share code, notes, and snippets.

@lovemyliwu
Last active December 29, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovemyliwu/74876ab824913350d46c3a9085f6b189 to your computer and use it in GitHub Desktop.
Save lovemyliwu/74876ab824913350d46c3a9085f6b189 to your computer and use it in GitHub Desktop.
shapely 线段操作
  1. 平移
>>> line=shapely.LineString([(0,0.3), (0.3,0)])
>>> line.parallel_offset(0.13, side="right")
<LINESTRING (0.092 0.392, 0.392 0.092)>
  1. 计算弧度radian,角度angle
origin=(0,0)
point=(1,1)
radian=math.atan2(point[1]-origin[1], point[0]-origin[0])
angle=radian*180/math.pi
  1. 延长线段100长度
line=shapely.LineString([origin, point])
new_point = (origin[0]+line.length+100, origin[1])
new_line=shapely.LineString([origin, new_point])
rotate(new_line, radian, origin=origin, use_radians=True)

交换origin和point可以在另一方向延长

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment