When you write an algorithm using gdal, the intermediate computing result is often stored in a temporary image file, and deleted after use. If there is only one temporary file, it doesn't matter if you create one, but when a complex algorithm may contain many temporary files (I have four temporary files when writing the hariss corner point auto-Matching Algorithm ), in this case, temporary files are always uncomfortable. In addition, when the second image is too large, temporary files also occupy a lot of space, it may be a headache if the space is insufficient or the specified temporary file path cannot be written. Third, it takes a lot of time to read and write the temporary file, especially when I/O is created on the disk, it takes a lot of time.
Based on the above several reasons, always want to do not need temporary files, found that gdal provides a VRT Virtual File (refer to the http://www.gdal.org/gdal_vrttut.html), view gdalenhance in gdal app. in the CPP file, it is found that VRT is complicated to use, or I am not familiar with it. I will take a closer look at it later. In addition to VRT, there is also a memory file named MEM in gdal. For more information, see http://gdal.org/frmt_mem.html. The usage of MEM files is the same as that of common files. refer to the following code:
# Include "gdal_priv.h" int main () {gdalallregister (); // open the raw data gdaldataset * posrcds; posrcds = (gdaldataset *) gdalopen ("C :\\ test. IMG ", ga_readonly); If (posrcds = NULL) Return-1; // get the mem file driver gdaldriver * podriver; podriver = getgdaldrivermanager () -> getdriverbyname ("mem"); If (podriver = NULL) Return-1; // you can use the create function to create a mem file, the file path provides an empty string with gdaldataset * podstds; podstds = podriver-> createcopy ("", posrcds, false, null ); {// do something} // close the temporary file directly after use. You do not need to delete the temporary file gdalclose (gdaldataseth) podstds); gdalclose (gdaldataseth) posrcds ); return 0 ;}