Pi-Hellz

Python - Polyline Getpart method

Discussion created by Pi-Hellz on Apr 2, 2012
Latest reply on Apr 4, 2012 by kimo
Hi,

I'm trying to convert and optimize the Ianko PolylineGetAzimut function to meet our requirements and i'm having problem to extract the line with the getpart method. I'm got this error message when I run the function :
AttributeError: 'function' object has no attribute 'shape'.

Thanks you


import arcpy
import math

def polyline_Get_Azimuth(azimut):
    #try:
        
        #pGeometry = params.Geometry
    fc = "C:\Temp\Generation_Direction\Montreal_Ouest_Test2.shp"
    #fc = arcpy.GetParameterAsText(0)
    dDistance = 0.5
    desc = arcpy.Describe(fc)
        ### V?rifier si les champs Azimut et Orientation sont pr?sent
    shapefieldname = desc.ShapeFieldName 
    fieldnames =  []
    fields = arcpy.ListFields(fc)
    for field in fields :
        print("Field:       {0}".format(field.name))
            #fieldnames.format(field.name)
            #print fieldnames   
            #field = fields.next()
    if "Azimut" not in fieldnames:
        arcpy.AddField_management(fc,"Azimut","DOUBLE")
    if "Orientatio" not in fieldnames :
        arcpy.AddField_management(fc,"Orientatio","TEXT","","","1")
     
        
        ### V?rification du type de format du shapefile       
    type = desc.shapetype
    #if fc.IsEmpty:
        #return -1
        #arcpy.AddMessage("Le fichier est vide")
    #else:
            #if pGeometry.GeometryType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
    if type != "Polyline":
        arcpy.AddMessage("Le fichier n'est pas du type polygone")
            #return -1
            
         
            
     
    rows = arcpy.SearchCursor(fc)       
    pPolyline = fc
    Pi = 4 * math.tan(1)
            #pLine = ESRI.ArcGIS.Geometry.Line()
    pLine = fc.getPart(0)
    dLength = pPolyline.Length
    pPolyline.QueryTangent(0, dDistance, True, dLength, pLine)
    dAngle = pLine.Angle * 360 / (2 * Pi)
    if (dAngle < 90):
        dAngle = 90 - dAngle
    else:
        dAngle = 450 - dAngle
    return dAngle
        
      #Process the lines
    row = rows.next()

    for row in rows:
        outshape = row.shape
        row.Azimut = dAngle
        #while row:
                #if geodesic:
                    #utshape = row.shape
                    #[Orientatio,Azimut] = azimut(outshape)
                #arcpy.AddMessage('!: %s,%s'%(sdmbearing,sdmazimuth))
                #row.Orientatio = Orientatio
                #row.Azimut = Azimut
                #else:
                    #pass #map_azimuth(inrow.shape)
                #rows.updaterow(row)
                #row = rows.next()
        rows.updaterow(row)
        row = rows.next()

Outcomes