Data type in GTiff

In this exercise we will see the importance to use the correct data type in GTiff environment.

Build up a GTiff using AWK

[5]:
%%bash

echo ncols 10       >  geodata_small/rast_ID.asc
echo nrows 10       >> geodata_small/rast_ID.asc
echo xllcorner 0    >> geodata_small/rast_ID.asc
echo yllcorner 0    >> geodata_small/rast_ID.asc
echo cellsize  1    >> geodata_small/rast_ID.asc

awk ' BEGIN {
for (row=1 ; row<=10 ; row++)  {
     for (col=1 ; col<=10 ; col++) {
         printf ("%i " , 16777200+col+(row-1)*10  ) } ; printf ("\n")  }}' >> geodata_small/rast_ID.asc

The rast_ID.asc has the typical structure of Arc/Info ASCII Grid

[6]:
%%bash
cat geodata_small/rast_ID.asc
ncols 10
nrows 10
xllcorner 0
yllcorner 0
cellsize 1
16777201 16777202 16777203 16777204 16777205 16777206 16777207 16777208 16777209 16777210
16777211 16777212 16777213 16777214 16777215 16777216 16777217 16777218 16777219 16777220
16777221 16777222 16777223 16777224 16777225 16777226 16777227 16777228 16777229 16777230
16777231 16777232 16777233 16777234 16777235 16777236 16777237 16777238 16777239 16777240
16777241 16777242 16777243 16777244 16777245 16777246 16777247 16777248 16777249 16777250
16777251 16777252 16777253 16777254 16777255 16777256 16777257 16777258 16777259 16777260
16777261 16777262 16777263 16777264 16777265 16777266 16777267 16777268 16777269 16777270
16777271 16777272 16777273 16777274 16777275 16777276 16777277 16777278 16777279 16777280
16777281 16777282 16777283 16777284 16777285 16777286 16777287 16777288 16777289 16777290
16777291 16777292 16777293 16777294 16777295 16777296 16777297 16777298 16777299 16777300

We can convert the rast_ID.asc Arc/Info ASCII Grid file to a GTiff

[7]:
%%bash
gdal_translate -ot UInt32 -co COMPRESS=DEFLATE -co ZLEVEL=9 geodata_small/rast_ID.asc geodata_small/rast_ID.tif
Input file size is 10, 10
0...10...20...30...40...50...60...70...80...90...100 - done.

Let’s suppose that you want make a mathematical operation rast_ID.asc * 2222 using gdal_calc.py. How you would build-up the line?

[ ]:
%%bash
gdal_calc.py ?????????????????????????????????????   --outfile=geodata_small/rast_ID_mult.tif --overwrite

You can use the inverse procedure (GTiff to Arc/Info ASCII Grid) to see if your computation is correct.

[11]:
%%bash
gdal_translate  -of   AAIGrid  geodata_small/rast_ID_mult.tif  geodata_small/rast_ID_mult.asc
cat geodata_small/rast_ID_mult.asc
Input file size is 10, 10
0...10...20...30...40...50...60...70...80...90...100 - done.
ncols        10
nrows        10
xllcorner    0.000000000000
yllcorner    0.000000000000
cellsize     1.000000000000
NODATA_value  1.7976931348623157081e+308
 37278940622.0 37278942844 37278945066 37278947288 37278949510 37278951732 37278953954 37278956176 37278958398 37278960620
 37278962842 37278965064 37278967286 37278969508 37278971730 37278973952 37278976174 37278978396 37278980618 37278982840
 37278985062 37278987284 37278989506 37278991728 37278993950 37278996172 37278998394 37279000616 37279002838 37279005060
 37279007282 37279009504 37279011726 37279013948 37279016170 37279018392 37279020614 37279022836 37279025058 37279027280
 37279029502 37279031724 37279033946 37279036168 37279038390 37279040612 37279042834 37279045056 37279047278 37279049500
 37279051722 37279053944 37279056166 37279058388 37279060610 37279062832 37279065054 37279067276 37279069498 37279071720
 37279073942 37279076164 37279078386 37279080608 37279082830 37279085052 37279087274 37279089496 37279091718 37279093940
 37279096162 37279098384 37279100606 37279102828 37279105050 37279107272 37279109494 37279111716 37279113938 37279116160
 37279118382 37279120604 37279122826 37279125048 37279127270 37279129492 37279131714 37279133936 37279136158 37279138380
 37279140602 37279142824 37279145046 37279147268 37279149490 37279151712 37279153934 37279156156 37279158378 37279160600
[ ]: