Example of gdal tool (1)

Source: Internet
Author: User

The tools provided by gdal are very practical. In the future, we plan to write a series of blog posts to briefly describe the tools provided by gdal, and then demonstrate them based on actual examples, hope to be useful for data processing.

First, describe the data to be prepared. Here I use the DEM Data of SRTM. For the download method, refer to my previous blog. The data is as follows. The downloaded raw data is a zip file. That is, 10 zip files in.

Today, we will first describe the gdalinfo and gdalbuildvrt tools. Gdalinfo, as its name implies, is used to view image information, which basically includes all information in the image. Currently, apart from being unable to view the gray value of the image, there is another tool to view the gray value of the image, other information can be viewed using this tool.

First, you can view the image information in one of the ZIP files (of course, You can decompress the ZIP file before processing ). Here, the zip file is not decompressed to demonstrate a place where gdal is relatively good. You can directly access the data in the zip package. Syntax:

gdalinfo.exe /vsizip/E:/newzealand/srtm_70_21.zip/srtm_70_21.tif

For details about how to spell the data path in the gdal access zip package file, refer to my previous blog [3]. The output information of the preceding command is as follows:



As you can see, gdal outputs the size, coordinates, data types, nodata values, and associated files of the images in the zip package. In addition, gdalinfo can use the-mm command to calculate the maximum and minimum values of the image, and the-Stats command to calculate the extreme values, mean values, variance, and other statistical information of the image, -Hist is used to calculate the histogram and other information of an image. In addition, there are some options to control whether the output information is displayed. For details, refer to the official document [1].

The gdalinfo tool has come to an end. Next we will splice the DEM Data of SRTM downloaded above to form a large file. Here we use gdalbuildvrt, a relatively "advanced" tool. In fact, it is very similar to the mosaic we often use, and it is similar here. The following describes the operation methods.

Next, we need to splice all the TIF files in the ZIP file into a large image based on geographical coordinates. Here we use the gdal VRT file format, a virtual file format, which is very convenient to use. You can generate a VRT file in two ways: Extract all zip data and process it; otherwise, you can directly process it without any pressure.
First, let's take a look at the decompression method. In fact, it is very simple. First, extract all the above ZIP files and store the TIF files in a folder. For example, here I am E: \ newzealand. The specific method is as follows: store all images in a TXT file named vrt_input_tif.txt. As follows:

E:/newzealand/srtm_70_21.tifE:/newzealand/srtm_70_22.tifE:/newzealand/srtm_70_23.tifE:/newzealand/srtm_71_19.tifE:/newzealand/srtm_71_20.tifE:/newzealand/srtm_71_21.tifE:/newzealand/srtm_71_22.tifE:/newzealand/srtm_72_20.tifE:/newzealand/srtm_72_21.tifE:/newzealand/srtm_72_22.tif

For non-pressure processing, you can directly use the zip access method in the virtual access mechanism provided by gdal to directly read the data in the zip package. In practice and practice, store all the ZIP files in a TXT file named vrt_input_zip.txt. As follows:

/vsizip/E:/newzealand/srtm_70_21.zip/srtm_70_21.tif/vsizip/E:/newzealand/srtm_70_22.zip/srtm_70_22.tif/vsizip/E:/newzealand/srtm_70_23.zip/srtm_70_23.tif/vsizip/E:/newzealand/srtm_71_19.zip/srtm_71_19.tif/vsizip/E:/newzealand/srtm_71_20.zip/srtm_71_20.tif/vsizip/E:/newzealand/srtm_71_21.zip/srtm_71_21.tif/vsizip/E:/newzealand/srtm_71_22.zip/srtm_71_22.tif/vsizip/E:/newzealand/srtm_72_20.zip/srtm_72_20.tif/vsizip/E:/newzealand/srtm_72_21.zip/srtm_72_21.tif/vsizip/E:/newzealand/srtm_72_22.zip/srtm_72_22.tif

Next, open cmd, switch to the gdal tool directory, and enter the following content to get a nzl_zip.vrt file. You can open it with arcmap10, and you can see that the entire image is spliced into a whole block.

gdalbuildvrt.exe -input_file_list E:\newzealand\vrt_input_tif.txt E:\newzealand\NZL_tif.vrtgdalbuildvrt.exe -input_file_list E:\newzealand\vrt_input_zip.txt E:\newzealand\NZL_zip.vrt

We use gdalinfo again to view the combined VRT file information. We can see that the image size has increased, and the file-related files also contain all ZIP files. Open the above VRT file with arcmap10 and find that all the data has been spliced into a large file. The size of the VRT file is only 6 kb. You can manage big data without occupying disk space. It is a bit like the built-in dataset function of arcmap10.

 

Note: You must use arcmap10 or a later version to open the VRT dataset of gdal. Or use qgis.

References:

[1] http://gdal.org/gdalinfo.html

[2] http://gdal.org/gdalbuildvrt.html

[3] http://blog.csdn.net/liminlu0314/article/details/8589042

[4] http://blog.csdn.net/liminlu0314/article/details/8068715

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.