Example #1
0
    def test_run(self):
        function = FloodPolygonBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        # exposure_path = test_data_path('exposure', 'buildings.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        # exposure_layer = QgsVectorLayer(exposure_path, 'Buildings', 'ogr')

        exposure_layer = clone_shp_layer(
            name='buildings',
            include_keywords=True,
            source_directory=test_data_path('exposure'))
        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(),
            extent.yMaximum(),
            extent.xMaximum(),
            extent.yMinimum()
        ]

        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.requested_extent = rect_extent
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # total flooded = 27, total buildings = 129
        count = sum(impact.get_data(attribute=function.target_field))
        self.assertEquals(count, 33)
        count = len(impact.get_data())
        self.assertEquals(count, 176)
    def test_run(self):
        function = FloodPolygonBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        # exposure_path = test_data_path('exposure', 'buildings.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        # exposure_layer = QgsVectorLayer(exposure_path, 'Buildings', 'ogr')

        exposure_layer = clone_shp_layer(
            name='buildings',
            include_keywords=True,
            source_directory=test_data_path('exposure'))
        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.requested_extent = rect_extent
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # total flooded = 27, total buildings = 129
        count = sum(impact.get_data(attribute=function.target_field))
        self.assertEquals(count, 33)
        count = len(impact.get_data())
        self.assertEquals(count, 176)
    def test_run(self):
        function = FloodPolygonBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        exposure_path = test_data_path('exposure', 'buildings.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Buildings', 'ogr')

        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = QgisWrapper(hazard_layer)
        function.exposure = QgisWrapper(exposure_layer)
        function.requested_extent = rect_extent
        function.parameters['building_type_field'] = 'TYPE'
        function.parameters['affected_field'] = 'FLOODPRONE'
        function.parameters['affected_value'] = 'YES'
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # total flooded = 27, total buildings = 129
        count = sum(impact.get_data(attribute='INUNDATED'))
        self.assertEquals(count, 33)
        count = len(impact.get_data())
        self.assertEquals(count, 176)