Merging with Python

1977
6
06-22-2012 10:45 AM
JamesMitchell
New Contributor II
Hello,

I hope somebody can please help me with a script i am developing below. It buffers an input and then select the features within the buffer but then doesnt do the merge. I assume it is to do with the List i am using as the merge input. When i run this through the python window in ArcMap it seems to work.

Any help will be greatly appreciated as i am quite stuck at the moment and have tried everything i can think of.

Thank you

James

import arcpy, os, string, arcgisscripting

#Read input parameters from script tool
LayersList = string.split(arcpy.GetParameterAsText(0),";")
Site_Boundary = arcpy.GetParameterAsText(1)
BufferDistance = arcpy.GetParameterAsText(2)
OutputFolderLocation = arcpy.GetParameterAsText(3)


# Process: Buffer
arcpy.Buffer_analysis(Site_Boundary, OutputFolderLocation + "\\" + BufferDistance + "_Buffer.shp", BufferDistance, "FULL", "ROUND", "NONE", "")


# Process: Loop Layers
for Layer in LayersList: 

# Get filename of layer
LayerName = os.path.basename(Layer).strip("'") + "_FL"

# Process: Make Feature Layer (In, Out)
arcpy.MakeFeatureLayer_management(Layer.strip("'"), LayerName)

# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(LayerName, "INTERSECT", OutputFolderLocation + "\\" + BufferDistance + "_Buffer.shp", "0 Meters", "NEW_SELECTION")

arcpy.CopyFeatures_management(LayerName, OutputFolderLocation + "\\" + LayerName)

#Create List and Add Layers to the List
L = list ()
L.append(LayerName) 

# Process: Merge Selected Features
arcpy.Merge_management(L, OutputFolderLocation + "\\All_Sites.shp")
Tags (2)
0 Kudos
6 Replies
DarrenWiens2
MVP Honored Contributor
Try:
L = []
0 Kudos
JasonScheirer
Occasional Contributor III
arcpy.Merge_management(";".join(L), OutputFolderLocation + "\\All_Sites.shp")
0 Kudos
DarrenWiens2
MVP Honored Contributor
From the help, it looks like the input list should be comma delimited for merge, not semi-colons. Am I wrong?

edit: I just tried my way and it works.

#Create List and Add Layers to the List
 L = []
 L.append(LayerName) 

# Process: Merge Selected Features
 arcpy.Merge_management(L, OutputFolderLocation + "\\All_Sites.shp") 
0 Kudos
JamesMitchell
New Contributor II
Hello,

Thank you for the replies. I have tried both ways but the merge only contains one layer. Please can you shed any further light on this?

Thank you very much.
0 Kudos
JamesMitchell
New Contributor II
Hello again,

I have managed to get this to work. I just needed to move the L = list() before the for loop. I assume it kept recreating the list and therefore ended up only containing the last layer from the layerslist.

Thanks
0 Kudos
NolanGeise
New Contributor
arcpy.Merge_management(";".join(L), OutputFolderLocation + "\\All_Sites.shp")


Just used this and it seems to work great, thanks
0 Kudos