开发者

Problem creating CFloat64 ENVI files with GDAL 1.6.1

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_CFloat6开发者_C百科4)
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...


In a nutshell, when driver.Create(...) or gdal.Open(...), etc return None, it's gdal's way of raising an IOError 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:

  1. Your version of gdal doesn't support ENVI files (e.g. gdal.GetDriverByName("something random") will return None as well.)
  2. Gdal is encountering some sort of internal error when creating a driver for an ENVI dataset.

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