0

I work with arcview 10.3. I try to merge layer files in order to get one layer file that include all the features in the other layer files. All layer files as different names, and they all spread in big folder that divided to a lot of sub folders. My code is:

import arcpy,os,sys,string,fnmatch
import arcpy.mapping
from arcpy import env


rootPath = r"C:\Project\layers"
pattern = '*.lyr'
lyr2merge = []
counter = 0
for root, dirs, files in os.walk(rootPath):  
    for filename in fnmatch.filter(files, pattern):  
        lyr2merge.append(os.path.join(root, filename))
        counter = counter + 1
 arcpy.Merge_management(lyr2merge, r"C:\Project\layers\layer_total.lyr")
print 'merge'
print counter

i got an error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Table View.
ERROR 000840: The value is not a Table View.
ERROR 000840: The value is not a Table View.
Failed to execute (Merge).

i can merge shapefiles Merge shapefiles in folders and subfolders with arcpy but after that i will have to save it as layer file. Is it possible?

1 Answer 1

1

You are receiving that error because you are not providing one of the supported data types to Merge_management:

Input datasets can be point, line, or polygon feature classes or tables.

You can create a Layer object from a shapefile and save the Layer as a Layer file.

However, you need to be aware that the spatial data is not saved as part of the layer file. The layer file contains a pointer to the location of the spatial data.

Instead of trying "to merge layer files in order to get one layer file that include all the features in the other layer files" perhaps try to:

  1. Find the data sources of layer files you want to "merge"
  2. Combine the data from those sources into a single spatial dataset
  3. Create a layer (to then save as a layer file) from that spatial dataset
2
  • how do i continue the code?
    – newGIS
    Commented Jan 26, 2015 at 13:52
  • 2
    I'm happy to answer specific questions, like what might be causing the error in a code snippet (and here I have gone a little beyond that), but am not keen to facilitate GIS SE being used as a code writing service. There are existing Q&As here and information in the ArcGIS Help that would provide answers to the second and third questions within your question.
    – PolyGeo
    Commented Jan 26, 2015 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.