I'm not understanding fully how extent is supposed to work in ArcPy/Python. I can't seem to get it to work in a function so I can filter it through my feature classes (FCs). I have read the ESRI help files, but remain confused.
Below is a description of what I am trying to accomplish, followed by the little code I have so far. I think it is an issue with my understanding of how this operation works, but any/all advice is welcome.
A script that will prompt for the name of a File Geodatabase and an XMIN, YMIN, XMAX, YMAX set of coordinates. Then loop over each feature class and determine if the extent of each feature class overlaps this extent. If so, it will also determine how many features are within that extent. *** Note: It should report 0 for any feature classes that process through the extent but have no features in the extent. Also, check if any of the following geometry operations exist: within, contains, or overlaps.
import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
#Set user-defined inputs
gdb = r"F:\....\&&&.gdb"
XMin = 1260000
YMin = 337000
XMax = 1280000
YMax = 360000
# Set extent
def Extent():
XMin = 1260000
YMin = 337000
XMax = 1280000
YMax = 360000
try:
arcpy.env.extent = arcpy.Extent(XMIN,YMIN,XMAX,YMAX)
extent = arcpy.env.extent
return extent
except:
print ("An Error has occurred in Extent().")
extent = Extent()
print extent
#List available Feature Classes in a List
def FCs_in_GDB(gdb):
try:
arcpy.env.workspace = gdb
print (arcpy.env.workspace)
fcs = []
for fds in arcpy.ListDatasets('','feature') + ['']:
for fc in arcpy.ListFeatureClasses('','',fds):
fcs.append(os.path.join(fds, fc))
return fcs
except:
print ("An Error has occurred in FCs_in_GDB().")
fcs = FCs_in_GDB(gdb)
for fc in fcs:
print fc