【GDAL计算山体阴影时报错“Received a NULL pointer”解决办法】

利用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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值