Use the memory file of gdal to save temporary files

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.