Esempio n. 1
0
 def test_zonal_with_exact_cell_boundaries(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(os.path.join(
         UNITDATA, '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(os.path.join(
         UNITDATA, '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)
Esempio n. 2
0
 def test_zonal_with_exact_cell_boundaries(self):
     """Test that zonal stats returns the expected output."""
     myRasterLayer, _ = load_layer(os.path.join(
         UNITDATA, 'other', 'tenbytenraster.asc'))
     # Note this is a matrix of 11x11 polys - one per cell
     # and one poly extending beyond to the right of each row
     # and one poly extending beyond the bottom of each col
     myVectorLayer, _ = load_layer(os.path.join(
         UNITDATA, 'other', 'ten_by_ten_raster_as_polys.shp'))
     myResult = calculate_zonal_stats(
         raster_layer=myRasterLayer,
         polygon_layer=myVectorLayer)
     myExpectedResult = {
         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
     myResult = {
         0L: myResult[0L],
         9L: myResult[9L],
         25L: myResult[25L],
         88L: myResult[88L],
         108L: myResult[108L]}
     self.maxDiff = None
     self.assertDictEqual(myExpectedResult, myResult)
Esempio n. 3
0
 def test_zonal(self):
     """Test that zonal stats returns the expected output."""
     myRasterLayer, _ = load_layer(os.path.join(
         UNITDATA, 'other', 'tenbytenraster.asc'))
     myVectorLayer, _ = load_layer(os.path.join(
         UNITDATA, 'other', 'zonal_polygons.shp'))
     myResult = calculate_zonal_stats(
         raster_layer=myRasterLayer,
         polygon_layer=myVectorLayer)
     myExpectedResult = {
         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
     self.maxDiff = None
     self.assertDictEqual(myExpectedResult, myResult)
Esempio n. 4
0
 def test_zonal(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(os.path.join(
         UNITDATA, 'other', 'tenbytenraster.asc'))
     vector_layer, _ = load_layer(os.path.join(
         UNITDATA, '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)
Esempio n. 5
0
 def test_zonal(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         os.path.join(UNITDATA, 'other', 'tenbytenraster.asc'))
     vector_layer, _ = load_layer(
         os.path.join(UNITDATA, '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)