0

我正在使用gdal.RasterizeLayer()GeoTiff 模板将 shapefile 转换为 GeoTiff,同时通过ATTRIBUTE. 我要输出的是一个 .tif,其中的 burn 值对应于给定属性的值。我发现它gdal.RasterizeLayer()正在燃烧为与我的属性字段中的值不对应的奇怪值。这是我目前拥有的:

    gdalformat = 'GTiff'
    datatype = gdal.GDT_Byte

    # Open Shapefile
    shapefile = ogr.Open(self.filename)
    shapefile_layer = shapefile.GetLayer()
    # Get projection info from reference image
    image = gdal.Open(ref_image, gdal.GA_ReadOnly)
    output = gdal.GetDriverByName(gdalformat).Create(output_tif, image.RasterXSize, image.RasterYSize, 1, datatype,
                                                     options=['COMPRESS=DEFLATE'])
    output.SetProjection(image.GetProjectionRef())
    output.SetGeoTransform(image.GetGeoTransform())

    # Write data to band 1
    band = output.GetRasterBand(1)
    band.SetNoDataValue(0)
    gdal.RasterizeLayer(output, [1], shapefile_layer, options=['ATTRIBUTE=FCode'])

    # Close datasets
    band = None
    output = None
    image = None
    shapefile = None

    # Build image overviews
    subprocess.call("gdaladdo --config COMPRESS_OVERVIEW DEFLATE " + output_tif + " 2 4 8 16 32 64", shell=True)

发生的情况是输出 .tif 为每个属性正确分配了不同的烧录值,但该值与属性值不对应。例如,输入属性值 FCode=46006 变成燃烧值 182(不清楚为什么!)。我尝试添加和删除该'COMPRESS=DEFLATE'选项,并添加和删除gdal.RasterizeLayer(). 无影响输出燃烧值。

您可以在此处查看输入 shapefile 和属性值:输入 .shp

输出的值不正确,在这里:输出栅格

4

1 回答 1

0

我通过将类型更改为gdal.GDT_Int32.

于 2020-03-09T22:14:34.357 回答