## ## Merge multiple shapefiles from a single directory. ## # Import modules and create the geoprocessor object try: # 9.2 and beyond import arcgisscripting, sys, os gp = arcgisscripting.create() except: # 9.1 and before import win32com.client, sys, os gp = win32com.client.Dispatch("esriGeoprocessing.GpDisp atch.1") infolder = gp.GetParameterAsText(0) outputfc = gp.GetParameterAsText(1) # Set the current workspace so the list has full paths gp.workspace = os.getcwd() # Start a blank list for appending bList = [] # For each file in the current directory for file in os.listdir(''): # Get only the shapefiles if (file.endswith(".shp")): # Append all the files together into one big list filepath = bList.append(file) # Hard-code the output merged shapefile name shapefile = "Merged.shp" # Given a list of shapefiles, separate each by a ";" # and put quotes around the whole thing def shpList(filepath): return '"%s"' % ';'.join(bList) # Set the variable "mergedlist" to the newly formatted list of shapefiles mergedlist = shpList(filepath) try: print "\nMerging " + mergedlist + " to get " + shapefile + "...\n" gp.merge_management(mergedlist, shapefile) print gp.getMessages() except: print gp.getMessages() print "\n *** ERROR: Shapefiles failed to merge *** \n" print "\nDone."
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.