Data Extraction Tool

3142
3
06-02-2015 08:23 AM
RyanFortier
New Contributor III

Hello,

I am looking for a way to utlize an AOI in order to search for data. I deally I would like to eliminate the need to search through folders and sub folders for the data I am looking for in a specific area. I would use the AOI to extract only the data within it. I know there is a data extraction tool within the server tools toolbox, but that only extracts data from within the table of contents. I am looking to create something that will look at an actual drive on the network and create a GDB or something.

Any thoughts?

Reply
0 Kudos
3 Replies
LukeWebb
Occasional Contributor III

Here's some half written code that would work if you sort out the names of the files etc.

import arcpy

from arcpy import env

def process (folder):

    env.workspace = folder

    for file in arcpy.listFeatureclasses (folder):

        arcpy.clip (file, study area, output)

        #If there were no features in the study area

        if arcpy.getcount (output) == 0:

            arcpy.delete(output)

    workspaces = arcpy.listWorkspaces()

    for workspace in workspaces:

        process(workspace )

inputfolder = r'C:\where\is\the\data'

process(inputfolder)

GerryGabrisch
Occasional Contributor III

Here is code that will sift though a directory (and all sub directories) and create a convex hull for all GIS data.  The convex hulls are written to a new feature class.  You can then add the feature class to an ArcMap project and see all the data that covers your area of interest.  The output feature class contains an attribute listing the path to the data.

try:

    print "Create Convex Hulls for All Vector Data..."

    print "Created by Gerry Gabrisch (geraldg@lummi-nsn.gov)"

    print "Copy?Right! Lummi Indian Business Council 10-1-2013"

  

    import arcpy, math, os, sys, traceback, winsound

    winsound.Beep(1000,500)

    winsound.Beep(2500,500)

   

    inDir = "Z:\\Data"

    appendeddata = "C:\gtemp\DataExtentsZData.shp"

  

    arcpy.env.overwriteOutput = True

    datapaths = []

  

    def GetBoundingGeometry(inFC,datapaths):

        outFeatureClass = "C:\\gtemp\\convexhulltemp2.shp"

        appendeddata = "C:\gtemp\DataExtentsZData.shp"

        try:

            arcpy.MinimumBoundingGeometry_management(inFC, outFeatureClass,"CONVEX_HULL", "ALL")

            arcpy.Append_management(outFeatureClass, appendeddata, "NO_TEST","","")

            desc = arcpy.Describe(inFC)

            datapaths.append(desc.catalogPath)

        except:

            pass

    

    for root, dirs, files in os.walk(inDir):

        print "working in ", root

        #Get all geodatabase feature classes and feature dataset feature classes...

        if root.endswith(".gdb"):

            arcpy.env.workspace = root

            FeatureClasses = arcpy.ListFeatureClasses("*", "All")

            for features in FeatureClasses:

                desc = arcpy.Describe(features)

                GetBoundingGeometry(features, datapaths)

            datasets = arcpy.ListDatasets("*", "FEATURE")

            for dataset in datasets:

                arcpy.env.workspace = root + "\\" + dataset

                FeatureClasses = arcpy.ListFeatureClasses("*", "All")

                for features in FeatureClasses:

                    GetBoundingGeometry(features, datapaths)

      

        else:

            arcpy.env.workspace = root

            FeatureClasses = arcpy.ListFeatureClasses("*", "All")

            for features in FeatureClasses:

                desc = arcpy.Describe(features)

                if desc.dataType == "CoverageFeatureClass":

                    pass

                else:

                    GetBoundingGeometry(features, datapaths)

    rows = arcpy.UpdateCursor(appendeddata)

    counter = 0

    for row in rows:

        row.filepath = datapaths[counter]

        counter += 1

        rows.updateRow(row)          

    print "done"

    winsound.Beep(2500,1000)

except arcpy.ExecuteError:

    msgs = arcpy.GetMessages(2)

    arcpy.AddError(msgs)

    print msgs

except:

    tb = sys.exc_info()[2]

    tbinfo = traceback.format_tb(tb)[0]

    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])

    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"

    arcpy.AddError(pymsg)

    arcpy.AddError(msgs)

    print pymsg + "\n"

    print msgs

RyanFortier
New Contributor III

Thank you guys, much appreciated. The I jumped the gun on what I had thought the project will be. I will however try to implement these scripts into tools later on. Thanks you for your time.

Reply
0 Kudos