Exemplo n.º 1
0
 def testAsWktCoordinates(self):
     """Test that we can get a proper wkt representation fo the rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = ('0 0, ' '5 5')
     myWkt = rect1.asWktCoordinates()
     myMessage = ('Expected: %s\nGot: %s\n' % (myExpectedWkt, myWkt))
     assert compareWkt(myWkt, myExpectedWkt), myMessage
Exemplo n.º 2
0
 def testAsWktCoordinates(self):
     """Test that we can get a proper wkt representation fo the rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = "0 0, " "5 5"
     myWkt = rect1.asWktCoordinates()
     myMessage = "Expected: %s\nGot: %s\n" % (myExpectedWkt, myWkt)
     assert compareWkt(myWkt, myExpectedWkt), myMessage
Exemplo n.º 3
0
 def testAsWktCoordinates(self):
     """Test that we can get a proper wkt representation fo the rect"""
     rect1 = QgsRectangle(0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = '0.0000000000000000 0.0000000000000000, 5.0000000000000000 5.0000000000000000'
     myWkt = rect1.asWktCoordinates()
     myMessage = ('Expected: %s\nGot: %s\n' % (myExpectedWkt, myWkt))
     self.assertEquals(myWkt, myExpectedWkt, myMessage)
Exemplo n.º 4
0
 def testAsWktCoordinates(self):
     """Test that we can get a proper wkt representation fo the rect"""
     rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0)
     myExpectedWkt = '0.0000000000000000 0.0000000000000000, 5.0000000000000000 5.0000000000000000'
     myWkt = rect1.asWktCoordinates()
     myMessage = ('Expected: %s\nGot: %s\n' %
                   (myExpectedWkt, myWkt))
     self.assertEquals(myWkt, myExpectedWkt, myMessage)
Exemplo n.º 5
0
    def run_scenario(self, items):
        """Run a simple scenario.

        :param items: A dictionary containing the scenario configuration
            as table items.
        :type items: dict

        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        LOGGER.info('Run simple task' + str(items))
        scenario_directory = str(self.source_directory.text())

        paths = []
        if 'hazard' in items:
            paths.append(items['hazard'])
        if 'exposure' in items:
            paths.append(items['exposure'])
        if 'aggregation' in items:
            paths.append(items['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.add_layers(scenario_directory, paths, self.iface)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % (
                scenario_directory, paths))
            return False

        # See if we have a preferred impact function
        if 'function' in items:
            function_id = items['function']
            result = scenario_runner.set_function_id(
                function_id, dock=self.dock)
            if not result:
                return False

        if 'aggregation' in items:
            aggregation_path = scenario_runner.extract_path(
                scenario_directory, items['aggregation'])[0]
            result = scenario_runner.set_aggregation_layer(
                aggregation_path, self.dock)
            if not result:
                return False

        # Set extent CRS if it exists
        if 'extent_crs' in items:
            crs = QgsCoordinateReferenceSystem(items['extent_crs'])
        else:
            # assume crs is Geo/WGS84
            crs = QgsCoordinateReferenceSystem('EPSG:4326')
        # set extent if exist
        if 'extent' in items:
            # split extent string
            coordinates = items['extent']
            coordinates = extent_string_to_array(coordinates)

            # set the extent according the value
            self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True)

            extent = QgsRectangle(*coordinates)

            self.dock.define_user_analysis_extent(extent, crs)

            message = 'set layer extent to %s ' % extent.asWktCoordinates()
            LOGGER.info(message)

            self.iface.mapCanvas().setExtent(extent)

        result = scenario_runner.run_scenario(self.dock)

        return result
Exemplo n.º 6
0
    def run_scenario(self, items):
        """Run a simple scenario.

        :param items: A dictionary containing the scenario configuration
            as table items.
        :type items: dict

        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        LOGGER.info('Run simple task' + str(items))
        scenario_directory = str(self.source_directory.text())

        paths = []
        if 'hazard' in items:
            paths.append(items['hazard'])
        if 'exposure' in items:
            paths.append(items['exposure'])
        if 'aggregation' in items:
            paths.append(items['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.add_layers(scenario_directory, paths)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % (
                scenario_directory, paths))
            return False

        # See if we have a preferred impact function
        if 'function' in items:
            function_id = items['function']
            result = scenario_runner.set_function_id(
                function_id, dock=self.dock)
            if not result:
                return False

        if 'aggregation' in items:
            aggregation_path = scenario_runner.extract_path(
                scenario_directory, items['aggregation'])[0]
            result = scenario_runner.set_aggregation_layer(
                aggregation_path, self.dock)
            if not result:
                return False

        # set extent if exist
        if 'extent' in items:
            # split extent string
            coordinates = items['extent'].replace(' ', '').split(',')
            count = len(coordinates)
            if count != 4:
                message = (
                    'Extent need exactly 4 value but got %s instead' % count)
                LOGGER.error(message)
                return False

            # parse the value to float type
            try:
                coordinates = [float(i) for i in coordinates]
            except ValueError as e:
                message = e.message
                LOGGER.error(message)
                return False

            # set the extent according the value
            self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True)

            extent = QgsRectangle(*coordinates)

            message = 'set layer extent to %s ' % extent.asWktCoordinates()
            LOGGER.info(message)

            self.iface.mapCanvas().setExtent(extent)

        result = scenario_runner.run_scenario(self.dock)

        return result
