使用 GDAL 1.6.1 创建 CFloat64 ENVI 文件时出现问题
我正在尝试使用 GDAL 写入 ENVI CFloat64 文件:
import numpy
from osgeo import gdal
from osgeo.gdalconst import GDT_CFloat64
a = numpy.zeros((1000, 1000), dtype='complex64')
driver = gdal.GetDriverByName("ENVI")
outfile = driver.Create("test.bin", 1000, 1000, 1, GDT_CFloat64)
outfile.GetRasterBand(1).WriteArray(a, 0, 0)
outfile = None
但无法将数组写入 outfile.GetRasterBand(1).WriteArray(a, 0, 0)
中的带区,因为 outfile
为无
;但是,空文件确实被创建了。有什么想法我做错了吗?
编辑:我应该指定我可以读取和写入 ENVI Float32 文件,因此驱动程序就在那里。只有CFloat64我不会写...
I'm trying to write ENVI CFloat64 files with GDAL:
import numpy
from osgeo import gdal
from osgeo.gdalconst import GDT_CFloat64
a = numpy.zeros((1000, 1000), dtype='complex64')
driver = gdal.GetDriverByName("ENVI")
outfile = driver.Create("test.bin", 1000, 1000, 1, GDT_CFloat64)
outfile.GetRasterBand(1).WriteArray(a, 0, 0)
outfile = None
but I can't write the array to the band in outfile.GetRasterBand(1).WriteArray(a, 0, 0)
because outfile
is None
; however, the empty file does get created. Any ideas what I am doing wrong?
EDIT: I should specify that I can read and write ENVI Float32 files, so the driver is there. Only CFloat64 that I can't write...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,当
driver.Create(...)
或gdal.Open(...)
等返回None
时,它是gdal的引发 IOError 或指示给定驱动程序名称无效的方法。 (或者可能表明发生了另一种错误,但这两个似乎是最有可能的)(我将跳过关于我多么不喜欢 gdal 的 python 绑定的咆哮......)
你没有明显做错任何事情(该示例创建一个全为零的 .bin 文件和一个格式正确的 .hdr 文件,因为它应该在我的机器上。)。
鉴于它创建了一个空文件,您似乎有权写入该文件,因此这不是 IO 问题。
这意味着:
gdal.GetDriverByName("something random")
也将返回None
。)检查 gdalinfo --formats 的输出,并确保 gdal 编译时支持 ENVI 文件(不过我认为应该是默认的)。
如果没有,请检查是否可以编写全零值的 geotiff(或任何其他格式)。如果没有任何效果,您需要重新安装 gdal。
希望这能为您指明正确的方向!
In a nutshell, when
driver.Create(...)
orgdal.Open(...)
, etc returnNone
, it's gdal's way of raising anIOError
or indicating than the given driver name is invalid. (Or potentially indicating that another sort of error occured, but those two seem the most likely)(I'll skip the rant about how much I dislike gdal's python bindings...)
You're not clearly doing anything wrong (The example creates a .bin file with all zeros and a properly formatted .hdr file, as it should, on my machine.).
Given that it creates an empty file, you appear to have permission to write to the file, so it's not an IO problem.
This means that either:
gdal.GetDriverByName("something random")
will returnNone
as well.)Check the output of
gdalinfo --formats
, and make sure that gdal is compiled with support for ENVI files (I think it should be by default, though).If not, check to see if you can write a geotiff (or any other format) with all zero values. If nothing is working, you need to re-install gdal.
Hope that gets you pointed in the right direction!
我认为该问题与 GDAL 由于与 ArcGIS 冲突而放弃对该格式的支持有关(令人难以置信!),请参阅此 错误报告。简短的回答是:我做不到,因为我的版本不可能做到这一点。
不幸的是,仍然没有适用于较新版本(现在最高为 1.8)的 Windows 安装程序,并且在 Windows 上从源代码构建几乎是不可能的。
I think the issue was related to GDAL dropping support of the format due to a conflict with ArcGIS (unbelievable!), see this bug report. The short answer is: I can't do it because it is impossible with my version.
Unfortunately, there is still no windows installer for newer versions, (up to 1.8 now), and building from source on Windows is nearly impossible.