Hi Everyone,
I am trying to write python code to detect if there is overlapping polygon from two feature classes. The goal of this code is to get overlapping polygons and there area. I start by trying to get the area of the polygons themselves. This I am trying to do using arcpy.geometry. Next I want to use the overlap geometry operation in 10.1. This is a boolean operation that will speed up the intersection command later. Then I do the intersection and the symmetric difference. The end goal is to get polygon overlap/difference.
I think I have a few bugs in my code, but I am struggling to get the logic and the syntax correct. I tried to model my code off of this thread: http://forums.arcgis.com/threads/609...Geometry%28%29 .
Any help would be greatly appreciated.
Code:
Thank you,
Luke Kaim
Thank you
Luke Kaim (SIE)
Lucas.Kaim@maine.edu
(914)263-7866
"Don’t complain. Just work harder" (Randy Pausch).
I am trying to write python code to detect if there is overlapping polygon from two feature classes. The goal of this code is to get overlapping polygons and there area. I start by trying to get the area of the polygons themselves. This I am trying to do using arcpy.geometry. Next I want to use the overlap geometry operation in 10.1. This is a boolean operation that will speed up the intersection command later. Then I do the intersection and the symmetric difference. The end goal is to get polygon overlap/difference.
I think I have a few bugs in my code, but I am struggling to get the logic and the syntax correct. I tried to model my code off of this thread: http://forums.arcgis.com/threads/609...Geometry%28%29 .
Any help would be greatly appreciated.
Code:
Code:
def main():
try:
import arcpy, sys, traceback, os, string, locale
arcpy.env.overwriteOutput = True
from arcpy import env
env.workspace =r"C:\Users\Luke Kaim\Documents\University of Maine\Fall_2012\Volunteer Geographic Information\simalar"
VGIFile = r"C:\Users\Luke Kaim\Documents\University of Maine\Fall_2012\Volunteer Geographic Information\simalar\polygon.shp"
VGIFileShapeName = arcpy.Describe(VGIFile).ShapeFieldName
VGIRows = arcpy.SearchCursor(VGIFile)
GNIS_FC = r"C:\Users\Luke Kaim\Documents\University of Maine\Fall_2012\Volunteer Geographic Information\simalar\GNIS.shp"
GNIS_FCShapeName = arcpy.Describe(GNIS_FC).ShapeFieldName
GNIS_FCRows = arcpy.SearchCursor(GNIS_FC)
#Create an empty Geometry object
g = arcpy.Geometry()
area=0
# get Geometry of every VGI polygon. Then get the area of each polygon
for VGIFileShapeName in VGIRows:
feat = VGIFileShapeName.getValue(shapeName)
area += feat.area
print area
#Create an empty Geometry object
g = arcpy.Geometry()
area=0
# get Geometry of every GNIS polygon. Then get the area of each polygon
for GNIS_FCShapeName in GNIS_FCRows:
feat = GNIS_FCShapeName.getValue(shapeName)
area += feat.area
print area
for VGIRow in VGIRows:
VGIGEOM = VGIRow.getValue(VGIFileShapeName)
GNIS_Rows = arcpy.SearchCursor(GNIS_FC)
for GNIS_Row in GNIS_Rows
GNIS_Geom = GNIS_Row.getValue(GNIS_FCShapeName)
if GNIS_Geom.overlaps(VGIGEOM):
arcpy.Intersect_analysis([GNIS_Geom,VGIGEOM],"in_memory/Intersection")
arcpy.SymDiff_analysis([GNIS_Geom,VGIGEOM],"in_memory/SymDiff")
intersectionRows = arcpy.SearchCursor("in_memory/Intersection")
for intersectionRow in intersectionRows:
intersectionArea = intersectionRow.Shape.area
print "Overlap Area: " + str(intersectionArea)
intersectionRows2 = arcpy.SearchCursor("in_memory/"in_memory/SymDiff"")
for intersectionRow1 in intersectionRows2:
intersectionArea2 = intersectionRow1.Shape.area
print "Overlap Area :in_memory/SymDiff " + str(intersectionArea2)
del VGIRows, GNIS_FCRows,GNIS_Rows
Luke Kaim
Thank you
Luke Kaim (SIE)
Lucas.Kaim@maine.edu
(914)263-7866
"Don’t complain. Just work harder" (Randy Pausch).