GDAL: patch/merge Arc/Info ASCII Grid files via CLI

Which is the best way to merge/patch two or more adjacent maps? Through CLI!

GDAL (Geospatial Data Abstraction Library) can help me (or you, if you are reading this post).

However, GDAL is not in love with Arc/Info ASCII Grid. I don’t know why, but I think that I will answer to my question in a future post, because I often work with this type of files.

 

Anyway, to achieve the goal described by the title of the post it’s necessary to translate the .asc file in .virt one, through the gdal_translate command (it’s very important to set the nodata value):

gdal_translate -of VRT -a_nodata -9999 map.asc map.virt

Now, it’s possible to patch all the converted maps through the gdalbuildvrt command:

gdalbuildvrt -srcnodata "-9999" -vrtnodata "-9999" 
patched.virt map1.virt map2.virt (and all the other maps)

Then, just a simple conversion and you’re done!

gdal_translate -of AAIGrid-a_nodata -9999 patched.virt patched.asc

See you soon!

About Francesco Serafin

I am a PhD student at the Department of Civil, Environmental and Mechanical Engineering at the University of Trento. My two greatest loves: Computer Science and Water (take three with my Lenovo!:D). As a result, the aim of my life is to make both passions coexist. My gpg public key available at https://pgp.mit.edu

Leave a Reply

Your email address will not be published.

*