def test_zonal_with_exact_cell_boundaries(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         test_data_path('other', 'tenbytenraster.asc'))
     # Note this is a matrix of 11x11 polygons - one per cell
     # and one poly extending beyond to the right of each row
     # and one poly extending beyond the bottom of each col
     vector_layer, _ = load_layer(
         test_data_path('other', 'ten_by_ten_raster_as_polys.shp'))
     result = calculate_zonal_stats(
         raster_layer=raster_layer,
         polygon_layer=vector_layer)
     expected_result = {
         0L: {'count': 1.0, 'sum': 0.0, 'mean': 0.0},  # TL polygon
         9L: {'count': 1.0, 'sum': 9.0, 'mean': 9.0},  # TR polygon
         25L: {'count': 1.0, 'sum': 3.0, 'mean': 3.0},  # Central polygon
         88L: {'count': 1.0, 'sum': 0.0, 'mean': 0.0},  # BL polygon
         108L: {'count': 1.0, 'sum': 9.0, 'mean': 9.0}}  # BR polygon
     # We will just check TL, TR, Middle, BL and BR cells
     result = {
         0L: result[0L],
         9L: result[9L],
         25L: result[25L],
         88L: result[88L],
         108L: result[108L]}
     # noinspection PyPep8Naming
     self.maxDiff = None
     self.assertDictEqual(expected_result, result)
Beispiel #2
0
 def test_zonal_with_exact_cell_boundaries(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         test_data_path('other', 'tenbytenraster.asc'))
     # Note this is a matrix of 11x11 polygons - one per cell
     # and one poly extending beyond to the right of each row
     # and one poly extending beyond the bottom of each col
     vector_layer, _ = load_layer(
         test_data_path('other', 'ten_by_ten_raster_as_polys.shp'))
     result = calculate_zonal_stats(raster_layer=raster_layer,
                                    polygon_layer=vector_layer)
     expected_result = {
         0L: {
             'count': 1.0,
             'sum': 0.0,
             'mean': 0.0
         },  # TL polygon
         9L: {
             'count': 1.0,
             'sum': 9.0,
             'mean': 9.0
         },  # TR polygon
         25L: {
             'count': 1.0,
             'sum': 3.0,
             'mean': 3.0
         },  # Central polygon
         88L: {
             'count': 1.0,
             'sum': 0.0,
             'mean': 0.0
         },  # BL polygon
         108L: {
             'count': 1.0,
             'sum': 9.0,
             'mean': 9.0
         }
     }  # BR polygon
     # We will just check TL, TR, Middle, BL and BR cells
     result = {
         0L: result[0L],
         9L: result[9L],
         25L: result[25L],
         88L: result[88L],
         108L: result[108L]
     }
     # noinspection PyPep8Naming
     self.maxDiff = None
     self.assertDictEqual(expected_result, result)
 def test_zonal(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         test_data_path('other', 'tenbytenraster.asc'))
     vector_layer, _ = load_layer(
         test_data_path('other', 'zonal_polygons.shp'))
     result = calculate_zonal_stats(
         raster_layer=raster_layer,
         polygon_layer=vector_layer)
     expected_result = {
         0L: {'count': 4, 'sum': 34.0, 'mean': 8.5},  # BR polygon
         1L: {'count': 9, 'sum': 36.0, 'mean': 4.0},  # center polygon
         2L: {'count': 4, 'sum': 2.0, 'mean': 0.5},  # TL polygon
         3L: {'count': 4, 'sum': 2.0, 'mean': 0.5},  # BL Polygon
         4L: {'count': 4, 'sum': 34.0, 'mean': 8.5}}  # TR polygon
     # noinspection PyPep8Naming
     self.maxDiff = None
     self.assertDictEqual(expected_result, result)
Beispiel #4
0
 def test_zonal(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         test_data_path('other', 'tenbytenraster.asc'))
     vector_layer, _ = load_layer(
         test_data_path('other', 'zonal_polygons.shp'))
     result = calculate_zonal_stats(raster_layer=raster_layer,
                                    polygon_layer=vector_layer)
     expected_result = {
         0L: {
             'count': 4,
             'sum': 34.0,
             'mean': 8.5
         },  # BR polygon
         1L: {
             'count': 9,
             'sum': 36.0,
             'mean': 4.0
         },  # center polygon
         2L: {
             'count': 4,
             'sum': 2.0,
             'mean': 0.5
         },  # TL polygon
         3L: {
             'count': 4,
             'sum': 2.0,
             'mean': 0.5
         },  # BL Polygon
         4L: {
             'count': 4,
             'sum': 34.0,
             'mean': 8.5
         }
     }  # TR polygon
     # noinspection PyPep8Naming
     self.maxDiff = None
     self.assertDictEqual(expected_result, result)