Qgis secondary development Lecture 4

Source: Internet
Author: User
Document directory
  • Step 1: Modify the qgis2.h file and add the following header files
  • Step 2: Modify the qgis2.cpp file to modify the addlayer function. The modified code is as follows:
  • Step 3: Modify the main function to support Chinese display. The Code is as follows:
  • Step 4: run the command as follows:
This article mainly implements the function of loading raster data. The main class used is qgsrasterlayer, and the code is modified based on the second lecture. Step 1: Modify the qgis2.h file and add the following header files

// 4th code # include <qgsrasterlayer. h> # include <qmessagebox. h>

Step 2: Modify the qgis2.cpp file to modify the addlayer function. The modified code is as follows:

// 4th code qfileinfo myrasterfileinfo (".. /data/abarema_jupunba_projection.tif "); qgsrasterlayer * myplayer = new qgsrasterlayer (myrasterfileinfo. filepath (), myrasterfileinfo. completebasename (); If (myplayer-> isvalid () {qmessagebox: Information (null, qstring (TR ("load layer ")), qstring (TR ("loaded successfully"), qmessagebox: Yes | qmessagebox: No); myplayer-> setdrawingstyle (qgsrasterlayer: singlebandpseudo docolor); myplayer-> Publish (qgsrasterlayer:: pseudo docolorshader); myplayer-> constraint (qgscontrastenhancement: Unknown, false); qlist <qgsmapcanvaslayer> mylayerset; qgsmaplayerregistry: instance ()-> addmaplayer (myplayer, true ); mpmapcanvas-> setextent (myplayer-> extent (); mylayerset. append (qgsmapcanvaslayer (myplayer); mpmapcanvas-> setlayerset (mylayerset);} else {qmessagebox: Information (null, qstring (TR ("load layer ")), qstring (TR ("loading failed"), qmessagebox: Yes | qmessagebox: No );}

Note: (1) differences between basename and completebasename: The character returned by basename does not contain ".", while the character returned by completebasename does not contain the character after the last.

Step 3: Modify the main function to support Chinese display. The Code is as follows:

QgsApplication a(argc, argv,TRUE);QTextCodec *codec = QTextCodec::codecForName("System");QTextCodec::setCodecForCStrings(codec);QTextCodec::setCodecForLocale(codec);QTextCodec::setCodecForTr(codec);qgis2 w;w.show();return a.exec()

Step 4: run the command as follows:

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.