Esempio n. 1
0
class DiscrertizeFields(ArcTool):
    """
    

    """

    implements(IGISTool)

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        DiscrertizeFields.id = DiscrertizeFields.id + 1
        self.name = self.__class__.__name__
        # Identifier is a combination of the name and the class counter
        self.id = (self.name, DiscrertizeFields.id)

        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__), debugging=True)

        self.log.debug(msgInitStart)
        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension("spatial")
        except LicenseError, e:
            self.log.error(e)
            return 1

        self.service = service

        self.log.debug(msgInitSuccess)
Esempio n. 2
0
class DiscrertizeFields(ArcTool):
    """
    

    """
    implements(IGISTool)

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        DiscrertizeFields.id = DiscrertizeFields.id + 1
        self.name = self.__class__.__name__
        # Identifier is a combination of the name and the class counter
        self.id = (self.name, DiscrertizeFields.id)

        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__),
                             debugging=True)

        self.log.debug(msgInitStart)
        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1

        self.service = service

        self.log.debug(msgInitSuccess)
Esempio n. 3
0
class CrossSelect(ArcTool):

    implements(IGISTool)

    """ ArcTool for batch selecting pixels from rasters in workspace based on
    a single raster.

    Tool works on a set of rasters in a workspace and uses a reference raster's
    unique values to select pixels from target rasters. For example, if
    reference raster would represent land use classes [1, 2, 3] and rasters A
    and B would have continuous values ArcCrossSelect would create 6 new rasters
    -> 1 / land use class / value raster.

    (0) Reference raster [refraster] - String representing reference raster
                                       based on which the selection will be
                                       made (required)
    (1) Input workspace [inworkspace] - String representing the source
                                         workspace that contains value rasters
                                         (required)
    (2) Output workspace [outworkspace] - String for the location of the
                                          resulting rasters (required)
    (3) Include values [include] - List holding values in the reference raster
                                   to include (optional, default: None)
    (4) Exclude values [exclude] - List holding values in the reference raster
                                   to exclude (optional, default: None)
    (5) Raster format [raster_type] - String for the output raster format
                                     (optional, default: "img")
    (6) Output name tag [tag] - String to tag the the output names. Will be
                                placed between the raster name body and value
                                identifier. tag = kp -> A_kp1.img
    """

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        CrossSelect.id = CrossSelect.id + 1
        self.id = CrossSelect.id
        self.name = self.__module__.split('.')[-1]

        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__),
                             debugging=True)

        self.log.debug(msgInitStart)

        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1

        self.service = service

        self.log.debug(msgInitSuccess)
Esempio n. 4
0
class CrossSelect(ArcTool):
    
    implements(IGISTool)
    
    """ ArcTool for batch selecting pixels from rasters in workspace based on 
    a single raster.
    
    Tool works on a set of rasters in a workspace and uses a reference raster's
    unique values to select pixels from target rasters. For example, if 
    reference raster would represent land use classes [1, 2, 3] and rasters A
    and B would have continuous values ArcCrossSelect would create 6 new rasters
    -> 1 / land use class / value raster.

    (0) Reference raster [refraster] - String representing reference raster 
                                       based on which the selection will be 
                                       made (required)
    (1) Input workspace [inworkspace] - String representing the source 
                                         workspace that contains value rasters
                                         (required)
    (2) Output workspace [outworkspace] - String for the location of the 
                                          resulting rasters (required)
    (3) Include values [include] - List holding values in the reference raster
                                   to include (optional, default: None)
    (4) Exclude values [exclude] - List holding values in the reference raster
                                   to exclude (optional, default: None)
    (5) Raster format [raster_type] - String for the output raster format
                                     (optional, default: "img")
    (6) Output name tag [tag] - String to tag the the output names. Will be 
                                placed between the raster name body and value 
                                identifier. tag = kp -> A_kp1.img
    """

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        CrossSelect.id = CrossSelect.id + 1
        self.id = CrossSelect.id
        self.name = self.__module__.split('.')[-1]
        
        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__), 
                                             debugging=True)

        self.log.debug(msgInitStart)

        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1
        
        self.service = service
        
        self.log.debug(msgInitSuccess)
