Monthly Archives: March 2010

Merging Shapefiles – gp.merge_management()

I have been pulling my hair out all day to get this to work.

I have a number of folders, each containing one shapefile (stratmap transportation files – ftp://ftp2.tnris.org/) with county-wide data. I would like to combine (merge) all these files into one state-wide (Texas) shapefile.

I didn’t like doing it this way (using a long string concatenation in my merge method), but I was unable to get the value table version of this to work, as shown on the ESRI website (here or here). Nor was I successful with Bill’s workaround to that problem. Is this really an ArcGIS bug, or was I doing something wrong ?

I found it wasn’t entirely clear from the documentation that you can use a string in your merge. Using a list sure would be easier.

# ————————————————-
# CountyToState.py
# A program that merges county-wide shapefile data
# and merges it into one state-wide shapefile.
# ————————————————-

# Create the Geoprocessor object
import os, sys, arcgisscripting, string
gp = arcgisscripting.create(9.3)

# Setup variables
gp.workspace = r”C:\Shp”¬† # The source directory
outshp = r’c:\shp\texas.shp’ # The output
fcstring = ” ”

# List all workspaces (folders)
workspaces = gp.listworkspaces(” “, “Folder”)

#Iterate through folders, set active workspace
for workspace in workspaces:
gp.workspace = workspace  # I found this was necessary

#List all feature classes (shapefiles) in folders
fcs = gp.ListFeatureClasses()

#Iterate through shapefiles
for fc in fcs:
#Create all shapefiles addresses (including)
# workspace in “;”-separated string for merging

fcstring=fcstring+str(workspace)+”\\”+str(fc)+”;”

#Merge shapefiles
gp.merge_management(fcstring,outshp)

———————————————–

The result of running this script was a convenient state wide file. Unfortunately, the size ballooned from a few MB per county to a 100MB SHP for the state, and an almost 1GB DBF.

3 Comments

Filed under Uncategorized

ArcGIS – WARNING 000595 (Error Code)

I just tried to extract a feature class (=> SHP) from an ESRI provided SDC file, and got this error:

WARNING 000595: C:\Users\xxxx\AppData\Local\Temp\citylim2.fid contains
the full list of features not able to be copied.

There are hundreds of polygon features missing from the resulting shapefile. What’s going on here ?

ESRI provides this error explanation:

Some features cannot be added to the output. This message is normally paired with a second warning/error message indicating the specific problem. The file listed in the message can be checked for a complete list of all features that could not be copied.

As usual, I wanna say, – Very Helpful !

Leave a comment

Filed under Uncategorized