I'm pretty new to ArcPy and Python.
In our database, we have a layer containing parcels (polygons) with a neighborhood code and a polygon layer that contains the neighborhood boundary. Within that parcel layer, we have some errors where the neighborhood that the parcel should be in is not. I'm trying to attempt a way to compare each parcel and see if it falls within the neighborhood boundary that it's assigned. An example would be if this parcel is assigned to neighborhood 1, and falls within the boundary of neighborhood 1. If the neighborhood boundary does not match up, I would like that selected so it can be analyzed further. This is what I have so far as my ArcPy code.
I got a runtime error when it could not find the column, but I'm also unsure if a search cursor is what I need. I tried a join using the standard GIS tool, but it didn't return what I needed. I used column 29 because that is the one that contains the neighborhood code, same for column 3.
# Name: ExtractFeaturesByLocationAndAttribute.py # Description: Extract features to a new feature class based on a spatial # relationships to another layer, and an attribute query # Import system modules import arcpy # Set the workspace arcpy.env.workspace = r'C:\ArcMap\Apt_Parcels' # Select all apartments which overlap the Neighborhood polygon Apartments_SelectAll = arcpy.SelectLayerByAttribute_management('Parcels_owner', 'NEW_SELECTION', "[AcctType] = 'APARTMENT'") arcpy.CopyFeatures_management(Apartments_SelectAll, 'Apartments_Outside_of_Boundary') Apartments_neighborhoods = arcpy.SelectLayerByAttribute_management('apartment_neighborhood', 'NEW_SELECTION', "[Id] = '0'") arcpy.CopyFeatures_management(Apartments_neighborhoods, 'Apartment_Neighborhoods') # Within selected features, further select only those apartments that fall outside # of the neighborhoods they are supposed to be in fc = r'N:\My Documents\ArcGIS\Default.gdb\Apartments_Outside_of_Boundary' fc1 = r'N:\My Documents\ArcGIS\Default.gdb\Apartment_Neighborhoods' with arcpy.da.SearchCursor(fc,['apt_nbhd']) as cursor1: for x in cursor1: print x with arcpy.da.SearchCursor(fc1, ['Nbhd']) as cursor2: for y in cursor2: print y arcpy.SelectLayerByAttribute_management(Apartments_Outside_of_Boundary, 'SUBSET_SELECTION', 'cursor1' == 'cursor2') # Write the selected features to a new featureclass arcpy.CopyFeatures_management(Apartments_SelectAll, 'Apartments_Outside_of_Boundary_final')