0

I am lookinig for a way to use an AOI to search and extract data from the data drive on the network at work. So, for example, I have folders of elevation data. Instead of sorthing through each folder and subfolder, I can just use an AOI and it will only give me back the data I need. The Extract Data tool in in the Server Tools toolbox is kind of what I am looking for, but it only performs the extraction on data within the table of contents.

Any thoughts?

1

You would need to use lots of iteration. This is the general logic as semi-psuedocode that you can follow:

import arcpy
import os

arcpy.env.workspace = ROOT = r'some\root\path'

# loop thu workspaces (arcpy.ListWorkspaces())
# for ws in arcpy.ListWorkpaces:
#   if is ANY type of gdb:
#   arcpy.env.workspace = gdb = os.path.join(ROOT, ws)
#       # loop thru root of gdb
#       for fc in arcpy.ListFeatureClasses()
#           arcpy.analysis.Clip <-- if feature class
#       for raster in arcpy.ListRasters():
#           arcpy.management.Clip <--  raster
#       loop thru feature data sets
#       for fd in arcpy.ListDatasets('*', 'Feature'):
#           set workspace to feature dataset
#           #arcpy.env.workspace = os.path.join(ROOT, ws, fd)
#           #loop through feature classes
#           for fc in arcpy.ListFeatureClasses()
#               arcpy.analysis.Clip <-- if feature class
#           for raster in arcpy.ListRasters():
#               arcpy.management.Clip <--  raster

#   elif workspace is folder:
#       set workspace to folder
#       #loop through feature classes
#       for fc in arcpy.ListFeatureClasses():
#           arcpy.analysis.Clip <-- if shapfile
#       for raster in arcpy.ListRasters():
#           arcpy.management.Clip <--  raster
#   # loop thru subfolders?  os.walk

You would also need to decide how to handle subfolders. It may also be worth looking into arcpy.da.Walk

1

First consideration: how do you want to create the AOI? You could easily use the current extent of the data frame if this tool is to be run from arcmap. This or this may be useful. Or, I believe, with a python toolbox you could create a polygon with a few clicks.

At any rate, once you have the polygon as a feature (I would suggest creating an in_memory feature class) I would say arcpy.da.Walk is the best way way to go. Use it like this:

import arcpy
import os

topdir = r"path/to/root/folder"

for path, dirs, files in arcpy.da.Walk(topdir):
    for d in dirs:

        arcpy.env.workspace = os.path.join(path,d)

        for ws in arcpy.ListWorkspaces():
            arcpy.env.workspace = ws

            for raster in arcpy.ListRasters():                    
                # do raster stuff
            for fc in arcpy.ListFeatureClasses():
                # do vector stuff

This should collect everything you need. You may want to use the arcpyDescribe() function on the rasters and fcs to get more information about them before you clip or extract them. It looks like there are filters you can use with arcpy.da.Walk, I just don't have experience with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.