コード例 #1
0
    def test_aggregate_raster_values_all_polys(self):
        """PyGeoprocessing: test aggregate raster values as a lump."""
        import pygeoprocessing

        base_raster_path = os.path.join(TEST_DATA,
                                        'aggregate_raster_values_data',
                                        'base_raster.tif')
        shapefile_path = os.path.join(TEST_DATA,
                                      'aggregate_raster_values_data',
                                      'watershed.shp')

        result = pygeoprocessing.aggregate_raster_values_uri(
            base_raster_path, shapefile_path)

        expected_result = pygeoprocessing.AggregatedValues(
            total={9999: 398428.0},
            pixel_mean={9999: 1.0},
            hectare_mean={9999: 11.111194773692587},
            n_pixels={9999: 398428.0},
            pixel_min={9999: 1.0},
            pixel_max={9999: 1.0})

        for metric in [
                'total', 'pixel_mean', 'hectare_mean', 'n_pixels', 'pixel_min',
                'pixel_max'
        ]:
            _assert_deep_almost_equal(self,
                                      getattr(expected_result, metric),
                                      getattr(result, metric),
                                      places=6)
コード例 #2
0
    def test_aggregate_raster_values_include_nodata(self):
        """PyGeoprocessing: test aggregate raster values, include nodata."""
        import pygeoprocessing

        base_raster_path = os.path.join(TEST_DATA,
                                        'aggregate_raster_values_data',
                                        'base_raster.tif')

        shapefile_path = os.path.join(TEST_DATA,
                                      'aggregate_raster_values_data',
                                      'overlap_watershed.shp')

        result = pygeoprocessing.aggregate_raster_values_uri(
            base_raster_path,
            shapefile_path,
            shapefile_field='DN',
            all_touched=False,
            polygons_might_overlap=True,
            ignore_nodata=False)

        expected_result = pygeoprocessing.AggregatedValues(
            total={
                1: 3.0,
                2: 398425.0,
                3: 5.0
            },
            pixel_mean={
                1: 1.0,
                2: 1.0,
                3: 0.41666666666666669
            },
            hectare_mean={
                1: 11.111111110950143,
                2: 11.111111110937156,
                3: 3.6282805923682009
            },
            n_pixels={
                1: 3.0,
                2: 398425.0,
                3: 12.0
            },
            pixel_min={
                1: 1.0,
                2: 1.0,
                3: 1.0
            },
            pixel_max={
                1: 1.0,
                2: 1.0,
                3: 1.0
            })

        for metric in [
                'total', 'pixel_mean', 'hectare_mean', 'n_pixels', 'pixel_min',
                'pixel_max'
        ]:
            _assert_deep_almost_equal(self,
                                      getattr(expected_result, metric),
                                      getattr(result, metric),
                                      places=6)