首页 > 解决方案 > PyGeoprocessing 库中允许重新分类栅格值的函数是什么?

问题描述

我正在尝试使用 QGIS Reclassify by Table 重新分类栅格值,但它正在下降。我遇到了 PyGeoprocessing 库,显然它比 R 重新分类函数快得多。但是,我在任何地方都找不到该库的文档或教程。

谢谢您的帮助

标签: raster

解决方案


PyGeoProcessing 的重分类函数被调用reclassify_raster,可以这样调用:

import pygeoprocessing
from osgeo import gdal

raster_path = 'the/path/to/your/input/raster.tif'

# You'll need to load your source and destination pixel values into a dictionary
# like this.  Oftentimes, this will be loaded in from a table.
reclassification_map = {
    1: 0.35
    2: 0.6
}


pygeoprocessing.reclassify_raster(
    (raster_path, 1),  # Use band 1
    reclassification_map,
    'reclassified.tif',
    gdal.GDT_Float32,  # You could use any gdal.GDT_* datatype, this example just uses Float32
    target_nodata=-1  # You could set the nodata value to whatever you wanted it to be
)

It's possible that the maintainers might release some API documentation, but until they do that, you can always just take a look at the function docstrings.  `reclassify_raster`, for example, is found in this file: https://github.com/natcap/pygeoprocessing/blob/main/src/pygeoprocessing/geoprocessing.py

推荐阅读