Gdal Library--read images and extract basic information

Source: Internet
Author: User

The Gdal library is a cross-platform raster Geodata format library that includes reading, writing, converting, and processing various raster data formats (some specific formats are not supported for some operations such as writing). It uses a single, abstract data model to support most raster data. Here are the formats supported by the Gdal library: http://www.gdal.org/formats_list.html

Note: This article uses the Gdal library in the QT development environment.

When using the Gdal library in Qt, in addition to adding Gdal_priv.h header files, you also need to add libs + =-lgdal to the Xxx.pro file and open the file with an editable document.

The file format is first registered when using Gdal, where we register all supported files: Gdalallregister ()

After registering with the DataSet object pointing to the Open data file, the data is read as follows:

Gdalallregister ();    
Gdaldataset *podataset;
QString filename;
Filename=qfiledialog::getopenfilename (This,
TR ("Choose Images"),
TR ("All fles (* *)"));
Open the image
Qbytearray ba = Filename.tolatin1 ();
Podataset = (gdaldataset*) gdalopen (Ba.data (), ga_readonly);

Note that you also need to convert qstring to char* type to ensure that the function parameter types are consistent.

1. Get basic information about an image

After using Gdal to read the image successfully, we can obtain some basic information of the image, as follows:

Description information: const char* gdaldataset::getdriver ()->getdescription (), usually the format of the image

Image size: Image width int gdaldataset::getrasterxsize ()

Image height int gdaldataset::getrasterysize ()

Number of bands: int Gdaldataset::getrastercount () The number of bands is the color of each pixel in the image, and the optics in physics is the light wave of a certain frequency. Bands are less one, many more, and in remote sensing imagery there are often multiple bands.

Projection information: gdaldataset::getprojectionref () Some images do not have projection information, rather than the general JPG, BMP format image.

Geographical coordinates information: double adfgeotransform[6]

Gdaldataset::getgeotransform (Adfgeotransform)

Geographic coordinates information is an array of 6 double data, adfgeotransform[1] and adfgeotransform[5] representing the distance between the east and south direction of a pixel, adfgeotransform[0] and adfgeotransform[3] represent the coordinates of the upper-left corner.

Band Information: Important information in the data set, band size, data type, color information, etc.

Methods of obtaining bands: Gdalrasterband *poband;

Poband = Podataset->getrasterband (i) Poband is a pointer to the I-band

Band size: int poband->getxsize ()

int Poband->getysize ()

Data type: const char* gdalgetdatatypename (Poband->getrasterdatatype ())

Color information: const char* Gdalgetcolorinterpretationname (Poband->getcolorinterpretation ())

2. Display the image information to be read

The above Gdal the method of acquiring image data information, then displays the data information in Qt.

QString Strimginfo;
QString Strimgformat =
Podataset->getdriver ()->getdescription ();
Strimginfo.append (TR ("Descreption: ") +strimgformat+ "\ n");

Similar to the above, the Qstring class in Qt has a vector-like function that can be used to add a new string after the Append function

Information obtained after the display: Ui->label->settext (strimginfo);

Gdal Library--read images and extract basic information

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.