import arcpy
arcpy.env.workspace = "C:/path/PADUS/Polys.gdb"
countiesFC = "Counties"
countyRows = arcpy.SearchCursor(countiesFC)
countyFields = arcpy.ListFields(countiesFC)
PADUSFC = "PADUS"
PADUSRows = arcpy.SearchCursor(PADUSFC)
PADUSFields = arcpy.ListFields(PADUSFC)
countyGeom = arcpy.Geometry()
countyGeomList = arcpy.CopyFeatures_management("Counties", countyGeom)
PADUSGeom = arcpy.Geometry()
PADUSGeomList = arcpy.CopyFeatures_management("PADUS", PADUSGeom)
countyIndex = 0
#arcpy.AddMessage(str(len(countyGeomList)))
for countyRow in countyRows:
countyGeom = countyGeomList[countyIndex]
#arcpy.AddMessage("county: " + countyRow.name + " - " + str(countyGeom.area))
PADUSFC = "PADUS"
PADUSRows = arcpy.SearchCursor(PADUSFC)
PADUSIndex = 0
for PADUSRow in PADUSRows:
PADUSGeom = PADUSGeomList[PADUSIndex]
if PADUSGeom.overlaps(countyGeom):
arcpy.AddMessage("PADUS: " + PADUSRow.own_type + "overlaps " + countyRow.NAME)
#here want to find the area of overlap between the two geometry polygons
PADUSIndex = PADUSIndex + 1
#arcpy.Delete_management("C:/temp/test.shp")
del PADUSFC
del PADUSRow
del PADUSRows
#arcpy.AddMessage(str(countyIndex))
countyIndex = countyIndex + 1
a = arcpy.Geometry()
a = arcpy.Intersect_analysis(PADUSGeom, countyGeom, "", "", "")
arcpy.AddMessage("Overlap Area: " + str(a.area))
if PADUSGeom.overlaps(countyGeom): diff = PADUSGeom.difference(countyGeom) diff_area = diff.area
if PADUSGeom.overlaps(countyGeom): diff = PADUSGeom.difference(countyGeom) diff_area = diff.area
if PADUSGeom.overlaps(countyGeom):
arcpy.Intersect_analysis([countyGeom, PADUSGeom], "in_memory/Intersection")
intersectionRows = arcpy.SearchCursor("in_memory/Intersection")
for intersectionRow in intersectionRows:
intersectionArea = intersectionRow.Shape.area
print "Overlap Area: " + str(intersectionArea)
#delete in_memory feature class
arcpy.Delete_management("in_memory/Intersection")
import arcpy
#arcpy.env.workspace = "C:/path/PADUS/Polys.gdb"
arcpy.env.workspace = "C:/path/Polys.gdb"
countiesFC = "Counties"
countyRows = arcpy.SearchCursor(countiesFC)
countyFields = arcpy.ListFields(countiesFC)
PADUSFC = "PADUS"
PADUSRows = arcpy.SearchCursor(PADUSFC)
PADUSFields = arcpy.ListFields(PADUSFC)
countyGeom = arcpy.Geometry()
countyGeomList = arcpy.CopyFeatures_management("Counties", countyGeom)
PADUSGeom = arcpy.Geometry()
PADUSGeomList = arcpy.CopyFeatures_management("PADUS", PADUSGeom)
countyIndex = 0
#arcpy.AddMessage(str(len(countyGeomList)))
for countyRow in countyRows:
countyGeom = countyGeomList[countyIndex]
arcpy.AddMessage("county: " + countyRow.name + " - " + str(countyGeom.area))
PADUSFC = "PADUS"
PADUSRows = arcpy.SearchCursor(PADUSFC)
PADUSIndex = 0
for PADUSRow in PADUSRows:
if arcpy.Exists("in_memory/Intersection"):
arcpy.Delete_management("in_memory/Intersection")
arcpy("del in_mem")
PADUSGeom = PADUSGeomList[PADUSIndex]
if PADUSGeom.overlaps(countyGeom):
arcpy.AddMessage("PADUS: " + PADUSRow.own_type + "overlaps " + countyRow.NAME)
#here want to find the area of overlap between the two geometry polygons
arcpy.Intersect_analysis([countyGeom, PADUSGeom], "in_memory/Intersection")
intersectionRows = arcpy.SearchCursor("in_memory/Intersection")
for intersectionRow in intersectionRows:
intersectionArea = intersectionRow.Shape.area
arcpy.AddMessage("Overlap Area: " + str(intersectionArea))
PADUSIndex = PADUSIndex + 1
del PADUSFC
del PADUSRow
del PADUSRows
#arcpy.AddMessage(str(countyIndex))
countyIndex = countyIndex + 1
def main():
try:
import arcpy, sys, traceback, os
arcpy.env.overwriteOutput = True
countiesFC = r"C:\tmp\Test.gdb\Counties"
countyShapeName = arcpy.Describe(countiesFC).ShapeFieldName
countyRows = arcpy.SearchCursor(countiesFC)
polyFC = r"C:\tmp\t.gdb\Polygons"
polyShapeName = arcpy.Describe(polyFC).ShapeFieldName
for countyRow in countyRows:
countyGeom = countyRow.getValue(countyShapeName)
polyRows = arcpy.SearchCursor(polyFC)
for polyRow in polyRows:
polyGeom = polyRow.getValue(polyShapeName)
if countyGeom.contains(polyGeom):
arcpy.Intersect_analysis([countyGeom, polyGeom], "in_memory/Intersection")
intersectionRows = arcpy.SearchCursor("in_memory/Intersection")
for intersectionRow in intersectionRows:
intersectionArea = intersectionRow.Shape.area
print "Overlap Area: " + str(intersectionArea)
del countyRows, countyRow, polyRows
except:
print arcpy.GetMessages()
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a
# message string
pymsg = tbinfo + "\n" + str(sys.exc_type)+ ": " + str(sys.exc_value)
# Return python error messages for use with a script tool
arcpy.AddError(pymsg)
# Print Python error messages for use in Python/PythonWin
print pymsg
if __name__ == '__main__':
main()