""" Spatial Data Modeller for ESRI* ArcGIS 9.2 Copyright 2007 Gary L Raines, Reno, NV, USA: production and certification Don L Sawatzky, Spokane, WA, USA: Python software development # --------------------------------------------------------------------------- # GeoXplore.py # Created on: Thu Jun 15 2006 02:58:13 PM # (generated by ArcGIS/ModelBuilder) # Usage: BandStats # --------------------------------------------------------------------------- """ # Import system modules import sys, string, os, commands, traceback # Create the Geoprocessor object #gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") import arcgisscripting gp = arcgisscripting.create() #Check input files try: ## Trainfile = gp.GetParameterAsText(1) #<== RDB Trainfile = gp.GetParameterAsText(0) if gp.exists(Trainfile): if Trainfile.endswith("_train.dta"): tprefix = os.path.basename(Trainfile)[:os.path.basename(Trainfile).index('_train')] else: tprefix = os.path.splitext(os.path.basename(Trainfile))[0] gp.AddWarning("\nUse the following input file in GeoXplore:\n\n%s\n"%(Trainfile)) ## Classfile = gp.GetParameterAsText(2) #<== RDB Classfile = gp.GetParameterAsText(1) if Classfile <> "": gp.AddWarning("\nUse the following input file in GeoXplore:\n\n%s\n"%(Classfile)) gp.AddWarning("Use one or more of the following output file names in GeoXplore:\n\n%s\n%s\n%s\n" %(os.path.join(gp.workspace,'%s.RBN'%tprefix), os.path.join(gp.workspace,'%s.PNN'%tprefix), os.path.join(gp.workspace,'%s.FUZ'%tprefix))) #geoxplor.exe starts in input files folder. command = os.path.join(sys.path[0], 'GeoXplore061106.exe') if not os.path.exists(command): gp.AddError("GeoXplore executable file does not exist: %s"%command) raise params = [] #gp.AddMessage('Running %s: '%command) os.spawnv(os.P_WAIT, command, params) #<== RDB ## if gp.exists('%s.RBN'%tprefix): ## gp.SetParameterAsText(3,gp.Describe('%s.RBN'%tprefix).CatalogPath) ## gp.AddWarning('%s.RBN exists.'%tprefix) ## if gp.exists('%s.PNN'%tprefix): ## gp.SetParameterAsText(4,gp.Describe('%s.PNN'%tprefix).CatalogPath) ## gp.AddWarning('%s.PNN exists.'%tprefix) ## if gp.exists('%s.FUZ'%tprefix): ## gp.SetParameterAsText(5,gp.Describe('%s.FUZ'%tprefix).CatalogPath) ## gp.AddWarning('%s.FUZ exists.'%tprefix) if gp.exists('%s.RBN'%tprefix): gp.SetParameterAsText(2,gp.Describe('%s.RBN'%tprefix).CatalogPath) #gp.AddWarning('%s.RBN exists.'%tprefix) if gp.exists('%s.PNN'%tprefix): gp.SetParameterAsText(3,gp.Describe('%s.PNN'%tprefix).CatalogPath) #gp.AddWarning('%s.PNN exists.'%tprefix) if gp.exists('%s.FUZ'%tprefix): gp.SetParameterAsText(4,gp.Describe('%s.FUZ'%tprefix).CatalogPath) #gp.AddWarning('%s.FUZ exists.'%tprefix) gp.AddMessage("Finished running GeoXplore") except Exception, msg: # get the traceback object tb = sys.exc_info()[2] # tbinfo contains the line number that the code failed on and the code from that line tbinfo = traceback.format_tb(tb)[0] # concatenate information together concerning the error into a message string pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + \ str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n" # generate a message string for any geoprocessing tool errors msgs = "GP ERRORS:\n" + gp.GetMessages(2) + "\n" gp.AddError(msgs) # return gp messages for use with a script tool gp.AddError(pymsg) # print messages for use in Python/PythonWin print pymsg print msgs raise