Exemplo n.º 7
0
    def run_scenario(self, items):
        """Run a simple scenario.

        :param items: A dictionary containing the scenario configuration
            as table items.
        :type items: dict

        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        # LOGGER.info('Run simple task' + str(items))
        scenario_directory = str(self.source_directory.text())

        paths = []
        if 'hazard' in items:
            paths.append(items['hazard'])
        if 'exposure' in items:
            paths.append(items['exposure'])
        if 'aggregation' in items:
            paths.append(items['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.add_layers(scenario_directory, paths, self.iface)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % (
                scenario_directory, paths))
            return False

        # See if we have a preferred impact function
        if 'function' in items:
            function_id = items['function']
            result = scenario_runner.set_function_id(
                function_id, dock=self.dock)
            if not result:
                return False

        if 'aggregation' in items:
            aggregation_path = scenario_runner.extract_path(
                scenario_directory, items['aggregation'])[0]
            result = scenario_runner.set_aggregation_layer(
                aggregation_path, self.dock)
            if not result:
                return False

        # Set extent CRS if it exists
        if 'extent_crs' in items:
            crs = QgsCoordinateReferenceSystem(items['extent_crs'])
        else:
            # assume crs is Geo/WGS84
            crs = QgsCoordinateReferenceSystem('EPSG:4326')
        # set extent if exist
        if 'extent' in items:
            # split extent string
            coordinates = items['extent']
            coordinates = extent_string_to_array(coordinates)

            # set the extent according the value
            self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True)

            extent = QgsRectangle(*coordinates)

            self.dock.define_user_analysis_extent(extent, crs)

            message = 'set layer extent to %s ' % extent.asWktCoordinates()
            # LOGGER.info(message)

            self.iface.mapCanvas().setExtent(extent)

        result = scenario_runner.run_scenario(self.dock)

        return result
Exemplo n.º 8
0
    def run_scenario(self, theItem):
        """Run a simple scenario.

        :param theItem: A dictionary contains the scenario configuration.
        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        LOGGER.info('Run simple task' + str(theItem))
        scenarioDirectory = str(self.leSourceDir.text())
        # dummy file
        dummyScenarioFilePath = os.path.join(scenarioDirectory, 'dummy.txt')

        myPaths = []
        if 'hazard' in theItem:
            myPaths.append(theItem['hazard'])
        if 'exposure' in theItem:
            myPaths.append(theItem['exposure'])
        if 'aggregation' in theItem:
            myPaths.append(theItem['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.addLayers(dummyScenarioFilePath, myPaths)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % (
                dummyScenarioFilePath, myPaths))
            return False

        # See if we have a preferred impact function
        if 'function' in theItem:
            myFunctionId = theItem['function']
            myResult = scenario_runner.setFunctionId(
                myFunctionId, theDock=self.dock)
            if not myResult:
                return False

        if 'aggregation' in theItem:
            absAggregationPath = scenario_runner.extractPath(
                dummyScenarioFilePath, theItem['aggregation'])[0]
            myResult = scenario_runner.setAggregationLayer(
                absAggregationPath, self.dock)
            if not myResult:
                return False

        # set extent if exist
        if 'extent' in theItem:
            # split extent string
            myCoordinate = theItem['extent'].replace(' ', '').split(',')
            myCount = len(myCoordinate)
            if myCount != 4:
                myMessage = 'Extent need exactly 4 value but got %s ' \
                            'instead' % myCount
                LOGGER.error(myMessage)
                return False

            # parse the value to float type
            try:
                myCoordinate = [float(i) for i in myCoordinate]
            except ValueError as e:
                myMessage = e.message
                LOGGER.error(myMessage)
                return False

            # set the extent according the value
            myExtent = QgsRectangle(*myCoordinate)

            myMessage = 'set layer extent to %s ' % myExtent.asWktCoordinates()
            LOGGER.info(myMessage)

            self.iface.mapCanvas().setExtent(myExtent)

        myResult = scenario_runner.runScenario(self.dock)

        return myResult
