def _get_layer(self, layer): """Analyze style of self._function and return appropriate class of the layer. :param layer: A layer. :type layer: QgsMapLayer or SAFE layer. :returns: The layer of appropriate type :rtype: SAFE or QgisWrapper :raises: InsufficientParametersError if self._function is not set, InvalidParameterError if style of self._function is not in ('old-style', 'qgis2.0') Any exceptions raised by other libraries will be propogated. """ if self._function is None or self._function == '': message = self.tr('Error: Function not set.') raise InsufficientParametersError(message) # Get type of the impact function (old-style or new-style) try: func_type = getSafeImpactFunctionType(self._function) if func_type == 'old-style': return convertToSafeLayer(layer) elif func_type == 'qgis2.0': # convert for new style impact function return QgisWrapper(layer) else: message = self.tr('Error: Function has unknown style.') raise InvalidParameterError(message) except: raise
def requires_clipping(self): """Check to clip or not to clip layers. If self._function is a 'new-style' impact function, then return False -- clipping is unnecessary, else return True :returns: To clip or not to clip. :rtype: bool :raises: InsufficientParametersError if function parameter is not set. InvalidParameterError if the function has unknown style. """ f = self.function() if f is None: message = self.tr('Error: Function is not provided.') raise InsufficientParametersError(message) style = getSafeImpactFunctionType(f) if style == 'old-style': return True elif style == 'qgis2.0': return False else: message = self.tr('Error: Function has unknown style.') raise InvalidParameterError(message)
def _convert_layer(self, layer): """Analyze style of self._function and return appropriate class of the layer. :param layer: A layer. :type layer: QgsMapLayer or SAFE layer. :returns: The layer of appropriate type :rtype: convertToSafeLayer :raises: InsufficientParametersError if self._function is not set, InvalidParameterError if style of self._function is not in ('old-style', 'qgis2.0') Any exceptions raised by other libraries will be propogated. """ # FIXME (DK): I'm not sure that it is good place for the # converting function. May be safe_qgis.safe_interface is better. # But I don't like pass information about function style to other # modules: I prefer keep only one place of function style analysis if self._function is None or self._function == '': message = self.tr('Error: Function not set.') raise InsufficientParametersError(message) # Get type of the impact function (old-style or new-style) try: func_type = getSafeImpactFunctionType(self._function) if func_type == 'old-style': return convertToSafeLayer(layer) elif func_type == 'qgis2.0': # TODO (DK): convert for new style impact function return convertToSafeLayer(layer) else: message = self.tr('Error: Function has unknown style.') raise InvalidParameterError(message) except: raise