Help: Merging several shape files from a geodatabase

2346
4
08-16-2011 11:34 AM
ZiaAhmed
New Contributor III
I am trying to merge several shape files (county)  from a geodatabase to create  a shapefile for  a state. I tryed following script - but it is not working.I am using ArcGis 10. Help will be appreciated. Thanks
zia

# Script:

import arcpy, os
## Set the workspace
arcpy.env.workspace= "K:/COUNTY_MUKEY/test.gdb"

fcs = arcpy.ListFeatureClasses()

# Create the multi-value string for the Analysis Union tool
fcs.reset
# Get the first feature class name and set the string variable
fc = fcs.next()
inputs = fc
# Get the next name and start the loop
fc = fcs.next()
while fc: # While the fc name is not empty
    inputs = inputs + ";" + fc
    fc= fcs.next()
print inputs
    # Process: Merge...
try:
    arcpy.Merge_management(inputs,"K:/STATE_ MUKEY/REA.gdb/soilmu_in")
    print "finished"
except:
    print "error"
    print arcpy.GetMessage()
    del arcpy


# Error
Traceback (most recent call last):
  File "K:\Script\Python_Script\merge_shape.py", line 12, in <module>
    fcs.reset
AttributeError: 'list' object has no attribute 'reset'
>>>
Tags (2)
0 Kudos
4 Replies
BruceNielsen
Occasional Contributor III
Doesn't ListFeatureClasses return a list? If so, then the statement
inputs = ';'.join(fcs)
is all you need to build the string.
0 Kudos
ZiaAhmed
New Contributor III
Could you please tell me where I am going to add [ "inputs = ';'.join(fcs)"] in this
script. Thanks Zia

Doesn't ListFeatureClasses return a list? If so, then the statement
inputs = ';'.join(fcs)
is all you need to build the string.
0 Kudos
ZiaAhmed
New Contributor III
Following simplified script works well for mergeing all shape files from a file geodatabase.
Thanks a lot. Zia

import arcpy, os, sys
## Set the workspace
#
output_feature_class = "K:/STATE_ MUKEY/AREA.gdb/soilmu_in"
featureType = "POLY"
#
input_workspace="K:/COUNTY_MUKEY/IN.gdb"
arcpy.env.workspace= input_workspace
fcs = arcpy.ListFeatureClasses()
#
arcpy.Merge_management(fcs,output_feature_class, "soilmu_in")
#
print arcpy.GetMessages
0 Kudos
LukeMacaulay
New Contributor II
Yep, what Zia did here works well. Thanks for sharing your code!
0 Kudos