1

Quantum GIS (qgis) is an open source GIS software. The functionality of qgis can be extended by plugins written in python or c++. This question is related to the DTClassifier which is c++ based. DTClassifier make it possible to automate the classification of raster maps, such as automate the classification of forests on remote sensed data.

I want to install the plugin on qgis 1.8.0 (Ubuntu 12.04 64-bit), that is done by placing the compiled linux DTClassifier plugin file into

/usr/lib/qgis/plugins 

However, that is a 32-bit binary сompiled under 32-bit Slackware 13.1 using OpenCV 2.3.1 while my os is Ubuntu 12.04 64 bit. Puting the file into

/usr/lib/qgis/plugins

is not recognized by qgis. Maybe because I have 64-bit os and OpenCV 2.4.1. So I tried to compile the provided source code but failed to do so. Anybody who could provide me with help how to compile the plugin or provide a already compiled file?

This is what I have accomplished so far:

I installed OpenCV 2.4.1, and Qt4, and downloaded the source for DTClassifier

svn co http://svn.gis-lab.info/dtclassifier/trunk dtclassifier

This source was put into the qgis-1.8.0 source. Then cmake was run with the CMakeLists.txt:

I found this (forum message) which is points to a 64-bit version for Ubuntu 11.04, but I could not make it work.

The details of what I have tried so far can be found below:

~/qgis-1.8.0/src/plugins/dtclassifier cmake .

The CMakeLists.txt

# set path to additional CMake modules
cmake_minimum_required (VERSION 2.6)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH})

FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Qt4)
INCLUDE(${QT_USE_FILE})

########################################################
# Files

SET (CLASSIFIER_SRCS
 classifier.cpp
 classifierdialog.cpp
 classifierutils.cpp
 rasterfileinfo.cpp
 layerselectordialog.cpp
)

SET (CLASSIFIER_UIS
 classifierdialogbase.ui
 layerselectordialogbase.ui
)

SET (CLASSIFIER_MOC_HDRS
 classifier.h
 classifierdialog.h
 layerselectordialog.h
)

SET (CLASSIFIER_RCCS  classifier.qrc)

########################################################
# Build

QT4_WRAP_UI (CLASSIFIER_UIS_H  ${CLASSIFIER_UIS})
QT4_WRAP_CPP (CLASSIFIER_MOC_SRCS  ${CLASSIFIER_MOC_HDRS})
QT4_ADD_RESOURCES(CLASSIFIER_RCC_SRCS ${CLASSIFIER_RCCS})

ADD_LIBRARY (classifierplugin MODULE
${CLASSIFIER_SRCS}
${CLASSIFIER_MOC_SRCS}
${CLASSIFIER_RCC_SRCS}
${CLASSIFIER_UIS_H}
)

INCLUDE_DIRECTORIES(
 ${CMAKE_CURRENT_BINARY_DIR}
 ${GDAL_INCLUDE_DIR}
 ${OpenCV_INCLUDE_DIR}
 ../../core/raster
 ../../core/renderer
 ../../core/symbology
 ../../core
 ../../gui
 ..
 .
 #/usr/include/opencv2
 )

TARGET_LINK_LIBRARIES(classifierplugin
 qgis_core
 qgis_gui
 ${OpenCV_LIBS}
 #/usr/lib/libopencv_core.so
 #/usr/lib/libopencv_ml.so
 #/usr/lib/libopencv_highgui.so
 #/usr/lib/libopencv_imgproc.so
)


########################################################
# Install

INSTALL(TARGETS classifierplugin
RUNTIME DESTINATION /usr/lib/qgis/plugins
LIBRARY DESTINATION /usr/lib/qgis/plugins
)

It did not give any error

-- Configuring done
-- Generating done
-- Build files have been written to: qgis-1.8.0/src/plugins/dtclassifier

. But then make fails complaining a lot:

make
[  6%] Building CXX object CMakeFiles/classifierplugin.dir/classifier.cpp.o
In file included from /qgis-1.8.0/src/plugins/dtclassifier/../../gui/qgisinterface.h:40:0,
from /qgis-1.8.0/src/plugins/dtclassifier/classifier.cpp:23:
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:30:19: error: variable ‘CORE_EXPORT QGis’ has initializer but incomplete type
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:30:19: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:32:3: error: expected primary-expression before ‘public’
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:32:3: error: expected ‘}’ before ‘public’
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:32:3: error: expected ‘,’ or ‘;’ before ‘public’
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:38:22: error: uninitialized const ‘QGIS_VERSION_INT’ [-fpermissive]
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:77:47: error: storage size of ‘qgisVectorGeometryType’ isn’t known
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:80:41: error: storage size of ‘qgisFeatureTypes’ isn’t known
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:108:25: error: uninitialized const ‘DEFAULT_IDENTIFY_RADIUS’ [-fpermissive]
/qgis-1.8.0/src/plugins/dtclassifier/../../core/qgis.h:109:1: error: expected declaration before ‘}’ token
make[2]: *** [CMakeFiles/classifierplugin.dir/classifier.cpp.o] Error 1
make[1]: *** [CMakeFiles/classifierplugin.dir/all] Error 2
make: *** [all] Error 2
4

1 回答 1

1

在 Quantum GIS (qgis) 版本 1.8.0 Ubuntu 64 位上编译 DTClassifier c++ 插件。

这是我如何在 Ubuntu 12.04 64 位上编译 DTClassifier 插件的简短说明。这可能不是最佳实践,但确实有效!

获取源代码

找出哪个版本的 qgis 与插件兼容。在 DTClassifier 的文档中,它已使用 OpenCV 2.3.1 在 32 位 Slackware 13.1 上的 qgis 1.8 上编译和测试。我的出发点是首先在我的系统上编译 qgis。所以我发现这个关于编译 qgis 的优秀指南我按照指南中的步骤 1 - 3.7 进行操作,除了我没有使用步骤 3.6 中建议的源

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

这是 qgis 1.9 但这里我们需要qgis 1.8因此,请下载我从“7 Sources and Sample Datase” 1.8 Final Release下载的 qgis 版本 1.8的源代码。(如何编译的说明也在源代码存档中作为文件“INSTALL”提供。)

关于我编译 qgis 的经验的注释。

我在使用 proj 和/或 gdal 库时遇到了一些麻烦。起初我有一个更高版本的 gdal 库,但使用 gdal 1.7.3 和 proj 4.8(由 synaptic 报告但 proj 命令报告版本 4.7)在整理 proj/gdal 故障后,编译成功,可以尝试 qgis。

如果您在尝试执行已编译的 qgis 文件时遇到错误,这可能会对您有所帮助:加载共享库时出错:libqgis_core.so.1.8.0: 无法打开共享对象文件:没有这样的文件或目录

继续编译 DTClassifier

DTClassifier 依赖于 OpenCV 库。我按照这个优秀的指南安装和测试 OpenCv 2.4.1 安装-opencv -2-4-1-ubuntu-12-04-lts

DTClassifier 的源码放在

qgis-1.8.0/src/plugins/dtclassifier

然后到 plugins 目录中的 cmakelist 文件需要还应该构建 DTClassifier 的信息:

qgis-1.8.0/src/plugins/CMakeLists.txt

此行已添加

ADD_SUBDIRECTORY(dtclassifier)

然后重复qgis的编译过程。请记住从安装指南中的步骤 3.7 运行“ccmake ..”,以便更新配置信息。现在配置应该有包含 OpenCV 库配置的行。这一次“make”运行得更快,因为之前的编译。

在 qgis 中,DTclassifier 插件现在应该在 qgis 插件管理器中显示为 DTclassifier。但是我在 qgis 1.8.0 的 ubuntu apt-get 版本中运行插件。所以生成的编译 DTClassifier 文件

qgis-1.8.0/build-master/output/lib/qgis/plugins/libclassifierplugin.so

需要放在qgis plugins目录下(通常是“/usr/lib/qgis/plugins”)。

它对我有用,希望它也对你有用!

注意:如果您尝试针对 qgis 1.9 编译 DTClassifier,那么您很可能会得到与此类似的错误列表:

 classifierdialog.cpp:328:13: error: ‘class QgsVectorDataProvider’ has no member named ‘select’

那是因为 1.9 版本的 qgis 类的 API 发生了变化?

于 2013-02-24T09:14:08.940 回答