jderekito

finding overlaping polygons

Discussion created by jderekito on Jun 26, 2012
Latest reply on Jun 27, 2012 by kenbuja
Hello,
I am looping through two different polygon shapefiles.  I am trying to compare polygons in each to see if they overlap.  I have tried both touches and overlaps geometry methods but to no avail.  Any help would be greatly appreciated.  Here is my code:

 
import arcpy

countiesFC = "C:/Data/NEMAC/Projects/CohesiveFire/Data/Source/Counties_Regions/CountiesSimplifiedNAD83.shp"
countyRows = arcpy.SearchCursor(countiesFC) 
countyFields = arcpy.ListFields(countiesFC)
countyDesc = arcpy.Describe(countiesFC)
countyShapeName = countyDesc.ShapeFieldName

statesFC = "C:/Data/NEMAC/Projects/CohesiveFire/Data/Source/States_Regions/StatesNAD83.shp"
stateRows = arcpy.SearchCursor(statesFC) 
stateFields = arcpy.ListFields(statesFC)
stateDesc = arcpy.Describe(statesFC)
stateShapeName = stateDesc.ShapeFieldName

#arcpy.AddMessage(countRow.NAME + " : " + str(geom.area))

for countyRow in countyRows:
    countyGeom = arcpy.Geometry()
    countyGeom = countyRow.getValue(countyShapeName)
    #arcpy.AddMessage("County: " + countyRow.NAME)
    statesFC = "C:/Data/NEMAC/Projects/CohesiveFire/Data/Source/States_Regions/StatesNAD83.shp"
    stateRows = arcpy.SearchCursor(statesFC) 
    stateFields = arcpy.ListFields(statesFC)
    stateDesc = arcpy.Describe(statesFC)
    stateShapeName = stateDesc.ShapeFieldName
    for stateRow in stateRows:
        stateGeom = arcpy.Geometry()
        stateGeom = countyRow.getValue(stateShapeName)
        if stateGeom.overlaps(countyGeom):
            arcpy.AddMessage("State: " + stateRow.STATE_NAME + "overlaps " + countyRow.NAME)
    del stateRow
    del stateRows
    del stateFields
        
   



Thanks ahead of time,
Derek

Outcomes