I am trying to compare county borders in two shapefiles and create a third showing how (if at all) those borders changed. To do so, I'm using
I have tried the following code:
# Detect changes in county boundaries over time import arcpy #Set working directory cd = r"C:\Users\folder" arcpy.env.workspace = cd arcpy.env.overwriteOutput = True #Set local variables file1 = r"county_shapefiles\county_2000.shp" file2 = r"county_shapefiles\county_2005.shp" output = r"county_shapefiles\county_changes.shp" #Create changes shapefile arcpy.DetectFeatureChanges_management(file1, file2, output, "500 Feet")
but I get the
error 000366: invalid geometry type. The error occurs twice, so I assume it is related to the two shapefiles I use as input.
I consulted the Help from Esri (http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/detect-feature-changes.htm), but in their example code they use shapefiles (.shp), too, so this should not be the problem.
Following ShaunO's suggestion I tried to use the
intersect function to do the same. I adapted his code in the following way:
file1 = r"county_shapefiles\county_2000.shp" file2 = r"county_shapefiles\county_2005.shp" arcpy.MakeFeatureLayer_management(file1,"lyr1") arcpy.MakeFeatureLayer_management(file2,"lyr2") #make an empty set to hold outputs from intersect tool CountyIDs = set() with arcpy.da.SearchCursor("lyr1", "COUNTY") as cursor1: for row in cursor1: with arcpy.da.SearchCursor("lyr2", "COUNTY") as cursor2: for rows in cursor2: #create sliver with intersect toool for each county arcpy.Intersect_analysis(["lyr1", "lyr2"], rows+".shp") #Add Interset outputs to set for merge CountyIDs.add(rows) #finally, merge all the outputs arcpy.Merge_management(CountyIDs,"county_changes.shp") #delete layers to release them from memory arcpy.Delete_management(lyr1) arcpy.Delete_management(lyr2)
I have changed some things that produced errors before (no guarantee I changed anything for the better. Still new to ArcPy/Python). Now the code does not produce any error anymore, but it does not finish either. Is this due to a programming error on my behalf, or simply because intersecting close to 4000 counties, and hence adding up 4000 shapefiles, is a very time-consuming or inefficient task?