Esempio n. 5
0
File: core.py Progetto: cbig/zupport
class ArcTool(Tool):
	
	"""
	Class to represent a generic ArcGIS scripting tool.

	This class is intended mostly to be subclassed and provides methods for
	getting the input parameters for the Geoprocessor (GP). ArcGIS must be
	present in the system. Class should not be instantiated, but instead used as
	a super class. Class and its derivatives have three user cases:

	1. Subclasses are instantiated *from within ArcGIS* (Toolbox): the
	GP will get all the provided parameters and it is up to the
	subclasses to handle them correctly.

	2. Subclasses are instantiated *directly from command line*: the
	GP will get all the provided parameters and it is up to the
	subclasses to handle them correctly.

	3. Subclasses are instantiated *from elsewhere in code*: the parameters
	provided by the Geoprocessor will not be what expected.

	Setting the workspace is the responsibility of subclasses.
	"""

	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)
		except:
Esempio n. 6
0
class ArcTool(Tool):
    """
	Class to represent a generic ArcGIS scripting tool.

	This class is intended mostly to be subclassed and provides methods for
	getting the input parameters for the Geoprocessor (GP). ArcGIS must be
	present in the system. Class should not be instantiated, but instead used as
	a super class. Class and its derivatives have three user cases:

	1. Subclasses are instantiated *from within ArcGIS* (Toolbox): the
	GP will get all the provided parameters and it is up to the
	subclasses to handle them correctly.

	2. Subclasses are instantiated *directly from command line*: the
	GP will get all the provided parameters and it is up to the
	subclasses to handle them correctly.

	3. Subclasses are instantiated *from elsewhere in code*: the parameters
	provided by the Geoprocessor will not be what expected.

	Setting the workspace is the responsibility of subclasses.
	"""
    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)
        except:
Esempio n. 7
0
class MultiConvertRaster(ArcTool):
    """ ArcTool for converting feature layers to rasters based on multiple
	attribute selections.

	TODO: parameters require a dictionary -> how will this handled by Toolbox
		  GUI?

	Parameters:
	(0) Input feature [infeature]:
	
		String representing source feature class (required)
		 
	(1) Input condition fields [inconfields]: 
	
		';'-separated list (String) of field names or a dictionary. List of 
		field names will create a cartesian product of all unique values in the 
		fields (same as ['all']below). 
		
		A dictionary {field_name: [values]} defines which fields and 
		values will be used for conditions. If [values] = [x1, x2, ..., x3]
		then x-values are used as values, if [values] = ['all'] then all values 
		are used (required)
		
	(2) Input value field [invalue]:
	
		String naming the field for output raster values [required]
									  
	(3) Output workspace [outws]:
	
		String path to output workspace (required)
		
	(4) Pixel size [pixelsize]: 
	
		Integer defining the output resolution (required)
	
	(5) Raster type [raster_type]:
		
		String file extension for output raster type (optional)
	
	(6) Fixed extent [extent]: 
	
		String defining a feature class or raster which extent will be used 
		(optional)
		
	(7) Snap raster [snap_raster]:
	
		String defining a raster to which result will be snapped
		(optional)

	"""
    implements(IGISTool)

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        MultiConvertRaster.id = MultiConvertRaster.id + 1
        self.id = MultiConvertRaster.id
        self.name = self.__module__.split('.')[-1]

        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__),
                             debugging=True)

        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1

        self.service = service

        self.log.debug(msgInitSuccess)
Esempio n. 8
0
class Aggregate(ArcTool):
    """ ArcTool for aggregating data to desired resolution while preserving 
    true NoData values.
    
    Tool will create new subfolders into the output workspace according to 
    target resolution if they do not exist.

    Parameters:
    
    (1) Input raster [inraster] 
    
        String representing the source workspace that contains rasters to be
        aggregated (required)
          
    (2) Output raster [outraster] 
        
        String for the location of the resulting rasters (required)
    
    (3) Cell factor [factors] 
        
        Integer cell factor (multiplier) to be used in the aggregation. 
        Original cell size will be taken from the rasters in the input 
        workspace. (required)
    
    (4) Nodata mode [nodata] 
        
        Boolean defining whether NoData mode is used. 
        True -> resulting aggregated rasters will have NoData
        False -> resulting aggregated rasters will not have NoData
        (required, default: True)
    
    (5) Extent [extent]
    
        String containing 'minX minY maxX maxY' that will be passed on
        to Arcpy.Extent class.
        (optional)
          
    (6) Mask (mask)
    
        String representing raster that will be used as a mask (optional)
        
    (7) Raster type [raster_type] 
    
        String file extension for output raster type (optional)
    

    """
    implements(IGISTool)

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        Aggregate.id = Aggregate.id + 1
        self.name = self.__class__.__name__
        # Identifier is a combination of the name and the class counter
        self.id = (self.name, Aggregate.id)
        
        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__), 
                                             debugging=True)
        
        self.log.debug(msgInitStart)
        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1
        
        self.service = service
        
        self.log.debug(msgInitSuccess)
