def test_run(self):
        """TestClassifiedPolygonPeopleFunction: Test running the IF."""

        # 1. Initializing function with necessary data
        function = ClassifiedPolygonHazardPolygonPeopleFunction.instance()

        hazard_path = test_data_path(
                'hazard', 'classified_generic_polygon.shp')
        exposure_path = test_data_path('exposure', 'census.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Hazard', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Exposure', 'ogr')

        # 1.1 Asserting if the provided data are valid
        self.assertEqual(hazard_layer.isValid(), True)
        self.assertEqual(exposure_layer.isValid(), True)

        # 2.Choosing the extent to run analysis
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.requested_extent = rect_extent

        # 3. Running the analysis
        function.run()
        impact = function.impact

        impact = safe_to_qgis_layer(impact)

        # Asserting for the number of features in the impact
        # layer

        self.assertEqual(impact.dataProvider().featureCount(), 6L)

        # 4. Asserting about the results found
        features = {}
        for feature in impact.getFeatures():
            area = feature.geometry().area() * 1e8
            features[feature['id']] = round(area, 1)

        # expected features changes accordingly
        # to the impact features
        expected_features = {
            1: 6438.5,
            2: 5894.1,
            3: 8534.3
        }
        self.assertEqual(features, expected_features)
        expected_results = [
            [u'High Hazard Zone', 7271.431538053051],
            [u'Medium Hazard Zone', 72852.05080801852],
            [u'Low Hazard Zone', 11459.170311153292],
            [u'Total affected people', 91583.0],
            [u'Unaffected people', 17269.0],
            [u'Total people', 108852]
        ]

        result = function.generate_data()['impact summary']['fields']

        for expected_result in expected_results:
            self.assertIn(expected_result, result)
예제 #2
0
    def test_run(self):
        """TestClassifiedPolygonPeopleFunction: Test running the IF."""

        # 1. Initializing function with necessary data
        function = ClassifiedPolygonHazardPolygonPeopleFunction.instance()

        hazard_path = standard_data_path('hazard',
                                         'classified_generic_polygon.shp')
        exposure_path = standard_data_path('exposure', 'census.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Hazard', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Exposure', 'ogr')

        # 1.1 Asserting if the provided data are valid
        self.assertEqual(hazard_layer.isValid(), True)
        self.assertEqual(exposure_layer.isValid(), True)

        # 2.Choosing the extent to run analysis
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(),
            extent.yMaximum(),
            extent.xMaximum(),
            extent.yMinimum()
        ]

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.requested_extent = rect_extent

        # 3. Running the analysis
        function.run()
        impact = function.impact

        impact = safe_to_qgis_layer(impact)

        # Asserting for the number of features in the impact
        # layer

        self.assertEqual(impact.dataProvider().featureCount(), 6L)

        # 4. Asserting about the results found
        features = {}
        for feature in impact.getFeatures():
            area = feature.geometry().area() * 1e8
            features[feature['id']] = round(area, 1)

        # expected features changes accordingly
        # to the impact features
        expected_features = {1: 6438.5, 2: 5894.1, 3: 8534.3}
        self.assertEqual(features, expected_features)
        expected_results = [[u'High Hazard Zone', 7271.431538053051],
                            [u'Medium Hazard Zone', 72852.05080801852],
                            [u'Low Hazard Zone', 11459.170311153292],
                            [u'Total affected people', 91583.0],
                            [u'Unaffected people', 17269.0],
                            [u'Total people', 108852]]

        result = function.generate_data()['impact summary']['fields']

        for expected_result in expected_results:
            self.assertIn(expected_result, result)
    def test_run(self):
        """TestClassifiedPolygonPeopleFunction: Test running the IF."""

        # 1. Initializing function with necessary data
        function = ClassifiedPolygonHazardPolygonPeopleFunction.instance()

        hazard_path = test_data_path(
                'hazard', 'classified_generic_polygon.shp')
        exposure_path = test_data_path('exposure', 'census.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Hazard', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Exposure', 'ogr')

        # 1.1 Asserting if the provided data are valid
        self.assertEqual(hazard_layer.isValid(), True)
        self.assertEqual(exposure_layer.isValid(), True)

        # 2.Choosing the extent to run analysis
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.requested_extent = rect_extent

        # 3. Running the analysis
        function.run()
        impact = function.impact

        impact = safe_to_qgis_layer(impact)

        # Asserting for the number of features in the impact
        # layer

        self.assertEqual(impact.dataProvider().featureCount(), 6L)

        # 4. Asserting about the results found
        features = {}
        for feature in impact.getFeatures():
            area = feature.geometry().area() * 1e8
            features[feature['id']] = round(area, 1)

        # expected features changes accordingly
        # to the impact features
        expected_features = {
            1: 6438.5,
            2: 5894.1,
            3: 8534.3
        }
        self.assertEqual(features, expected_features)
        expected_impact_summary = [
            '**High Hazard Zone**, 4,600------',
            '**Medium Hazard Zone**, 65,700------',
            '**Low Hazard Zone**, 11,500------',
            '**Total affected people**, 81,600------',
            '**Unaffected people**, 17,300------',
            '**Total people**, 98,900---'
        ]
        for row in expected_impact_summary:
            self.assertIn(row, function.impact_summary().to_text())
예제 #4
0
    def test_run(self):
        """TestClassifiedPolygonPeopleFunction: Test running the IF."""

        # 1. Initializing function with necessary data
        function = ClassifiedPolygonHazardPolygonPeopleFunction.instance()

        hazard_path = test_data_path('hazard',
                                     'classified_generic_polygon.shp')
        exposure_path = test_data_path('exposure', 'census.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Hazard', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Exposure', 'ogr')

        # 1.1 Asserting if the provided data are valid
        self.assertEqual(hazard_layer.isValid(), True)
        self.assertEqual(exposure_layer.isValid(), True)

        # 2.Choosing the extent to run analysis
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(),
            extent.yMaximum(),
            extent.xMaximum(),
            extent.yMinimum()
        ]

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.requested_extent = rect_extent

        # 3. Running the analysis
        function.run()
        impact = function.impact

        impact = safe_to_qgis_layer(impact)

        # Asserting for the number of features in the impact
        # layer

        self.assertEqual(impact.dataProvider().featureCount(), 6L)

        # 4. Asserting about the results found
        features = {}
        for feature in impact.getFeatures():
            area = feature.geometry().area() * 1e8
            features[feature['id']] = round(area, 1)

        # expected features changes accordingly
        # to the impact features
        expected_features = {1: 6438.5, 2: 5894.1, 3: 8534.3}
        self.assertEqual(features, expected_features)
        expected_impact_summary = [
            '**High Hazard Zone**, 4,600------',
            '**Medium Hazard Zone**, 65,700------',
            '**Low Hazard Zone**, 11,500------',
            '**Total affected people**, 81,600------',
            '**Unaffected people**, 17,300------',
            '**Total people**, 98,900---'
        ]
        for row in expected_impact_summary:
            self.assertIn(row, function.impact_summary().to_text())