Esempio n. 1
0
    def run(self):
        """ Main function for hazard impact calculation thread.
        Requires three properties to be set before execution
        can take place:

        * Hazard layer - a path to a raster,
        * Exposure layer - a path to a vector points layer.
        * Function - a function that defines how the Hazard assessment
          will be computed.

        After the thread is complete, you can use the filename and
        result accessors to determine what the result of the analysis was::

          calculator = ImpactCalculator()
          rasterPath = os.path.join(TESTDATA, 'xxx.asc')
          vectorPath = os.path.join(TESTDATA, 'xxx.shp')
          calculator.setHazardLayer(self.rasterPath)
          calculator.setExposureLayer(self.vectorPath)
          calculator.setFunction('Flood Building Impact Function')
          myRunner = calculator.getRunner()
          #wait till completion
          myRunner.join()
          myResult = myRunner.result()
          myFilename = myRunner.filename()


        Args:
           None.
        Returns:
           None
        Raises:
           InsufficientParametersError
           set.
        """
        if (self._hazardLayer is None) or \
                (self._exposureLayer is None) or \
                (self._function is None):
            myMessage = self.tr('Ensure that hazard, exposure and function '
                                'are all set before trying to run the '
                                'analysis.')
            raise InsufficientParametersError(myMessage)
        try:
            myLayers = [self._hazardLayer, self._exposureLayer]
            self._impactLayer = calculateSafeImpact(theLayers=myLayers,
                                                    theFunction=self._function)
        except MemoryError, e:
            myMessage = self.tr(
                'An error occurred because it appears that '
                'your system does not have sufficient memory. Upgrading '
                'your computer so that it has more memory may help. '
                'Alternatively, consider using a smaller geographical '
                'area for your analysis, or using rasters with a larger '
                'cell size.')
            self._exception = e
            self._traceback = traceback.format_tb(sys.exc_info()[2])
            self._result = myMessage
            LOGGER.exception(myMessage)
    def run(self):
        """ Main function for hazard impact calculation thread.
        Requires three properties to be set before execution
        can take place:

        * Hazard layer - a path to a raster,
        * Exposure layer - a path to a vector points layer.
        * Function - a function that defines how the Hazard assessment
          will be computed.

        After the thread is complete, you can use the filename and
        result accessors to determine what the result of the analysis was::

          calculator = ImpactCalculator()
          rasterPath = os.path.join(TESTDATA, 'xxx.asc')
          vectorPath = os.path.join(TESTDATA, 'xxx.shp')
          calculator.setHazardLayer(self.rasterPath)
          calculator.setExposureLayer(self.vectorPath)
          calculator.setFunction('Flood Building Impact Function')
          myRunner = calculator.getRunner()
          #wait till completion
          myRunner.join()
          myResult = myRunner.result()
          myFilename = myRunner.filename()


        Args:
           None.
        Returns:
           None
        Raises:
           InsufficientParametersError
           set.
        """
        if (self._hazardLayer is None or self._exposureLayer is None
            or self._function is None):
            myMessage = self.tr('Ensure that hazard, exposure and function '
                                'are all set before trying to run the '
                                'analysis.')
            raise InsufficientParametersError(myMessage)
        try:
            myLayers = [self._hazardLayer, self._exposureLayer]
            self._impactLayer = calculateSafeImpact(theLayers=myLayers,
                                        theFunction=self._function)
        except MemoryError, e:
            myMessage = self.tr('An error occurred because it appears that '
                    'your system does not have sufficient memory. Upgrading '
                    'your computer so that it has more memory may help. '
                    'Alternatively, consider using a smaller geographical '
                    'area for your analysis, or using rasters with a larger '
                    'cell size.')
            self._exception = e
            self._traceback = traceback.format_tb(sys.exc_info()[2])
            self._result = myMessage
            LOGGER.exception(myMessage)
    def run(self):
        """ Main function for hazard impact calculation thread.
        Requires three properties to be set before execution
        can take place:

        * Hazard layer - a path to a raster,
        * Exposure layer - a path to a vector points layer.
        * Function - a function that defines how the Hazard assessment
          will be computed.

        After the thread is complete, you can use the filename and
        result accessors to determine what the result of the analysis was::

          calculator = ImpactCalculator()
          rasterPath = os.path.join(TESTDATA, 'xxx.asc')
          vectorPath = os.path.join(TESTDATA, 'xxx.shp')
          calculator.setHazardLayer(self.rasterPath)
          calculator.setExposureLayer(self.vectorPath)
          calculator.setFunction('Flood Building Impact Function')
          myRunner = calculator.getRunner()
          #wait till completion
          myRunner.join()
          myResult = myRunner.result()
          myFilename = myRunner.filename()


        Args:
           None.
        Returns:
           None
        Raises:
           InsufficientParametersException
           set.
        """
        if (self._hazardLayer is None or self._exposureLayer is None
                or self._function is None):
            myMessage = self.tr('Ensure that hazard, exposure and function '
                                'are all set before trying to run the '
                                'analysis.')
            raise InsufficientParametersException(myMessage)
        try:
            myLayers = [self._hazardLayer, self._exposureLayer]
            self._impactLayer = calculateSafeImpact(theLayers=myLayers,
                                                    theFunction=self._function)
        # Catch and handle all exceptions:
        # pylint: disable=W0703
        except Exception, e:
            myMessage = self.tr('Calculation error encountered:\n')
            #store the exception so that controller class can get it later
            self._exception = e
            self._traceback = traceback.format_tb(sys.exc_info()[2])
            print myMessage
            self._result = myMessage
Esempio n. 4
0
    def run(self):
        """ Main function for hazard impact calculation thread.
        Requires three properties to be set before execution
        can take place:

        * Hazard layer - a path to a raster,
        * Exposure layer - a path to a vector points layer.
        * Function - a function that defines how the Hazard assessment
          will be computed.

        After the thread is complete, you can use the filename and
        result accessors to determine what the result of the analysis was::

          calculator = ImpactCalculator()
          rasterPath = os.path.join(TESTDATA, 'xxx.asc')
          vectorPath = os.path.join(TESTDATA, 'xxx.shp')
          calculator.setHazardLayer(self.rasterPath)
          calculator.setExposureLayer(self.vectorPath)
          calculator.setFunction('Flood Building Impact Function')
          myRunner = calculator.getRunner()
          #wait till completion
          myRunner.join()
          myResult = myRunner.result()
          myFilename = myRunner.filename()


        Args:
           None.
        Returns:
           None
        Raises:
           InsufficientParametersException
           set.
        """
        if self._hazardLayer is None or self._exposureLayer is None or self._function is None:
            myMessage = self.tr(
                "Ensure that hazard, exposure and function " "are all set before trying to run the " "analysis."
            )
            raise InsufficientParametersException(myMessage)
        try:
            myLayers = [self._hazardLayer, self._exposureLayer]
            self._impactLayer = calculateSafeImpact(theLayers=myLayers, theFunction=self._function)
        # Catch and handle all exceptions:
        # pylint: disable=W0703
        except Exception, e:
            myMessage = self.tr("Calculation error encountered:\n")
            # store the exception so that controller class can get it later
            self._exception = e
            self._traceback = traceback.format_tb(sys.exc_info()[2])
            print myMessage
            self._result = myMessage