POST
|
Hello I've been working on this off and on for the past 3 weeks so I thought I'd try to forum for some answers. It's not that complicated of a problem. I have a model that I've attached to this message. In this model I have a custom script. The script is called "MergeFolder" and I have copied and pasted it below. It merges all shapefiles in one folder into a single shapefile. I am using Arc9.3 and the folder contains all line shapefiles. What I've been having problems is accepting user input for assigning the input folder and the output merged shapefile. I know the use of arguments will solve this but how specifically can I do this? How can I change the script to accept user input? In the model, I changed the script properties to the attachments below (inFolder & outShp). Are the properties correct? ## ## 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.GpDispatch.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." Thank you
... View more
12-08-2010
05:55 AM
|
0
|
2
|
3157
|
POST
|
Below is a post I found on the old ESRI forum. When I add a raster from my file geodatabase, I want it to programatically load the layer file as well. Where do I insert the code below to do that? http://forums.esri.com/Thread.asp?c=93&f=992&t=277233 I use a File Geodatabase with the name: database.gdb I have some layers in this gdb, which I want to load to ArcMap programmatically.(the database.gdb is a folder with files inside with extensions .freelist, .gdbindexes, .gdbtable, .gdbtablx and .spx) Wherever I look in the forum I get code for an mdb Geodatabase. How can I load a layer from a File Geodatabase? The following code didn't work. I get an automation error at the line pWorkspaceFactory.OpenFromFile("C:\ZZZ\database.gdb", 0) It only works (I think) with mdb files Thank you Dim pWorkspaceFactory As IWorkspaceFactory Set pWorkspaceFactory = New FileGDBWorkspaceFactory 'Open the Access Workspace Dim pWorkspace As IFeatureWorkspace Set pWorkspace = pWorkspaceFactory.OpenFromFile("C:\ZZZ\database.gdb", 0) 'Open the featureclass Dim pFeatureClass As IFeatureClass Set pFeatureClass = pWorkspace.OpenFeatureClass("LayerName") 'Create a new Feature Layer Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = New FeatureLayer 'Set the feature class to the geodatabase featureclass Set pFeatureLayer.FeatureClass = pFeatureClass pFeatureLayer.Name = pFeatureClass.AliasName 'Add the new layer to ArcMap Dim pDoc As IMxDocument Set pDoc = ThisDocument Dim pMap As IMap Set pMap = pDoc.FocusMap pMap.AddLayer pFeatureLayer 'Refresh the view and table of contents pDoc.UpdateContents pDoc.ActiveView.Refresh
... View more
08-23-2010
05:37 AM
|
0
|
4
|
6523
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|