def __init__(self, parameters, service, *args, **kwargs): """Constructor initializes the Geoprocessor using :mod:`arcgisscripting` and loops thorugh all the available parameters in the Geoprocessor. Will raise an exception if problems occur with the Geoprocessor. Parameters are intended to be used in subclasses. Parameters: parameters - parameters object holding parameter information """ Tool.__init__(self, parameters) self._backend = 'arcgis' # TODO: handle the ArcGIS versions correctly try: # Inialize the logger for this tool. Logging system must be set up # before doing thishis self.logger = ArcLogger("Zupport.ArcTool", debugging=True) self.logger.debug('[%s] Acquiring geoprocessor' % service) self.gp = get_geoprocessor(10) # Set the scratch workspace explicitly to ESRI default self.gp.ScratchWorkspace = os.path.join(os.path.expanduser('~'), 'AppData', 'Local', 'Temp') except ImportError, e: self.logger.error('ArcGIS not present in the system.') sys.exit(1)
def __init__(self, parameters, service, *args, **kwargs): Tool.__init__(self, parameters, service, *args, **kwargs) self.name = self.__class__.__name__ # Identifier is a combination of the name and the class counter self.id = (self.name, PairFileiterator.id) self.log = Logger("Zupport.%s" % (self.__class__.__name__), debugging=True) self.service = service self.log.debug(msgInitSuccess)
def __init__(self, backend, parameters, *args, **kwargs): """Constructor will try to import all the necessary GDAL related modules (:mod:`osr`, :mod:`ogr`, :mod:`gdal`) and bind them as instance variables. If GDAL is not present in the system program execution will terminate. Parameters: backend - string describing the backend in use parameters - parameters object holding parameter information arclogging - boolean defining whether ArcGIS logging system is used """ Tool.__init__(self, backend, parameters, arclogging=False) # Try importing GDAL, will fail if GDAL not present try: from osgeo import osr, ogr, gdal except ImportError: self.logger.error('GDAL/OGR not present in the system.') return 1 # TODO: how does this really work? Does it mean, that each instance # has own copy or are they shared? # TODO: implement engine attribute self.osr = osr self.ogr = ogr self.gdal = gdal for parameter in args: self._parameters.append(parameter) for parameter, value in kwargs.iteritems(): self._parameters.append(value) # Check for keyword arguments if kwargs.has_key('inworkspace'): self.input = kwargs['inworkspace'] # Check for regular arguments elif len(args) > 0: self.input = args[0] # If input is defined create a workspace if self.input: self.workspace = Workspace(self.input) # Check for keyword arguments if kwargs.has_key('outworkspace'): self.output = kwargs['outworkspace'] # Check for regular arguments elif len(args) > 1: self.output = args[1]
def update(self, use_gp_params, gui, *args, **kwargs): """ Parse the provided *args and **kwargs into Parameters object (self.parameters). """ paramsno = int(self.gp.GetArgumentCount()) try: if gui: self.logger.gui = True # If parameters come from gp -> Tool being called from ArcGIS if paramsno > 0 and use_gp_params: # Last parameter toggles debugging self.logger.debugging = bool(self.gp.GetParameter(paramsno - 1)) self.logger.debug(str(paramsno)) gp_parameters = self.gp.GetParameterInfo() #self.logger.debug(self.parameters.parameter_names) for n in range(paramsno): self.logger.debug('param: ' + str(n)) self.logger.debug('name: ' + gp_parameters[n].name) self.logger.debug('value: ' + str(gp_parameters[n].value)) self.parameters.set_parameter_value( n, gp_parameters[n].value) # Otherwise parameters are provided as args or kwargs, this is also # the case if parameters are processed and provided for at batch # operation (parameters from ArcGIS form are different to those # provided for the actual tool) else: Tool.update(self, *args, **kwargs) self.logger.debugging = bool(self.get_parameter('debug')) self.gp.LogHistory = self.logger.debugging self.ready = True except ParameterError, e: self.log.exception('%s' % e)
def update(self, use_gp_params, gui, *args, **kwargs): """ Parse the provided *args and **kwargs into Parameters object (self.parameters). """ paramsno = int(self.gp.GetArgumentCount()) try: if gui: self.logger.gui = True # If parameters come from gp -> Tool being called from ArcGIS if paramsno > 0 and use_gp_params: # Last parameter toggles debugging self.logger.debugging = bool(self.gp.GetParameter(paramsno - 1)) self.logger.debug(str(paramsno)) gp_parameters = self.gp.GetParameterInfo() #self.logger.debug(self.parameters.parameter_names) for n in range(paramsno): self.logger.debug('param: ' + str(n)) self.logger.debug('name: ' + gp_parameters[n].name) self.logger.debug('value: ' + str(gp_parameters[n].value)) self.parameters.set_parameter_value(n, gp_parameters[n].value) # Otherwise parameters are provided as args or kwargs, this is also # the case if parameters are processed and provided for at batch # operation (parameters from ArcGIS form are different to those # provided for the actual tool) else: Tool.update(self, *args, **kwargs) self.logger.debugging = bool(self.get_parameter('debug')) self.gp.LogHistory = self.logger.debugging self.ready = True except ParameterError, e: self.log.exception('%s' % e)
def __init__(self, parameters, service, *args, **kwargs): Tool.__init__(self, parameters)