Gdal database-read images and extract Basic Information

Source: Internet
Author: User

The gdal library is a cross-platform grid Geographic Data Format library, including reading, writing, conversion, and processing of various grid 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 there is a format supported by the gdal Library: http://www.gdal.org/formats_list.html

Note: This document uses the gdal library in the QT development environment.

When using the gdal library in QT, in addition to adding the gdal_priv.h header file, you also need to add libs + =-lgdal to the XXX. Pro file, and open the file with editable documents.

When using gdal, first register the file format. Here we register all supported file formats: gdalallregister ()

After registration, you can use a DataSet object to point to an opened data file to read the data 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 qstring needs to be converted to char * to ensure that the function parameter types are consistent.

1. obtain basic image information

After reading the image successfully using gdal, you can obtain basic information about the image, as shown below:

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

Image Size: Image Width int gdaldataset: getrasterxsize ()

Image Height int gdaldataset: getrasterysize ()

Band number: int gdaldataset: getrastercount () band number refers to the color type contained in each pixel of the image. In physics, colors are light waves of a certain frequency. There is only one band, and there are more than one band. There are usually multiple bands in remote sensing images.

Projection information: gdaldataset: getprojectionref () some images do not have projection information, which is inferior to General jpg and BMP images.

Geographic coordinate information: Double adfgeotransform [6]

Gdaldataset: getgeotransform (adfgeotransform)

Geographic coordinate information is an array containing six double data types. adfgeotransform [1] and adfgeotransform [5] indicate the distance between East and West and a pixel in the north and south directions, adfgeotransform [0] And adfgeotransform [3] indicate the coordinates in the upper left corner.

Band information: important information in data sets, including band size, data type, and color information.

How to obtain the band: gdalrasterband * poband;

Poband = podataset-> getrasterband (I) poband is the pointer to the I-th 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 read image information

The above describes how gdal obtains image data, and then displays the data in QT.

QString strImgInfo;
QString strImgFormat =
poDataset->GetDriver()->GetDescription();
strImgInfo.append(tr("Descreption: ")+strImgFormat+"\n");

Like above, the qstring class in QT has a function similar to a vector. You can use the append function to add a new string after the string.

After the information is obtained, it is displayed: UI-> label-> settext (strimginfo );

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.