I am trying to learn how to do some error catching/avoiding in ArcPy. Here is a simplified version of what I would like to do. I would like to take some points, and then check to see if there is a line in a line feature class with a matching ID to the point, and the same thing to match each point to a polygon. If each point doesn't have a matching line and polygon, I want to skip that point and move on to the next. Can someone tell me what I'm doing wrong? Here is an example script showing how I am trying to do this:
# Import arcpy module
import sys, os, time, arcpy, smtplib
from arcpy import env
from arcpy.sa import *
env.overwriteOutput = True
env.workspace = r"D:\WorkingDirectory\Geoprocessing\Work.gdb"
PointFC = r"D:\WorkingDirectory\Geoprocessing\Work.gdb\points"
LineFC = r"D:\WorkingDirectory\Geoprocessing\Work.gdb\lines"
PolygonFC = r"D:\WorkingDirectory\Geoprocessing\Work.gdb\points"
Line_idField = arcpy.AddFieldDelimiters(LineFC, line_id)
Poly_idField = arcpy.AddFieldDelimiters(PolygonFC, poly_id)
try:
rows = arcpy.SearchCursor(PointFC)
for row in rows:
Pt_id = row.pt_id
PTpoly_id = row.poly_id
PTline_id = row.line_id
#This section if for skipping null values to help prevent crashes
arcpy.MakeFeatureLayer_management (PolygonFC, "Polylyr")
arcpy.AddJoin_management(row, "poly_id","Polylyr", "poly_id","KEEP_COMMON")
#This is where I get an error - it doesn't like the IS
PolyIDnull = Poly_idField IS NULL
arcpy.AddMessage('\nThis site does not have a polygon : ' + str(row.pt_id))
if PolyIDnull:
continue
arcpy.RemoveJoin_manaement(row, "Polylyr")
arcpy.MakeFeatureLayer_management (LineFC, "Linelyr")
arcpy.AddJoin_management(row, "line_id","Lineylyr", "line_id","KEEP_COMMON")
LineIDnull = Line_idField IS NULL
arcpy.AddMessage('\nThis site does not have a line : ' + str(row.pt_id))
if LineIDnull:
continue
arcpy.RemoveJoin_manaement(row, "Linelyr")
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))`