Select to view content in your preferred language

Help required - Script for merging shapefiles

7319
33
06-25-2010 03:55 AM
AlisonBowyer
New Contributor
Does anyone have Python code lines that i could use to merge shapefiles within subdirectories? Ideally I only want to merge shapefiles with the same names (i.e. merge all shapefile1 from folder1, folder2, folder3 into a new shapefile, all shapefile2 from folder1, folder2 etc)  I have point, polygon and line features that I need to merge.

I did find some code at http://forums.esri.com/thread.asp?t=231065&f=1729&c=93 but this merges all polygon or point features within the directories, and doesn't include line features.

Any help people can give me will be much appreciated as I don't understand the coding!
0 Kudos
33 Replies
MartinErglis
Emerging Contributor
You can also accomphish this with Data Interoperabiltiy extension - just make an interoperability connection to folder, including subfolders. After that, you will have all in one layer and you can use tool "feature class to feature class" to export to single shape file.

Martins
0 Kudos
LeslieGoodyear
New Contributor
I am very new to scripting and am learning as I go on this one... that being said, when I get to the point of creating the gp object, I can't figure out how to get to the next step. 

>>> import sys, os, arcgisscripting
>>> gp = arcgisscripting.create
>>> import string
>>> thepath = 'S:/Early Development Instrument (EDI) Data/GIS Base/Draft/FL,NY,OK,TX,WA/Area Water'
>>> thetargetfolder = 'S:/Early Development Instrument (EDI) Data/GIS Base/Draft/FL,NY,OK,TX,WA/MergedScripted'
>>> thefilename = 'checkthisbabyout.shp'
>>> GP = Dispatch ("esri.Geoprocessing.GPDispatch.1")
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    GP = Dispatch ("esri.Geoprocessing.GPDispatch.1")
NameError: name 'Dispatch' is not defined
0 Kudos
LeslieGoodyear
New Contributor
I realize that last post had no clear question... What does it mean when Python says that a name has not been defined?
0 Kudos
DanPatterson_Retired
MVP Emeritus
this line
>>> GP = Dispatch ("esri.Geoprocessing.GPDispatch.1")
is not needed since the geoprocessor was created earlier
>>> gp = arcgisscripting.create
and no module or method called Dispatch exists in your import statements or within their functions
0 Kudos