我正在使用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以及具有不正確值的輸出,如下所示:輸出柵格
添加回答
舉報
0/150
提交
取消