# 优化主线点集
def initPolyline(oldArr, L):
newArr = arcpy.CreateObject("Array")
if len(oldArr) < 2:
return oldArr
# 加入起始辅助点
newArr.add(arcpy.Point(oldArr[0].X * 2 - oldArr[1].X, oldArr[0].Y * 2 - oldArr[1].Y))
for i in range(len(oldArr)):
newArr.add(oldArr[i])
# 加入结尾辅助点
newArr.add(arcpy.Point(oldArr[len(oldArr) - 1].X * 2 - oldArr[len(oldArr) - 2].X,
oldArr[len(oldArr) - 1].Y * 2 - oldArr[len(oldArr) - 2].Y))
newArr.add(oldArr[len(oldArr) - 1])
return newArr
def getParallelPoint(p0, p1, p2, Distance):
a=0
b=0
y12 = p2.X - p1.X
x12 = p2.Y - p1.Y
y01 = p1.X - p0.X
x01 = p1.Y - p0.Y
if x12 == 0:
a = math.pi / 2
if y12 < 0:
a = -a
else:
a = math.atan(y12 / x12)
if x01 == 0:
b = math.pi / 2
if y01 < 0:
b = -b
else:
b = math.atan(y01 / x01)
#关键核心处
if p2.Y < p1.Y:
a += math.pi
if p1.Y < p0.Y:
b += math.pi
k = (b - a - math.pi) / 2
r = a + k
d = Distance / math.sin(k)
sinr = math.sin(r)
cosr = math.cos(r)
d_lat = d * sinr
d_lng = d * cosr
return [d_lat, d_lng]
python折线平行算法
最新推荐文章于 2024-06-19 21:44:09 发布