利用GDAL计算山体阴影时报错“Received a NULL pointer”。
ERROR 4: `E:\高分数据备份\水利高分二期20220328\水利高分二期20220328\DSM\绥德吴堡demclip.tif' not recognized as a supported file format.
Traceback (most recent call last):
File "E:/gaofen/xunhuan.py", line 102, in <module>
hill135 = gdal.DEMProcessing(outputhill135,outdem, "hillshade", azimuth=135, altitude=45, zFactor=1)
File "D:\Software\Conda\envs\python37\lib\site-packages\osgeo\gdal.py", line 942, in DEMProcessing
return DEMProcessingInternal(destName, srcDS, processing, colorFilename, opts, callback, callback_data)
File "D:\Software\Conda\envs\python37\lib\site-packages\osgeo\gdal.py", line 4255, in DEMProcessingInternal
return _gdal.DEMProcessingInternal(*args)
ValueError: Received a NULL pointer.
原始代码:
outdem=r'E:\gaofen\demclip.tif'
dataset1 = driver.Create(outdem, column, row, 1, gdal.GDT_Float32)
transform1=(xmin, 2.5, 0.0, ymax, 0.0, -2.5)
dataset1.SetGeoTransform(transform1) # 写入仿射变换参数
dataset1.SetProjection(projection) # 写入投影
dataset1.GetRasterBand(1).WriteArray(clip_mask1)
gdal.DEMProcessing(r"E:\gaofen\hill315.tif", outdem, "hillshade", azimuth=315,
altitude=45, zFactor=0.9996)
gdal.DEMProcessing中的dem输入的是文件路径,报错ValueError: Received a NULL pointer.
后来将其改为dataset1之后就可以成功运行了
修改之后代码:
outdem=r'E:\gaofen\demclip.tif'
dataset1 = driver.Create(outdem, column, row, 1, gdal.GDT_Float32)
transform1=(xmin, 2.5, 0.0, ymax, 0.0, -2.5)
dataset1.SetGeoTransform(transform1) # 写入仿射变换参数
dataset1.SetProjection(projection) # 写入投影
dataset1.GetRasterBand(1).WriteArray(clip_mask1)
gdal.DEMProcessing(r"E:\gaofen\hill315.tif", dataset1, "hillshade", azimuth=315,
altitude=45, zFactor=0.9996)