C# GDAL: How to Translate Grid to USGS .dem Format

cdemgdalraster

I am attempting to translate ArcInfo binary grids to USGS DEM format (.dem). I have installed the GDAL .NET bindings thru this build installer. I can get to GDAL in my C# add-in I am working on. However, it seems that I cannot create a USGS DEM:

Gdal.AllRegister();
GDAL.Dataset originalImage = Gdal.Open("C:\\65587895\\hdr.adf", GDAL.Access.GA_ReadOnly);
Driver demDriver = Gdal.GetDriverByName("USGSDEM");

int x = originalImage.RasterXSize;
int y = originalImage.RasterYSize;

Dataset dsDem = demDriver.Create("C:\\Data\\65587895\\foo.dem", x, y, 1, DataType.GDT_Int16, null);

Gives the error:

System.ApplicationException: GDALDriver::Create() ... no create method implemented for this format.

I thought the USGSDEM format was read/write…am I wrong on that? The formats list says that creation of USGSDEM is supported, but a run of demDriver.GetMetadata(null) to get the metadata from the USGSDEM driver results in no return of DCAP_CREATE=YES, only DCAP_CREATECOPY=YES, which makes me cringe, thinking that indeed the GDALDriver::Create() method is not implemented for the USGSDEM format.

Any thoughts or experience with this? Any other thoughts on translating binary grids to DEMs?

Best Answer

Turns out you use the CreateCopy method instead, since the Create method is indeed not implemented for the USGSDEM format:

OSGeo.GDAL.Dataset dsDem = demDriver.CreateCopy(c.outputFile, originalImage, 0, null, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Sample Data");

I must admit that after not getting many responses here, I asked this question on the gdal-dev osgeo mailing list, which is where this answer came from.