I made the following script to merge shape files of different format types (poly,line, points):
def main():
import arcpy
from arcpy import env
import globalpath
import os
env.workspace = globalpath.toolDataPath
dataPath=globalpath.toolDataPath
arcpy.env.overwriteOutput = True
#try:
DataTypeL=[("Polygon","mergedTOTPoly.shp"),("Polyline","mergedTOTLines.shp"),("Point","MergedTOTPoint.shp")]
for dType in DataTypeL:
(Typei,Title)=dType
matches = []
counter=0
for dirpath, dirnames, filenames in arcpy.da.Walk(dataPath+"\\UtilityDataFromZorgel",datatype="FeatureClass",type=Typei):
for filename in filenames:
match = ( os.path.join(dirpath, filename))
arcpy.AddMessage(m)
matches.append (match)
counter = counter + 1
arcpy.Merge_management(matches, dataPath+"\\utilities"+Title)
arcpy.AddMessage(str(counter)+" "+str(Typei)+" layers were merged into "+ str(filename))
#except:
arcpy.AddWarning("Merging Utility Layers Failed")
if __name__ == "__main__":
main()
I get the following error:
Traceback (most recent call last):
File "C:\merger.py", line 30, in <module>
main()
File "C:\merger.py", line 25, in main
arcpy.Merge_management(matches, dataPath+"\\utilities"+Title)
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3762, in Merge
raise e
ExecuteError: ERROR 001156: Failed on input OID 0, could not write value 'Kanata' to output field TILE_ID
Failed to execute (Merge).
When I merge these files manually from arcmap it works, and fields are mapped as follows:
"STRUCT_TYP \"STRUCT_TYP\" true true false 18 Text 0 0 ,First,#,Allstream_hdwr_L,STRUCT_TYP,-1,-1,allstream_L,STRUCT_TYP,-1,-1,Allstream_lines_L,STRUCT_TYP,-1,-1,Allstream_text_L,STRUCT_TYP,-1,-1,Atria_lines_L,STRUCT_TYP,-1,-1,Atria_text_L,STRUCT_TYP,-1,-1,bell_L,STRUCT_TYP,-1,-1)
where STRUCT_TYP is a shared field.
please let me know how can I get around this error, and if it is indeed mapping the fields how can I do it in batched merging, or should I merge each file individually?
-
Take a deep look into this online topic: Mapping input fields to output fieldsFarid Cheraghi– Farid Cheraghi2015年05月19日 19:27:54 +00:00Commented May 19, 2015 at 19:27
1 Answer 1
I got it to run on a directory full of parcels, PLSS, and annexations. The directory had a mix of shapefiles and file geodatabases. I defined the datapath differently, but otherwise changed nothing.
It failed on the 13th polygon feature class. The resulting shapefile had 62 fields and 44525 records. My failure was a type mismatch, so it was different than yours.
Try running on a subset of your input feature classes and add some print commands to tell you which feature class failed. You may have a field name or file name that is invalid in arcpy, but works when the feature class is inserted as a layer in ArcMap.
-
I'll try that and post what I findSolaire– Solaire2015年05月20日 11:55:46 +00:00Commented May 20, 2015 at 11:55
-
and why did you get a type mismatch at that point I'm curiousSolaire– Solaire2015年05月20日 12:00:45 +00:00Commented May 20, 2015 at 12:00
-
adding error handlers shows that only polygons are giving me errors, i removed some of the shape files to see if the issue persists it appears that "TILE_ID" is a problematic field as the problem appears with different values other than "Kanata"Solaire– Solaire2015年05月20日 13:12:06 +00:00Commented May 20, 2015 at 13:12
-
Is the "TILE_ID" field the same length (in characters) in all of your source files? If not, then rename one of your files with a wider "TILE_ID" field so that it is processed first.jlcrawf0– jlcrawf02015年05月20日 15:36:29 +00:00Commented May 20, 2015 at 15:36
-
no it's not the same length, I could have swore its about text length, i was trying to recalculate the value for "TILE_ID" as str(!TILE_ID!)[:4]Solaire– Solaire2015年05月20日 15:38:27 +00:00Commented May 20, 2015 at 15:38