Ubuntu下编译Quantum GIS(QGIS)

前言:QGIS是一个用Qt框架写的开源桌面GIS工具。无论从学习GIS还是学习QT的角度它都是一个很好的工具。本文简介在ubuntu环境下编译QGIS源代码的方法。

参考链接:

http://gvision.info/using-qtcreator-with-qgis/

http://hub.qgis.org/projects/quantum-gis/repository/revisions/master/entry/INSTALL


环境:Ubuntu 11.10 


一、依赖的工具集:

- CMake >= 2.6.2

- Flex

- Bison >= 2.4


二、依赖库:

- Qt >= 4.4.0

- Proj >= 4.4.x

- GEOS >= 3.0

- Sqlite3 >= 3.0.0

- GDAL/ORG >= 1.4.x

- Qwt >= 5.0


可选依赖库:

- For GRASS plugin - GRASS >= 6.0.0 (libraries compiled with exceptions support on Linux 32bit)

- for georeferencer - GSL >= 1.8

- for postgis support and SPIT plugin - PostgreSQL >= 8.0.x

- for gps plugin - expat >= 1.95 and gpsbabel

- for mapserver export and PyQGIS - Python >= 2.3 (2.5+ preferred)

- for python support - SIP >= 4.8, PyQt >= must match Qt version

- for qgis mapserver - FastCGI


三、编译QGIS所需的依赖库在Ubuntu的 "universe"组件里,这个组件默认是关闭的,为了编译QGIS必须激活:

1、编辑 /etc/apt/sources.list 文件

2、打开所有以 "deb"开头的行

3、更新sources库, 在命令行里输入:sudo apt-get update


四、安装第一部分提到的依赖库

注意:这里有不同的发行版本, 安装命令也会相应有些差别, 根据自己的需要选择 lucid, maverick, natty, oneiric, precise, sid, squeeze, 或是wheezy.

|| Distribution | install command for packages |
	
  | lucid | ``apt-get install bison cmake doxygen flex git-core graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | maverick | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev libqtwebkit-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | natty | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev libqtwebkit-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | oneiric | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev libqtwebkit-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | precise | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libopenscenegraph-dev libosgearth-dev libpq-dev libproj-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | sid | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libopenscenegraph-dev libosgearth-dev libpq-dev libproj-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libqwt-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | squeeze | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libpq-dev libproj-dev libqt4-dev libqwt5-qt4-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |
	
  | wheezy | ``apt-get install bison cmake doxygen flex git graphviz grass-dev libexpat1-dev libfcgi-dev libgdal1-dev libgeos-dev libgsl0-dev libopenscenegraph-dev libosgearth-dev libpq-dev libproj-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libqwt-dev libspatialindex-dev libspatialite-dev libsqlite3-dev pkg-config pyqt4-dev-tools python python-dev python-qt4 python-qt4-dev python-sip python-sip-dev txt2tags xauth xfonts-base xvfb`` |

五、git

git是一个类似与SVN的版本控制工具, qgis的源代码是用git管理的, 你可以在ubuntu software center 或是用命令行安装git工具。

在 home文件夹下面创建dev/cpp文件夹, 将QGIS的源代码放到这个目录下:

cd ${home}/dev/cpp

git clone git://github.com/qgis/Quantum-GIS.git

推荐的一种得到源代码的途径是直接到QGIS的官方网站下载,这里建议下载 release的稳定版本(笔者经验,master版本有时候编译会出问题,当前是版本是1.7.4)。因为用git从sourceforge上面checkout出来的是不稳定的版本,编译过程可能出现问题。


六、编译源代码(可以选择两种编译方式,如果你的目的还包括改写qgis源代码,可以用第二种QtCreator编译)

(一)命令行编译

1、创建目录${home}/apps

mkdir -p ${HOME}/apps
 
 
2、创建一个build目录,并且运行 ccmake
cd Quantum-GIS
mkdir build-master
cd build-master
ccmake ..
当运行ccmake的时候(..是必须的),会出现一个配置菜单,修改CMAKE_INSTALL_PREFIX为 ${home}/apps.按c开始配置,有时候需要按几次c才会出现g,让你生成make file.
 
 
3、build
命令行输入 
make
make install

4、运行

$home/apps/bin/qgis

如果编译成功,QGIS就会成功运行。

(二)QtCreator编译

1、重新解压出来一份源代码(不要用用过第一种方法编译的那套代码)

2、打开QtCreator

File->Open File or Project

找到源代码的根目录,里面应该有CMakeLists.txt.打开。会出现下图选择build的目录

Ubuntu下编译Quantum GIS(QGIS)_第1张图片

按Next出现下图设置cmake参数 -DCMAKE_BUILD_TYPE=Debug

Ubuntu下编译Quantum GIS(QGIS)_第2张图片

点击Run CMake会自动生成相应的makefiles.然后点击Finish.

3、设置build环境

点击Projects->Build Settings->Add Build Step->Custom Process Step,设置如下图:


默认情况下,QGIS会安装在/usr/local, 此时需要设置你对该目录具有读写权限。


4、设置运行环境,Run Settings(在Build Settings旁边)。

Ubuntu下编译Quantum GIS(QGIS)_第3张图片

覆盖默认的可执行文件,点击Add,选择Custom Executable, 

Executable: /usr/local/bin/qgis
Arguments :
Working directory: $HOME
Run in terminal: [no]
Debugger: C++ [yes]
          Qml [no]
点击Rename,设置可执行文件的名字为Installed QGIS或是其他你喜欢的名字。

设置如下图:

Ubuntu下编译Quantum GIS(QGIS)_第4张图片


5、运行和调试, 设置断点后,点击Start Debugging按钮,即可进入调试模式。


你可能感兴趣的:(python,ubuntu,Flex,git,Build,Graphviz)