Exemplo n.º 9
0
    def run_scenario(self, theItem):
        """Run a simple scenario.

        :param theItem: A dictionary contains the scenario configuration.
        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        LOGGER.info('Run simple task' + str(theItem))
        scenarioDirectory = str(self.source_directory.text())

        myPaths = []
        if 'hazard' in theItem:
            myPaths.append(theItem['hazard'])
        if 'exposure' in theItem:
            myPaths.append(theItem['exposure'])
        if 'aggregation' in theItem:
            myPaths.append(theItem['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.addLayers(scenarioDirectory, myPaths)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' % (
                scenarioDirectory, myPaths))
            return False

        # See if we have a preferred impact function
        if 'function' in theItem:
            myFunctionId = theItem['function']
            myResult = scenario_runner.setFunctionId(
                myFunctionId, theDock=self.dock)
            if not myResult:
                return False

        if 'aggregation' in theItem:
            absAggregationPath = scenario_runner.extractPath(
                scenarioDirectory, theItem['aggregation'])[0]
            myResult = scenario_runner.setAggregationLayer(
                absAggregationPath, self.dock)
            if not myResult:
                return False

        # set extent if exist
        if 'extent' in theItem:
            # split extent string
            myCoordinate = theItem['extent'].replace(' ', '').split(',')
            myCount = len(myCoordinate)
            if myCount != 4:
                myMessage = 'Extent need exactly 4 value but got %s ' \
                            'instead' % myCount
                LOGGER.error(myMessage)
                return False

            # parse the value to float type
            try:
                myCoordinate = [float(i) for i in myCoordinate]
            except ValueError as e:
                myMessage = e.message
                LOGGER.error(myMessage)
                return False

            # set the extent according the value
            self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True)

            myExtent = QgsRectangle(*myCoordinate)

            myMessage = 'set layer extent to %s ' % myExtent.asWktCoordinates()
            LOGGER.info(myMessage)

            self.iface.mapCanvas().setExtent(myExtent)

        myResult = scenario_runner.runScenario(self.dock)

        return myResult
Exemplo n.º 10
0
    def run_scenario(self, items):
        """Run a simple scenario.

        :param items: A dictionary containing the scenario configuration
            as table items.
        :type items: dict

        :returns: True if success, otherwise return False.
        :rtype: bool
        """
        LOGGER.info('Run simple task' + str(items))
        scenario_directory = str(self.source_directory.text())

        paths = []
        if 'hazard' in items:
            paths.append(items['hazard'])
        if 'exposure' in items:
            paths.append(items['exposure'])
        if 'aggregation' in items:
            paths.append(items['aggregation'])

        # always run in new project
        self.iface.newProject()

        try:
            scenario_runner.add_layers(scenario_directory, paths)
        except FileNotFoundError:
            # set status to 'fail'
            LOGGER.exception('Loading layers failed: \nRoot: %s\n%s' %
                             (scenario_directory, paths))
            return False

        # See if we have a preferred impact function
        if 'function' in items:
            function_id = items['function']
            result = scenario_runner.set_function_id(function_id,
                                                     dock=self.dock)
            if not result:
                return False

        if 'aggregation' in items:
            aggregation_path = scenario_runner.extract_path(
                scenario_directory, items['aggregation'])[0]
            result = scenario_runner.set_aggregation_layer(
                aggregation_path, self.dock)
            if not result:
                return False

        # set extent if exist
        if 'extent' in items:
            # split extent string
            coordinates = items['extent'].replace(' ', '').split(',')
            count = len(coordinates)
            if count != 4:
                message = ('Extent need exactly 4 value but got %s instead' %
                           count)
                LOGGER.error(message)
                return False

            # parse the value to float type
            try:
                coordinates = [float(i) for i in coordinates]
            except ValueError as e:
                message = e.message
                LOGGER.error(message)
                return False

            # set the extent according the value
            self.iface.mapCanvas().mapRenderer().setProjectionsEnabled(True)

            extent = QgsRectangle(*coordinates)

            message = 'set layer extent to %s ' % extent.asWktCoordinates()
            LOGGER.info(message)

            self.iface.mapCanvas().setExtent(extent)

        result = scenario_runner.run_scenario(self.dock)

        return result