我正在使用GeoTiff模板将形状文件转换为GeoTiff,同时通过刻录输出值。我想输出的是一个.tif,其中刻录值对应于给定属性的值。我发现这是烧焦到与我的属性字段中的值不对应的奇怪值。以下是我目前拥有的内容:gdal.RasterizeLayer()ATTRIBUTEgdal.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(不清楚为什么!我尝试添加和删除该选项,并添加和删除的“ 3D”选项。不影响输出刻录值。'COMPRESS=DEFLATE'gdal.RasterizeLayer()
您可以在此处查看输入形状文件和属性值:输入 .shp
以及具有不正确值的输出,如下所示:输出栅格
HUWWW
相关分类