Gdal experience record in VC ++

Source: Internet
Author: User

 

Recently, during my internship, I used TIF (geotiff) image processing a while ago, and used gdal in vc2005 to record related things.

 

The latest version of gdal has reached 1.7.2. In addition to Win32, gdal has to deal with Windows Mobile's Pocket PC, so it also looks at the support of wince, it is found that, although there is always the wince directory,However, onlyVersion 1.4 of WinCEOnly the version can be compiled and used.Later versions of the wince branch are all set up

 

However, the content here is basically irrelevant to the version.

 

The basic things are needless to say. The tutorials and examples on the official website are easy to understand, and the data model is easy to explain. The following link provides a Chinese translation of the basic content:

 

Http://www.osgeo.org.cn/l18n/gdal/index.html

 

Here is a summary of the gdal skills

 

File read/write:

 

In gdal, there are three main types of image read/write:

Gdaldataset: rasterio (...)

Gdalrasterband: rasterio (...)

Gdalrasterband: readblock (...) and writeblock (...)

After my own tests, the efficiency is not much different, but there are still some differences.

The first two are essentially the same, except that the first one can read all band information in the specified image range at a time, while the second one can only read the information in the specified band. The parameters of both functions include the region to be read from the source image and the target size. Based on these two parameters, rasterio can automatically scale the image (I only need to zoom in ). The first type of reading, because it can read all the bands, there are some special points, which are described later.

 

Readblock and writeblock are read according to the image file's segmented structure. The size of the segmented block is already an objective existence of the image file itself. Because they are suitable for reading files in multiple parts, the speed is the fastest, however, it can only be read by a shard, with poor flexibility.

 

Gdaldataset: Last three parameters of rasterio-> Read result data arrangement

 

This function reads all the bands in the specified region. Since all the bands are read, there is a problem with the data organization format. For general images, a band (a component of the actual color) is 8 bit, so the data we obtain through rasterio is byte * pdata; (here, byte, it can be typedef unsigned char byte ). For a 24-bit true color chart, the three red, green, and blue (RGB) bands are stored in pdata. The last three parameters of rasterio specify this mode of organization, for specific concepts, refer to the descriptions in the API document. Here we provide npixelspace, nlinespace, and nbandspace. If they are all 0, the data in pdata is organized as Rrr... rggg .... Gbbb... B (the default settings are used for all three parameters). If it is set to (3, 0, 1), it can be arranged as rgbrgbrgb ..... (Three data bits per pixel. Each Data bit is automatically available for each row and one data bit per band). The latter is easier to display. Of course, if the color of Windows bitmap data is BGR, you can set nbandcount = 3, panbandmap = new int [] {, 1}. In this way, the order of reading the band is BGR ~

 

 

Processing of Two-value TIF graph (1bit TIF graph)

 

A two-value chart generally has only one band and only 1 bit in this band. Even so, when gdal reads data, getdatatype also returns gdt_byte, which is considered to be an 8-bit band, in the middle, every 1 bit is automatically read as 8 bit (the value remains unchanged, and only 0 and 1 are available ). This may be because C ++ does not have a suitable data type that can represent the data size that is not a multiple of 8 bits (even if bool is 1 bit, there is also a four-value diagram (2 bits ), the eight-value graph (3bit ).

Unified 8-bit has no impact on read and operation processing, but if you create a gdaldataset and write it directly, the image will suddenly become eight times larger, because it is written into an 8-bit single-band image. In this case, the creation option of TIFF should be used. The create function has a string array input creation option (nbits = 1 is to create a 1bit graph). For details, refer:

Http://www.gdal.org/frmt_gtiff.html

 

 

Pyramid (thumbnail)

 

You can call buildoverview to create thumbnails of different proportions. By default, gdal is saved as a. Ovr file, which can only be an integer to Reduce the proportion. In this way, when rasterio is called to read the image in a scaled-down manner, gdal will automatically use the scaled data in the corresponding proportion in the pyramid, which can greatly improve the display processing speed of the image.

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.