Batch Merge Shape Files
December 23 2010 |
2 comments
Categories:
Map Data
I have a large quantity of UK shape files from the Ordnance Survey OpenOS Data catalogue (VectorMap District). The data is divided into 10km tiles and each tile has up to 14 different shape files (point, line and polygon). Each tile is in its own folder and all files are named the same way, ie. "Road_Line.shp" or "Height.shp" in each folder.
Is there a way that I can merge all "Height" or "Road" files in a batch, rather than having to manually select each individual file through the Merge tool. Is there a way of merging files with the same name, that sit within different sub-folders? I have looked at the batch option for Merge, but it does not appear to do what I need.
Mapping Center Answer:
Yes, you can merge in a batch mode using Python Scripting or Iterators in Model Builder. In python, you would need to loop through each subfolder and then merge the files. I have created a sample script for your case, which is attached here.
You can modify the attached script in a text editor and then load it in a python window and run it. This script will merge all your roads/height shapefiles in one process.
Hope this helps!
# check if 'Riverside' name exists in shapefile name
if filename.find("Riverside") == 0:
print os.path.join(root, filename)
riverside = str(os.path.join(root, filename))
riversideList.append(riverside)
elif filename.find("San Bernadino") == 0:
print os.path.join(root, filename)
SanBernadino= str(os.path.join(root, filename))
SanBernadinoList.append(SanBernadino
elif
--- code here---
There are a number of ways to acheive what you want, and I am suggesting just one. You can read about arcpy here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_ArcPy/000v00000001000000/
and regarding python here: http://docs.python.org/
If you would like to post a comment, please login.