Gdal remote sensing image reading and display-VC Environment

Source: Internet
Author: User

Gdal is a database for reading, writing, and reading data from grids and vectors. It has a huge application in the GIS industry. Remote sensing images are an important type of our spatial data, the following code reads and displays remote sensing data:

Char * szfilename = "K: \ provincial/municipal map \ new folder (2) \ fuzhoucity. TIF "; gdaldataset * podataset; // gdalallregister (); podataset = (gdaldataset *) gdalopen (szfilename, ga_readonly); If (podataset = NULL) {afxmessagebox (_ T ("file opening failed !!! "); Return;} gdalrasterband * poband1; // a remote sensing band gdalrasterband * poband2; gdalrasterband * poband3; int nbandcount = podataset-> getrastercount (); poband1 = podataset-> getrasterband (1); poband2 = podataset-> getrasterband (2); poband3 = podataset-> getrasterband (3 ); // obtain the size of the image display window getclientrect (& m_viewrect); int nimgsizex = podataset-> getrasterxsize (); int nimgsizey = podataset-> getrasterysize (); // obtain the coefficient of the affine transformation. Double adfgeotransform [6]; podataset-> getgeotransform (adfgeotransform); double right = adfgeotransform [0] + nimgsizex * adfgeotransform [1]; double Bottom = adfgeotransform [3] + nimgsizey * adfgeotransform [5]; int encrypted, encrypted; encrypted = nimgsizex; nbuffersizey = nimgsizey; int nscrrenwidth = m_viewrect.width (); int nscrrenheight = bytes (); // allocate memory byte * pafscanblock1, * pafscanblock2, * pafscanblock3, * templock1, * templock2, * templock3; pafscanblock1 = (byte *) for the data buffer zone *) cplmalloc (nscrrenwidth) * (nscrrenheight); pafscanblock2 = (byte *) cplmalloc (nscrrenwidth) * (nscrrenheight); substring = (byte *) cplmalloc (nscrrenwidth) * (nscrrenheight); templock1 = pafscanblock1; templock2 = pafscanblock2; templock3 = pafscanblock3; // read data poband1-> rasterio (gf_read, 0, 0, latency, latency, pafscanblock1, nscrrenwidth, nscrrenheight, gdt_byte, 0, 0); poband2-> rasterio (gf_read, 0, 0, average, average, pafscanblock2, nscrrenwidth, nscrrenheight, gdt_byte, 0, 0 ); poband3-> rasterio (gf_read, 0, 0, nbuffersizex, nbuffersizey, pafscanblock3, nscrrenwidth, nscrrenheight, gdt_byte, 0, 0 ); // display the image DWORD dwbytes = (nscrrenwidth * 24)/8 point by point in view; while (DWORD) dwbytes) % 4) {dwbytes ++ ;} byte * szbuffer = new byte [nscrrenheight * dwbytes]; memset (szbuffer, 0, nscrrenheight * dwbytes); byte * ptemp = szbuffer; cclientdc DC (this); int nindex = 0; for (INT I = 0; I <nscrrenheight; I ++) {for (Int J = 0; j <nscrrenwidth; j ++) {byte dn1 = * pafscanblock1; byte dn2 = * pafscanblock2; byte dn3 = * pafscanblock3; // It is first drawn to the memory DC and then to the DC dcmem of the device. setpixel (J, I, RGB (dn1, dn2, dn3); // display the pixel value pafscanblock1 ++; pafscanblock2 ++; pafscanblock3 ++ ;} szbuffer = ptemp + dwbytes * I;} PDC-> bitblt (0, 0, m_viewrect.width (), m_viewrect.height (), & dcmem, 0, 0, srccopy); cplfree (templock1 ); cplfree (templock2); cplfree (templock3 );

 

The following figure shows the effects of remote sensing images:

In this way, the display effect is the same as that opened by ArcGIS.

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.