[gdal-dev] extra spaces when writing to AAIGRID format

bhmcrae bmcrae at tnc.org
Thu Dec 15 12:21:11 EST 2011


Hi,

I'm having problems with GDAL inserting leading spaces when writing from a
numpy array to ESRI ASCII Grid format.

The problem occurs whenever there are integers in the array (even though the
array itself is floating point).

E.g., if I try to write a 3x3 grid that ArcGIS can read, it needs to look
something like this:

ncols        3
nrows        3
xllcorner    100.000000000000
yllcorner    100.000000000000
cellsize     0.000010000000
1.00000000000000000 1.4809201955795288 1.4809201955795288 
0.11773009598255157 0.15476560592651367 0.86710774898529053 
0.17429724335670471 0.76037305593490601 10.00000000000000

Instead, the ascii file written by GDAL looks like this (which can't be read
by ArcGIS because of extra leading spaces in the first line of the data):


ncols        5
nrows        5
xllcorner    100.000000000000
yllcorner    100.000000000000
cellsize     0.000010000000
      1 1.4809201955795288 1.4809201955795288 
 0.25947147607803345 0.71342569589614868 2.8101832866668701 
 0.11773009598255157 0.15476560592651367 0.86710774898529053 
 0.17429724335670471 0.76037305593490601     10 0.74458205699920654 

Here is the code I have been trying to use:

format = "MEM"
driver = gdal.GetDriverByName( format )      
dst_ds = driver.Create( file, len(data[0]), len(data),1,gdal.GDT_Float32)
dst_ds.SetGeoTransform([xllcorner, cellsize, 0, ull, 0, cellsize])
dst_ds.GetRasterBand(1).WriteArray(data)
format = 'AAIGrid'
driver = gdal.GetDriverByName(format)
dst_ds_new = driver.CreateCopy(file, dst_ds) 
dst_ds = None


I've seen this problem on various versions of python going back at least 3
years, so have relied on the much slower numpy.savetxt command instead of
using GDAL.

Any thoughts on how to make this work?

Thanks!
Brad







--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/extra-spaces-when-writing-to-AAIGRID-format-tp7097852p7097852.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list