Jump to content

 
Photo

Help with Python -->Merge_management

- - - - -

  • Please log in to reply
2 replies to this topic

#1
sidra

sidra

    Newbie

  • New Member
  • Pip
  • 4 posts
  • Australia

Hello,
I have been working on a Python script that will go into multiple sub folders of the main folder and puts all the files with the same name in a list, and then merge them together. Everything works until the Merge_management tool, i get the following error:

Traceback (most recent call last):
File "H:\Python\Practice\Sidra Scripts\test.py", line 31, in <module>
arcpy.Merge_management(fencePoList, outputName)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 3124, in Merge
raise e
ExecuteError: Failed to execute. Parameters are not valid.

The script is:

import arcpy
import os
from arcpy import env
arcpy.overwriteoutput = 1


inputFolder= "H:\\Python\\Practice\\SampleData\\\Survey_data"
targetFileName= "H:\\Python\\Practice\\SampleData\\Survey_data\\Merged_Posts.shp"


# Create the empty list
fencePoList= []

#try:
for root, dirs, files in os.walk(inputFolder, topdown=True):
for filename in files:
if filename[-6]=="P":
#print os.path.join(root, filename)
fencePosts = str(os.path.join(root, filename))
fencePoList.append(fencePosts)


# Format the list of shapefiles properly for the merge tool
#mergeSHP = '"'+';'.join(fencePoList)+'"'
#print mergeSHP

# Determine the new output feature class path and name
outputName = os.path.join(inputFolder, "Merged_Posts.shp")
#Merging the fence_pole files in all the folders
print "starting merge"
arcpy.Merge_management(fencePoList, outputName)
print "ending merge"

arcpy.AddMessage(arcpy.GetMessages())



#except Exception, ErrorDesc:
#If an error set output boolean parameter "Error" to True.
# arcpy.AddError(str(ErrorDesc))
# row = None
# rows = None

Hope someone can help!
Thanks

#2
Ninomax

Ninomax

    Contributor

  • Validated Member
  • PipPip
  • 37 posts
  • Vietnam

Hello
As the error is "Parameters are not valid", i would check what values of fencePoList and outputName are.
i notice you put one extra "\" for the inputFolder (before Survey_data).
it should be

"H:\\Python\\Practice\\SampleData\\Survey_data" or

or

inputFolder= r"H:\Python\Practice\SampleData\Survey_data"

Hope this helps

#3
sidra

sidra

    Newbie

  • New Member
  • Pip
  • 4 posts
  • Australia

I checked my code and i figured out the problem ..my list should only have .shp files, ive modifed my code and its working now :)
its funny how sometimes such stupid blunders cause soo much painnn lol
Thanks for your help though, much appreciated :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

-->