在Arcgis 10中使用Python计算方位角时的语法错误

时间:2013-03-17 18:18:20

标签: python

我正在尝试使用arcgis 10中的Python计算方位角,但是我遇到了语法错误。这是我的代码:

def CalculaAzimuth(Linea):
    Xorigen = linea.firstPoint.Y
    Yorigen = linea.firstPoint.X
    Xfinal = linea.lastPoint.X
    Yfinal = linea.lastPoint.Y
    DeltaX = Xfinal - Xorigen
    DeltaY = Yfinal - Xorigen
    PI = math.pi()
    Azimuth = 4 * PI
    if DeltaX = 0:
        if DeltaY >=0:
            Azimuth = 0
        else:
            Azimuth = 180
    elif DeltaX >0:
        Azimuth = 90 - math.atan( DeltaY / DeltaX ) * 180 / PI
    elif DeltaX <0:
        Azimuth = 270 - math.atan( DeltaY / DeltaX )* 180 / PI

return Azimuth

1 个答案:

答案 0 :(得分:4)

好的,这是一个带有上述所有注释的清理版本,加上逻辑和一些变量清理的小改动。 请注意,这不是球体上的真正方位角。

def CalculaAzimuth(linea):
    if (hasattr(linea,'type') and linea.type == 'polyline'):
        xf = linea.firstPoint.X
        yf = linea.firstPoint.Y
        xl = linea.lastPoint.X
        yl = linea.lastPoint.Y
        dX = xl - xf
        dY = yl - yf
        PI = math.pi
        Azimuth = 0 #Default case, dX = 0 and dY >= 0
        if dX > 0:
            Azimuth = 90 - math.atan( dY / dX ) * 180 / PI
        elif dX < 0:
            Azimuth = 270 - math.atan( dY / dX )* 180 / PI
        elif dY < 0:
            Azimuth = 180
        return Azimuth
    else:
        return False