Muskie77

Bulk Load shp's into file gdb feature classes based on geometry (polygon,point,line)

Discussion created by Muskie77 on Jun 23, 2011
Hi all,

I'm a py-noob....but not a total programmer-noob. Definitely very new to harnessing all the gp functions. I'm hoping someone can give me some good guidance.

I have an insanely big folder full of (many) folders which contain (many) shapefiles and images. The projections of all the files are the same.

My task is to:

1) Bulk Load the shapefiles into feature classes (according to their different geometry type- which are polygons, points, and lines). Can't do this using the Load function in Catalog (**unless I find a way to print the list of shapefiles I generated in Python to an xml document which I can load there**).

2) Compare the attributes from these different shapefiles. Create a list of where the attributes differ so that I can see to it to populate the geodb with only the COMMON and desired attributes. 


In trying to DIY, I found this blog: http://www.aubreyrhea.net/gis/index.php/tag/geodatabase/

This blog (nearly) tells me how to do exactly what I need to do to get this job done...but doesn't add those critical details a noob needs to move past confounded to success (not blogger's fault: I just don't think noobs are the target audience). I did email blogger...but not that hopeful I'll hear back from her.

Where I am:

I have successfully set up the code to print a list of all the shapefiles in the folder. Now I'm trying to connect the dots. I would like to try her attribute tables comparison method....but it simply won't run.  I think I'm having problems with the "sys.argv[]" function (for example: in order to generate my shpList, I had to change the pattern = "*.shp"...not "sys.argv[1]" like the blog indicated).

I'm also loss at what functions are used to check shapefile geometry (if it's point, polyline, or polygon)....and how to use the ArcToolbox's "To Geodatabase" function to move the items from my shpList into geodatabase feature classes.

Enclosed is my code:


# import modules and create the geoprocessor object

import arcgisscripting, os, fnmatch, sys, string

#Set the workspace. List all of the shapefiles

# load toolbox

# gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")

# returns a list of shapefiles in the specified folder
# that match the specified wildcard search pattern

folder = r"R:\Temp\arielle\CalEMA"

pattern = "*.shp"
shpList = []

for path, dirs, files in os.walk(folder):
 for filename in fnmatch.filter(files, pattern):
  shpList.append(os.path.join(path, filename))

gp.AddMessage("Shapefiles returned:")
for shp in shpList:
 gp.AddMessage(shp)

for item in shpList:
        print item


# create a list of attribute field names

targetLayer = sys.argv[2]
targetList = gp.ListFields(targetLayer)
targetNames = []
for field in targetList:
 targetNames.append(field.Name)

# create a list of attribute field names for a list of shapefiles

x = 0
fieldNames = []
for shps in shpList:
 fieldList = gp.ListFields(shpList[x])
 for field in fieldList:
  fieldNames.append(field.Name)
 x = x + 1

Outcomes