Esempio n. 9
0
class MultiConvertRaster(ArcTool):
	""" ArcTool for converting feature layers to rasters based on multiple
	attribute selections.

	TODO: parameters require a dictionary -> how will this handled by Toolbox
		  GUI?

	Parameters:
	(0) Input feature [infeature]:
	
		String representing source feature class (required)
		 
	(1) Input condition fields [inconfields]: 
	
		';'-separated list (String) of field names or a dictionary. List of 
		field names will create a cartesian product of all unique values in the 
		fields (same as ['all']below). 
		
		A dictionary {field_name: [values]} defines which fields and 
		values will be used for conditions. If [values] = [x1, x2, ..., x3]
		then x-values are used as values, if [values] = ['all'] then all values 
		are used (required)
		
	(2) Input value field [invalue]:
	
		String naming the field for output raster values [required]
									  
	(3) Output workspace [outws]:
	
		String path to output workspace (required)
		
	(4) Pixel size [pixelsize]: 
	
		Integer defining the output resolution (required)
	
	(5) Raster type [raster_type]:
		
		String file extension for output raster type (optional)
	
	(6) Fixed extent [extent]: 
	
		String defining a feature class or raster which extent will be used 
		(optional)
		
	(7) Snap raster [snap_raster]:
	
		String defining a raster to which result will be snapped
		(optional)

	"""
	implements(IGISTool)

	id = 0

	def __init__(self, parameters, service, *args, **kwargs):
		ArcTool.__init__(self, parameters, service, *args, **kwargs)

		MultiConvertRaster.id = MultiConvertRaster.id + 1
		self.id = MultiConvertRaster.id
		self.name = self.__module__.split('.')[-1]
		
		self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__), 
											 debugging=True)
		

		# Tool needs spatial analyst in order to run
		# TODO: this should be moved to ToolValidator
		try:
			self.register_extension('spatial')
		except LicenseError, e:
			self.log.error(e)
			return 1
		
		self.service = service
		
		self.log.debug(msgInitSuccess)
Esempio n. 10
0
class Aggregate(ArcTool):
    """ ArcTool for aggregating data to desired resolution while preserving 
    true NoData values.
    
    Tool will create new subfolders into the output workspace according to 
    target resolution if they do not exist.

    Parameters:
    
    (1) Input raster [inraster] 
    
        String representing the source workspace that contains rasters to be
        aggregated (required)
          
    (2) Output raster [outraster] 
        
        String for the location of the resulting rasters (required)
    
    (3) Cell factor [factors] 
        
        Integer cell factor (multiplier) to be used in the aggregation. 
        Original cell size will be taken from the rasters in the input 
        workspace. (required)
    
    (4) Nodata mode [nodata] 
        
        Boolean defining whether NoData mode is used. 
        True -> resulting aggregated rasters will have NoData
        False -> resulting aggregated rasters will not have NoData
        (required, default: True)
    
    (5) Extent [extent]
    
        String containing 'minX minY maxX maxY' that will be passed on
        to Arcpy.Extent class.
        (optional)
          
    (6) Mask (mask)
    
        String representing raster that will be used as a mask (optional)
        
    (7) Raster type [raster_type] 
    
        String file extension for output raster type (optional)
    

    """
    implements(IGISTool)

    id = 0

    def __init__(self, parameters, service, *args, **kwargs):
        ArcTool.__init__(self, parameters, service, *args, **kwargs)

        Aggregate.id = Aggregate.id + 1
        self.name = self.__class__.__name__
        # Identifier is a combination of the name and the class counter
        self.id = (self.name, Aggregate.id)

        self.log = ArcLogger("Zupport.%s" % (self.__class__.__name__),
                             debugging=True)

        self.log.debug(msgInitStart)
        # Tool needs spatial analyst in order to run
        # TODO: this should be moved to ToolValidator
        try:
            self.register_extension('spatial')
        except LicenseError, e:
            self.log.error(e)
            return 1

        self.service = service

        self.log.debug(msgInitSuccess)