码迷,mamicode.com
首页 > 其他好文 > 详细

Qt4.8.6+mingw+Qgis2.4.0基于QGis的二次开发

时间:2014-11-16 00:41:50      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:qgis二次开发

关于QGis的二次开发,大致看了一下,基本都是在VC+QT的环境下做环境部署,而且QGis的版本非常老,在mingw下直接开发搭建环境的例子少之又少,基于最新的Qgis2.4.0版本做了相应的尝试,并成功搭建相应的环境,大致的配置如下:

由于在搭建的过程之中遇到的问题实在太多,没有一一记录下来,所以在本文中没有做过多的描述,如有疑问可以联系husteryou@163.com,或者留言

环境搭建

bubuko.com,布布扣

bubuko.com,布布扣


bubuko.com,布布扣


pro文件配置

QT       += core gui xml

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = qgisdemo
TEMPLATE = app


SOURCES += main.cpp#     #mainwindow.cpp

#INCLUDEPATH += qgis-2.4.0
#INCLUDEPATH += qgis-2.4.0\core
#INCLUDEPATH += qgis-2.4.0\core\symbology-ng
#INCLUDEPATH += qgis-2.4.0\analysis
#INCLUDEPATH += qgis-2.4.0\gui

INCLUDEPATH += qgis-2.4.0
INCLUDEPATH += qgis-2.4.0/core
INCLUDEPATH += qgis-2.4.0/core/symbology-ng
INCLUDEPATH += qgis-2.4.0/analysis
INCLUDEPATH += qgis-2.4.0/gui


FORMS    += mainwindow.ui

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_analysis
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_analysis
else:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_analysis

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_core
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_core
else:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_core

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_gui
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_gui
else:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_gui

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/



实例

#include "mainwindow.h"
#include <QApplication>

#include <qgis.h>
#include<QApplication>

#include<qgsapplication.h>

#include<qgsproviderregistry.h>

#include<qgssinglesymbolrendererv2.h>

#include<qgsmaplayerregistry.h>

#include<qgsvectorlayer.h>

#include<qgsmapcanvas.h>

#include<QString>

#include<QApplication>

#include<QWidget>


int main( int argc, char *argv[] )

{

//        QApplication a(argc, argv);
//        MainWindow w;
//        w.show();

//        return a.exec();

    QgsApplication a( argc, argv ,true);

       //QApplication a(argc, argv);

    //////////////////////////////////////////////////////////////////////////

    //注意这三行代码需要更改路径;

    QString myPluginsDir        ="D:/Qt/workspace/qgis-2.4.0/qgis-2.4.0/build/output/plugins";

    QString myLayerPath         ="F:/20140605/data_1_3/10m_admin_1_states_provinces_shp.shp";

    QString myLayerBaseName     = "Clip";

    //////////////////////////////////////////////////////////////////////////

    QgsProviderRegistry::instance( myPluginsDir); 

    QgsVectorLayer * mypLayer = new QgsVectorLayer( myLayerPath, myLayerBaseName, "ogr" ); 

    //QgsSingleSymbolRendererV2 *mypRenderer = new QgsSingleSymbolRendererV2( mypLayer->geometryType() );

    QList <QgsMapCanvasLayer> myLayerSet;

   // mypLayer->setRenderer( mypRenderer );

   //mypLayer->setRendererV2(mypRenderer);

    QgsMapLayerRegistry::instance()->addMapLayer( mypLayer, true );

    myLayerSet.append( QgsMapCanvasLayer(mypLayer, true ) );

    QgsMapCanvas * mypMapCanvas = new QgsMapCanvas( 0, 0 );


    mypMapCanvas->setExtent(mypLayer->extent() );

    mypMapCanvas->enableAntiAliasing( true);

    mypMapCanvas->setCanvasColor( QColor(255, 255, 255 ) );

    mypMapCanvas->freeze( false );

    mypMapCanvas->setLayerSet( myLayerSet);

    mypMapCanvas->setVisible( true );

    mypMapCanvas->refresh();

    mypMapCanvas->show();

    return a.exec();
}


运行结果

bubuko.com,布布扣

Qt4.8.6+mingw+Qgis2.4.0基于QGis的二次开发

标签:qgis二次开发

原文地址:http://blog.csdn.net/youfangyuan/article/details/41154647

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!