def validateLicense(): """ Check that the current license is using advanced. :return: """ if not arcpy.ProductInfo() == 'ArcInfo': if arcpy.CheckProduct('ArcInfo') == 'available': arcpy.SetProduct('ArcInfo') else: raise Exception('An advanced license was not available')
def createConnFile(self): ''' Turns out this is actually much simpler than was originally thought. Don't need a schema or a password to create the the sde file. This makes things much simpler ''' # connFileFullPath = self.secrets.getConnectionFilePath() connDirPath, connFilePath = os.path.split(self.connFile2Create) self.logger.debug("connDir: %s", connDirPath) self.logger.debug("connFile: %s", connFilePath) self.logger.debug("Connection file: %s", self.connFile2Create) suffix = os.path.splitext(self.connFile2Create)[1] if not suffix: self.connFile2Create = '{0}.sde'.format(self.connFile2Create) if not os.path.exists(self.connFile2Create): # if not arcpy.Exists(connFileFullPath): self.logger.debug('trying to create conn file ...') # for direct connect use: # CreateDatabaseConnection_management # host:port/serviceName, most of the time its just host/serviceName connStr = self.getConnectionString() self.logger.debug("importing arcpy...") import arcpy # @UnresolvedImport self.logger.debug("arcpy imported") arcpy.SetProduct('arcinfo') self.logger.debug('arcpy product info %s', arcpy.ProductInfo()) self.logger.debug("arcpytool report: %s", arcpy.CreateDatabaseConnection_management) self.logger.debug( 'inspect %s', inspect.getargspec(arcpy.CreateDatabaseConnection_management)) # seems to require a value for username and password even through they are invalid arcpy.CreateDatabaseConnection_management(connDirPath, connFilePath, self.dbtype.upper(), connStr, 'DATABASE_AUTH', 'junk', 'junk', 'DO_NOT_SAVE_USERNAME', self.sde) self.logger.info('connection file %s has been created', self.connFile2Create)
def checkOutLicenses(licenseType, extensionList): # Check out all necessary licenses if licenseType != None and len(licenseType) > 0: retVal = arcpy.SetProduct(licenseType) if retVal == "CheckedOut" or retVal == "AlreadyInitialized": arcpy.AddMessage("Got product successfully.") else: arcpy.AddError("Could not get license '" + licenseType + "'; return code: " + retVal) raise LicenseError for extension in extensionList: if arcpy.CheckExtension(extension) == "Available": arcpy.AddMessage(extension + " extension is available") retVal = arcpy.CheckOutExtension(extension) if retVal != "CheckedOut": arcpy.AddError("Could not get extension: " + extension + "; return code: " + retVal) raise LicenseError else: arcpy.AddMessage("Got extension: " + extension) else: raise LicenseError
# # corridor_mapper.py # Created on: Thu Apr 14 2011 03:58:21 PM # Author: Brent L. Brock, Craighead Institute # Usage: corridor_mapper <vshdLayer> <lcLayer> # --------------------------------------------------------------------------- # Import system modules import sys, string, os, arcpy from functionlib import CreateTempWorkspace, CleanFiles, ConvertMetersToOther, Rescale # Create the Geoprocessor object # Set the necessary product code arcpy.SetProduct("ArcInfo") arcpy.overwriteoutput = 1 arcpy.AddMessage("\tChecking availability of spatial analyst license...") if arcpy.CheckExtension("spatial") == "Available": arcpy.CheckOutExtension("spatial") else: arcpy.AddWarning("\tSpatial Analyst is needed to run this tool. Processing aborted...") raise "LicenseError" # Script arguments... pntLayer = sys.argv[1] lcLayer = sys.argv[2] lcSource = sys.argv[3] spPref = sys.argv[4] linkLayer = sys.argv[5]
#------------------------------------------------------------------------------- # Name: Extract Roughness polygons # Purpose: Extract Roughness polygons # # Author: LerchM # # Created: 30.04.2015 # Changed: 09.07.2015 # Licence: PNE Wind AG internal #------------------------------------------------------------------------------- #Arcpy importieren import arcpy #Lizenz pruefen arcpy.SetProduct("ArcView") #Begrüßung print "*** Rauhigkeitsextraktion ***\n" #Abfrage von UTM-Zone und Ausdehnung print "Koordinatenabfrage:" utm_zone = 0 while utm_zone not in (31, 32, 33): utm_zone = input("UTM Zone (ETRS) [31/32/33] ") if utm_zone == 33: epsg = 25833 elif utm_zone == 31: epsg = 25831 else: epsg = 25832
def execute(self, parameters, messages): """The source code of the tool.""" #CHECK LICENSING #Advanced License status = arcpy.SetProduct('arcInfo') if status == 'CheckedOut': pass if status == 'AlreadyInitialized': pass if status == 'NotLicensed': arcpy.ExcecuteError( "ERROR: ArcGIS Advanced licence is required to run this tool.") if status == 'Failed': arcpy.ExcecuteError( "ERROR: ArcGIS Advanced licence is required to run this tool.") #Extensions if arcpy.CheckExtension("Spatial") == "Available": arcpy.CheckOutExtension("Spatial") else: arcpy.ExcecuteError( "ERROR: The Spatial Analyst extension is required to run this tool." ) arcpy.env.overwriteOutput = True rapid_out_folder = parameters[0].valueAsText Drainage_Lines = parameters[1].valueAsText Stream_ID_DrainageLine = parameters[2].valueAsText Next_Down_ID = parameters[3].valueAsText length_field_DrainageLine = parameters[4].valueAsText Slope_field_DrainageLine = parameters[5].valueAsText Catchment_Features = parameters[6].valueAsText Stream_ID_Catchments = parameters[7].valueAsText Input_Reservoirs = parameters[8].valueAsText script_directory = os.path.dirname(__file__) arcpy.ImportToolbox( os.path.join(os.path.dirname(script_directory), "RAPID Tools.pyt")) #Create Network Connecitivty File out_network_connectivity_file = os.path.join(rapid_out_folder, "rapid_connect.csv") arcpy.CreateNetworkConnectivityFile_RAPIDTools( Drainage_Lines, Stream_ID_DrainageLine, Next_Down_ID, out_network_connectivity_file) # Create subset file out_subset_file = os.path.join(rapid_out_folder, "riv_bas_id.csv") arcpy.CreateSubsetFile_RAPIDTools(Drainage_Lines, Stream_ID_DrainageLine, out_subset_file) #Create Muksingum Parameters # Process: Muksingum k out_muskingum_kfac_file = os.path.join(rapid_out_folder, "kfac.csv") arcpy.CreateMuskingumKfacFile_RAPIDTools( in_drainage_line_features=Drainage_Lines, stream_ID=Stream_ID_DrainageLine, length=length_field_DrainageLine, slope=Slope_field_DrainageLine, co=1000.0 / 3600.0, in_formula="Eta*River Length/Sqrt(River Slope) [0.05, 0.95]", in_network_connectivity_file=out_network_connectivity_file, out_muskingum_kfac_file=out_muskingum_kfac_file) out_muskingum_k_file = os.path.join(rapid_out_folder, "k.csv") arcpy.CreateMuskingumKFile_RAPIDTools(0.35, out_muskingum_kfac_file, out_muskingum_k_file) # Process: Muskingum x out_muskingum_x_file = os.path.join(rapid_out_folder, "x.csv") arcpy.CreateMuskingumXField_RAPIDTools(Drainage_Lines, Stream_ID_DrainageLine, "0.3", Input_Reservoirs) arcpy.CreateMuskingumXFile_RAPIDTools(Drainage_Lines, Stream_ID_DrainageLine, out_muskingum_x_file) if Catchment_Features: lsm_grid_directory = os.path.join(script_directory, "lsm_grids") # Create ECMWF Low Res Weight Table low_resolution_ecmwf_grid = os.path.join( lsm_grid_directory, "runoff_ecmwf_tco639_grid.nc") low_resolution_weight_table = os.path.join( rapid_out_folder, "weight_ecmwf_tco639.csv") arcpy.CreateWeightTableFromECMWFRunoff_RAPIDTools( low_resolution_ecmwf_grid, out_network_connectivity_file, Catchment_Features, Stream_ID_Catchments, low_resolution_weight_table) # Create ECMWF High Res Weight Table high_resolution_ecmwf_grid = os.path.join( lsm_grid_directory, "runoff_ecmwf_t1279_grid.nc") high_resolution_weight_table = os.path.join( rapid_out_folder, "weight_ecmwf_t1279.csv") arcpy.CreateWeightTableFromECMWFRunoff_RAPIDTools( high_resolution_ecmwf_grid, out_network_connectivity_file, Catchment_Features, Stream_ID_Catchments, high_resolution_weight_table) # Create ERA Interim Weight Table era_interim_ecmwf_grid = os.path.join(lsm_grid_directory, "runoff_era_t511_grid.nc") era_interim_weight_table = os.path.join(rapid_out_folder, "weight_era_t511.csv") arcpy.CreateWeightTableFromECMWFRunoff_RAPIDTools( era_interim_ecmwf_grid, out_network_connectivity_file, Catchment_Features, Stream_ID_Catchments, era_interim_weight_table) # Flowline to point out_point_file = os.path.join(rapid_out_folder, "comid_lat_lon_z.csv") arcpy.FlowlineToPoint_RAPIDTools(Drainage_Lines, out_point_file) return