QGIS Coding and Compilation Guide
Total Page:16
File Type:pdf, Size:1020Kb
Quantum GIS Coding and Compilation Guide Version 1.1 'Pan' 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 Introduction 1 2 Writing a QGIS Plugin in C++ 2 2.1 Why C++ and what about licensing ............................. 2 2.2 Programming a QGIS C++ Plugin in four steps ...................... 2 2.3 Further information ...................................... 20 3 Creating C++ Applications 21 3.1 Creating a simple mapping widget ............................. 21 3.2 Working with QgsMapCanvas ................................ 24 4 Writing a QGIS Plugin in Python 28 4.1 Why Python and what about licensing ........................... 28 4.2 What needs to be installed to get started .......................... 28 4.3 Programming a simple PyQGIS Plugin in four steps ................... 29 4.4 Uploading the plugin to the repository ........................... 32 4.5 Further information ...................................... 32 5 Creating PyQGIS Applications 34 5.1 Designing the GUI ...................................... 34 5.2 Creating the MainWindow .................................. 35 5.3 Finishing Up ......................................... 39 5.4 Running the Application ................................... 40 6 Installation Guide 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.1 Installation and Coding Guide iii Contents 7.4.5 Final python notes .................................. 46 7.5 Subversion: .......................................... 46 7.6 CMake: ............................................ 46 7.7 QGIS: ............................................. 46 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) 48 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 : GSL ........................... 50 8.3.2 Additional Dependencies : Expat .......................... 50 8.3.3 Additional Dependencies : SIP ........................... 51 8.3.4 Additional Dependencies : PyQt .......................... 52 8.3.5 Additional Dependencies : Bison .......................... 52 8.4 Install CMAKE for OSX ................................... 53 8.5 Install subversion for OSX .................................. 53 8.6 Check out QGIS from SVN ................................. 54 8.7 Configure the build ...................................... 55 8.8 Building ............................................ 56 9 Building on GNU/Linux 56 9.1 Building QGIS with Qt4.x .................................. 56 9.2 Prepare apt .......................................... 57 9.3 Install Qt4 ........................................... 57 9.4 Install additional software dependencies required by QGIS ................ 58 9.5 GRASS Specific Steps .................................... 58 9.6 Setup ccache (Optional) ................................... 58 9.7 Prepare your development environment .......................... 59 9.8 Check out the QGIS Source Code ............................. 59 9.9 Starting the compile ..................................... 60 9.10 Building Debian packages .................................. 61 9.11 Running QGIS ........................................ 61 10 Creation of MSYS environment for compilation of Quantum GIS 62 10.1 Initial setup .......................................... 62 10.1.1 MSYS ......................................... 62 10.1.2 MinGW ........................................ 62 10.1.3 Flex and Bison .................................... 62 QGIS 1.1 Installation and Coding Guide iv Contents 10.2 Installing dependencies ................................... 63 10.2.1 Getting ready ..................................... 63 10.2.2 GDAL level one .................................... 63 10.2.3 GRASS ........................................ 65 10.2.4 GDAL level two .................................... 66 10.2.5 GEOS ......................................... 66 10.2.6 SQLITE ........................................ 67 10.2.7 GSL .......................................... 67 10.2.8 EXPAT ......................................... 68 10.2.9 POSTGRES ..................................... 68 10.3 Cleanup ............................................ 68 11 Building with MS Visual Studio 68 11.1 Setup Visual Studio ..................................... 68 11.1.1 Express Edition .................................... 69 11.1.2 All Editions ...................................... 69 11.2 Download/Install Dependencies ............................... 69 11.2.1 Flex and Bison .................................... 69 11.2.2 To include PostgreSQL support in Qt ........................ 70 11.2.3 Qt ........................................... 70 11.2.4 Proj.4 ......................................... 71 11.2.5 GSL .......................................... 71 11.2.6 GEOS ......................................... 71 11.2.7 GDAL ......................................... 72 11.2.8 PostGIS ........................................ 73 11.2.9 Expat ......................................... 73 11.2.10CMake ........................................ 73 11.3 Building QGIS with CMAKE ................................. 73 12 Building under Windows using MSVC Express 74 12.1 System preparation ..................................... 74 12.2 Install the libraries archive .................................. 75 12.3 Install Visual Studio Express 2005 ............................. 75 12.4 Install Microsoft Platform SDK2 ............................... 76 12.5 Edit your vsvars ........................................ 78 12.6 Environment Variables .................................... 80 12.7 Building Qt4.3.2 ....................................... 81 12.7.1 Compile Qt ...................................... 81 12.7.2 Configure Visual C++ to use Qt ........................... 81 12.8 Install Python ......................................... 82 12.9 Install SIP ........................................... 82 12.10Install PyQt4 ......................................... 83 QGIS 1.1 Installation and Coding Guide v Contents 12.11Install CMake ......................................... 83 12.12Install Subversion ....................................... 83 12.13Initial SVN Check out .................................... 84 12.14Create