aragon

ArcMap Draw Camera Range with ArcPy for all column

Discussion created by aragon on Oct 14, 2011
Latest reply on Jan 29, 2015 by rsiebenmann
hi,
i am working on some camera data. I have some points which consist of azimuth, angle, distance(1000 mt), and of course coordinate field attributes. In arcmap I want to draw shapes like pie chart ... i write some code inspritaions from some similar code .. but when i choose all necessity column from my shp file and make code run , i am getting error to my except point in code...





import arcpy, string, operator, math

try:
 #Collect azimuth, angle and x,y parameters
 fc = string.replace(arcpy.GetParameterAsText(0),"\\","/")
 fields = arcpy.ListFields(fc)
 descfc = arcpy.Describe(fc)
 sr = descfc.spatialReference
 azimuth = arcpy.GetParameterAsText(1)
 angle = arcpy.GetParameterAsText(2)
 x = arcpy.GetParameterAsText(3)
 y = arcpy.GetParameterAsText(4)

 #Check for output featureclass 
 outfc  = string.replace(fc, ".shp", "_range.shp")
 lstfc = string.split(fc, "/")
 for fd in lstfc:
  fn = fd
 #If existance
 if arcpy.Exists(outfc):
  arcpy.AddMessage("Deleting " + outfc)
  arcpy.Delete_management(outfc)
 #folder name
 folder = string.replace(fc, "/" + fn, "")
 arcpy.RefreshCatalog(folder)
 arcpy.env.workspace = folder
 
    #Create the feature class
 arcpy.AddMessage("Creating a polygon featureclass " + outfc)
 sf = string.replace(outfc,folder + "/", "")
 arcpy.CreateFeatureclass_management(folder, sf, "POLYGON", fc, "SAME_AS_TEMPLATE", "SAME_AS_TEMPLATE", sr)
 arcpy.RefreshCatalog(folder)

    #Open search and insert cursors
 n = 0
 insrecs = arcpy.InsertCursor(outfc)
 recs = arcpy.SearchCursor(fc)
 rec = recs.next()
 while rec:
  x = rec.getValue(x)
  y = rec.getValue(y)
  angle = rec.getValue(angle)
  azimuth = rec.getValue(azimuth)
  
  azimuth = operator.mod(azimuth, 360)
 
  if azimuth <= 90:
   azimuth = 90 - azimuth
  elif azimuth <= 360:
   azimuth = 360 - (azimuth -90)
  
  arr = arcpy.Array()
  
  azimuth1 = azimuth - (angle/2)
  azimuth2 = azimuth + (angle/2)
  azimuthSo = azimuth1
  
  arr.add(x,y)
 
  while True:
   tx = x + math.cos((math.pi/180) * azimuthSo) * 1000
   ty = y + math.sin((math.pi/180) * azimuthSo) * 1000
   point = arcpy.Point()
   point.x = tx
   point.y = ty
   arr.add(point)
   if azimuthSo >= azimuth2:
    break
   azimuthSo +=5
    
  arr.add(x,y)
  
  #arcpy.AddMessage(add)
      
  #Add feature
        insrec = insrecs.newRow()
        insrec.Shape = arr
        fld = fields.reset()
        fld = fields.next()
        while fld:
            if fld.name <> "Shape" and fld.name <> "FID":
                insrec.setValue ( fld.name, rec.getValue(fld.name))
            fld = fields.next()
        insrecs.insertRow(insrec)

        #Next records        
        n = n + 1
        rec = recs.next()    
  
  
 #arcpy.AddMessageno of features
 arcpy.RefreshCatalog(folder)
 arcpy.AddMessage("\n" + str(n) + " features stored")

 #Completion message
 arcpy.AddMessage("\n** Finished **\n")
 
except:

    #Error
    arcpy.AddMessage("\n** Error **\n")


finally:

    #Cleanup
    del arcpy
    #arcpy.AddMessage("\n** Finished **\n")
 

Outcomes