QGIS Coding and Compilation Guide
Total Page:16
File Type:pdf, Size:1020Kb
Quantum GIS Coding and Compilation Guide Version 1.3 'Mimas' Preamble This document is the original Coding and Compilation Guide of the described software Quantum GIS. The software and hardware described in this document are in most cases registered trademarks and are therefore subject to the legal requirements. Quantum GIS is subject to the GNU General Public License. Find more information on the Quantum GIS Homepage http://qgis.osgeo.org. The details, data, results etc. in this document have been written and verified to the best of knowledge and responsibility of the authors and editors. Nevertheless, mistakes concerning the content are possible. Therefore, all data are not liable to any duties or guarantees. The authors, editors and publishers do not take any responsibility or liability for failures and their consequences. Your are always welcome to indicate possible mistakes. This document has been typeset with LATEX. It is available as LATEX source code via subversion and online as PDF document via http://qgis.osgeo.org/documentation/manuals.html. Translated versions of this document can be downloaded via the documentation area of the QGIS project as well. For more information about contributing to this document and about translating it, please visit: http://www.qgis.org/wiki/index.php/Community_Ressources Links in this Document This document contains internal and external links. Clicking on an internal link moves within the document, while clicking on an external link opens an internet address. In PDF form, internal links are shown in blue, while external links are shown in red and are handled by the system browser. In HTML form, the browser displays and handles both identically. Coding Compilation Guide Authors and Editors: Tim Sutton Marco Hugentobler Gary E. Sherman Tara Athan Godofredo Contreras Werner Macho Carson J.Q. Farmer Otto Dassau Jürgen E. Fischer Davis Wills Magnus Homann Martin Dobias With thanks to Tisham Dhar for preparing the initial msys (MS Windows) environment documentation, to Tom Elwertowski and William Kyngesburye for help in the MAC OSX Installation Section and to Carlos Dávila. If we have neglected to mention any contributors, please accept our apologies for this oversight. Copyright c 2004 - 2009 Quantum GIS Development Team Internet: http://qgis.osgeo.org Contents Contents Title i Preamble ii Table of Contents iii 1 Writing a QGIS Plugin in C++ 1 1.1 Why C++ and what about licensing ............................. 1 1.2 Programming a QGIS C++ Plugin in four steps ...................... 1 1.3 Further information ...................................... 19 2 Creating C++ Applications 20 2.1 Creating a simple mapping widget ............................. 20 2.2 Working with QgsMapCanvas ................................ 23 3 Writing a QGIS Plugin in Python 27 3.1 Why Python and what about licensing ........................... 27 3.2 What needs to be installed to get started .......................... 27 3.3 Programming a simple PyQGIS Plugin in four steps ................... 28 3.4 Uploading the plugin to the repository ........................... 31 3.5 Further information ...................................... 31 4 Creating PyQGIS Applications 33 4.1 Designing the GUI ...................................... 33 4.2 Creating the MainWindow .................................. 34 4.3 Finishing Up ......................................... 39 4.4 Running the Application ................................... 39 5 Installation Guide 43 6 General Build Notes 43 6.1 An overview of the dependencies required for building .................. 43 7 Building under windows using msys 44 7.1 MSYS: ............................................. 44 7.2 Qt4.3 ............................................. 44 7.3 Flex and Bison ........................................ 45 7.4 Python stuff: (optional) .................................... 45 7.4.1 Download and install Python - use Windows installer ............... 45 7.4.2 Download SIP and PyQt4 sources ......................... 45 7.4.3 Compile SIP ..................................... 46 7.4.4 Compile PyQt ..................................... 46 QGIS 1.3 Installation and Coding Guide iii Contents 7.4.5 Final python notes .................................. 46 7.5 Subversion: .......................................... 46 7.6 CMake: ............................................ 46 7.7 QGIS: ............................................. 47 7.8 Compiling: ........................................... 47 7.9 Configuration ......................................... 47 7.10 Compilation and installation ................................. 48 7.11 Run qgis.exe from the directory where it’s installed (CMAKE_INSTALL_PREFIX) ... 48 7.12 Create the installation package: (optional) ......................... 48 8 Building on Mac OSX using frameworks and cmake (QGIS > 0.8) 49 8.1 Install XCODE ........................................ 49 8.2 Install Qt4 from .dmg ..................................... 49 8.3 Install development frameworks for QGIS dependencies ................. 50 8.3.1 Additional Dependencies : General compatibility note .............. 50 8.3.2 Additional Dependencies : GSL ........................... 50 8.3.3 Additional Dependencies : Expat .......................... 51 8.3.4 Additional Dependencies : Python ......................... 51 8.3.5 Additional Dependencies : SIP ........................... 52 8.3.6 Additional Dependencies : PyQt .......................... 53 8.3.7 Additional Dependencies : Bison .......................... 54 8.4 Install CMAKE for OSX ................................... 54 8.5 Install subversion for OSX .................................. 54 8.6 Check out QGIS from SVN ................................. 55 8.7 Configure the build ...................................... 56 8.7.1 Configure the Cmake build ............................. 56 8.7.2 Configure the Xcode build .............................. 58 8.8 Building ............................................ 58 8.8.1 Building with Cmake ................................. 58 8.8.2 Building with Xcode ................................. 59 9 Building on GNU/Linux 59 9.1 Building QGIS with Qt4.x .................................. 59 9.2 Prepare apt .......................................... 59 9.3 Install Qt4 ........................................... 60 9.4 Install additional software dependencies required by QGIS ................ 60 9.5 GRASS Specific Steps .................................... 61 9.6 Setup ccache (Optional) ................................... 61 9.7 Prepare your development environment .......................... 61 9.8 Check out the QGIS Source Code ............................. 62 9.9 Starting the compile ..................................... 62 9.10 Building Debian packages .................................. 63 QGIS 1.3 Installation and Coding Guide iv Contents 9.11 Running QGIS ........................................ 64 9.12 A practical case: Building QGIS and GRASS from source on Ubuntu with ECW and MrSID formats support .................................... 64 9.12.1 Step 1: install base packages ............................ 64 9.12.2 Step 2: compile and install the ecw libraries .................... 65 9.12.3 Step 3: download the MrSID binaries ....................... 65 9.12.4 Step 4: compile and install the gdal libraries .................... 66 9.12.5 Step 5: compile and install GRASS ......................... 67 9.12.6 Step 6: compile and install the GDAL-GRASS libraries .............. 68 9.12.7 Step 6: compile and install QGIS .......................... 69 10 Creation of MSYS environment for compilation of Quantum GIS 70 10.1 Initial setup .......................................... 70 10.1.1 MSYS ......................................... 70 10.1.2 MinGW ........................................ 71 10.1.3 Flex and Bison .................................... 71 10.2 Installing dependencies ................................... 71 10.2.1 Getting ready ..................................... 71 10.2.2 GDAL level one .................................... 72 10.2.3 GRASS ........................................ 74 10.2.4 GDAL level two .................................... 74 10.2.5 GEOS ......................................... 75 10.2.6 SQLITE ........................................ 75 10.2.7 GSL .......................................... 76 10.2.8 EXPAT ......................................... 76 10.2.9 POSTGRES ..................................... 76 10.3 Cleanup ............................................ 77 11 Building with MS Visual Studio 77 11.1 Setup Visual Studio ..................................... 77 11.1.1 Express Edition .................................... 77 11.1.2 All Editions ...................................... 78 11.2 Download/Install Dependencies ............................... 78 11.2.1 Flex and Bison .................................... 78 11.2.2 To include PostgreSQL support in Qt ........................ 78 11.2.3 Qt ........................................... 79 11.2.4 Proj.4 ......................................... 79 11.2.5 GSL .......................................... 80 11.2.6 GEOS ......................................... 80 11.2.7 GDAL ......................................... 81 11.2.8 PostGIS ........................................ 81 11.2.9 Expat ......................................... 81 QGIS 1.3 Installation and Coding Guide v Contents 11.2.10CMake ........................................ 82 11.3 Building QGIS with CMAKE ................................