def test_run(self): function = FloodRasterRoadsFunction.instance() hazard_path = standard_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = standard_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', '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 = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent function.run() impact = function.impact keywords = impact.get_keywords() self.assertEquals(function.target_field, keywords['target_field']) expected_inundated_feature = 182 count = sum(impact.get_data(attribute=function.target_field)) self.assertEquals(count, expected_inundated_feature)
def test_run(self): function = FloodRasterRoadsFunction.instance() hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', '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 = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent function.run() impact = function.impact keywords = impact.get_keywords() self.assertEquals(function.target_field, keywords['target_field']) expected_inundated_feature = 182 count = sum(impact.get_data(attribute=function.target_field)) self.assertEquals(count, expected_inundated_feature)
def test_zero_intersection(self): hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path('exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent function = FloodRasterRoadsFunction.instance() rect_extent = [106.831991, -6.170044, 106.834868, -6.167793] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent with self.assertRaises(ZeroImpactException): function.run()
def test_zero_intersection(self): hazard_path = test_data_path( 'hazard', 'continuous_flood_20_20.asc') exposure_path = test_data_path( 'exposure', 'roads.shp') # noinspection PyCallingNonCallable hazard_layer = QgsRasterLayer(hazard_path, 'Flood') # noinspection PyCallingNonCallable exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr') # Let's set the extent to the hazard extent function = FloodRasterRoadsFunction.instance() rect_extent = [106.831991, -6.170044, 106.834868, -6.167793] function.hazard = SafeLayer(hazard_layer) function.exposure = SafeLayer(exposure_layer) function.requested_extent = rect_extent with self.assertRaises(ZeroImpactException): function.run()