博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Qt4.8.6+mingw+Qgis2.4.0基于QGis的二次开发
阅读量:6344 次
发布时间:2019-06-22

本文共 4954 字,大约阅读时间需要 16 分钟。

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

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

环境搭建

pro文件配置

QT       += core gui xmlgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = qgisdemoTEMPLATE = appSOURCES += 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\guiINCLUDEPATH += qgis-2.4.0INCLUDEPATH += qgis-2.4.0/coreINCLUDEPATH += qgis-2.4.0/core/symbology-ngINCLUDEPATH += qgis-2.4.0/analysisINCLUDEPATH += qgis-2.4.0/guiFORMS    += mainwindow.uiwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_analysiselse:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_analysiselse:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_analysisINCLUDEPATH += $$PWD/DEPENDPATH += $$PWD/win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_coreelse:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_coreelse:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_coreINCLUDEPATH += $$PWD/DEPENDPATH += $$PWD/win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_guielse:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibqgis_guielse:unix:!macx: LIBS += -L$$PWD/lib/ -llibqgis_guiINCLUDEPATH += $$PWD/DEPENDPATH += $$PWD/

实例

 
#include 
#include 
#include 
 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#include "mouseprocess.h"
#include "paintprocess.h"
 
 
int main( int argc, char *argv[] )
{
 
QgsApplication a( argc, argv ,true);
 
//
 
//注意这三行代码须要更改路径;
QString myPluginsDir        ="D:/Qt/workspace/qgis-2.4.0/qgis-2.4.0/build/output/plugins";//插件路径(编译好的qgis目录下的plugins目录);
QString myLayerPath1         ="F:/gis/data_1_3/10m_admin_0_countries.shp";//图层路径,必须设置为你电脑里面shp文件的路径,不然打不开数据;
QString myLayerPath2         ="F:/gis/qgis_sample_data/shapefiles/airports.shp";//图层路径,必须设置为你电脑里面shp文件的路径,不然打不开数据;
 
//
QgsProviderRegistry::instance( myPluginsDir); //初始化插件的文件夹;
 
QgsVectorLayer * mypLayer1 = new QgsVectorLayer( myLayerPath1, "myLayer1", "ogr" ); //初始化矢量图层;
QgsVectorLayer * mypLayer2 = new QgsVectorLayer( myLayerPath2, "myLayer2", "ogr" ); //初始化矢量图层;
QgsVectorLayer * mypLayer3 = new QgsVectorLayer(); //初始化矢量图层;
mypLayer3->setRendererV2(QgsFeatureRendererV2::defaultRenderer(QGis::Point));
 
QgsFeatureIterator iter = mypLayer2->getFeatures();
QgsFeature feature;
while(iter.nextFeature(feature)){
QgsGeometry *geo = feature.geometry();
QgsPoint point = geo->asPoint();
//qDebug() << point.x() << point.y() << endl;
}
 
for(int index = 0; index < 100; index ++){
QgsPoint point;
 
double xmin = -4.4802e+06;
double xmax = 4.61512e+06;
double ymin = 1.43353e+06;
double ymax = 6.50259e+06;
 
point.setX(xmin + (xmax - xmin) * ((double) qrand()) / RAND_MAX);
point.setY(ymin + (ymax - ymin) * ((double) qrand()) / RAND_MAX);
 
QgsFeature feature;
QgsGeometry *geo = QgsGeometry::fromPoint(point);
feature.setGeometry(geo);
mypLayer3->addFeature(feature);
mypLayer3->updateFeature(feature);
 
qDebug() << point.x() << point.y() << endl;
}
 
QList
ring;
 
//-4.4802e+06 4.61512e+06 1.43353e+06 6.50259e+06
ring.append(QgsPoint(-4.4802e+06, 1.43353e+06));
ring.append(QgsPoint(4.61512e+06, 6.50259e+06));
ring.append(QgsPoint(2.61512e+06, 4.50259e+06));
//mypLayer2->addRing(ring);
 
qDebug() << mypLayer2->featureCount() << endl;
 
//QgsSingleSymbolRendererV2 *mypRenderer = new QgsSingleSymbolRendererV2( mypLayer->geometryType() );
QList 
myLayerSet;
// mypLayer->setRenderer( mypRenderer );
//mypLayer->setRendererV2(mypRenderer);
 
QgsMapLayerRegistry::instance()->addMapLayer( mypLayer1, true );
QgsMapLayerRegistry::instance()->addMapLayer( mypLayer2, true );
QgsMapLayerRegistry::instance()->addMapLayer( mypLayer3, true );
 
//myLayerSet.append( QgsMapCanvasLayer(mypLayer3, true ) );
myLayerSet.append( QgsMapCanvasLayer(mypLayer2, true ) );
//myLayerSet.append( QgsMapCanvasLayer(mypLayer1, true ) );
 
QgsRectangle extent = mypLayer2->extent();
qDebug() << extent.xMinimum() << extent.xMaximum() << extent.yMinimum() << extent.yMaximum() << endl;
 
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas( 0, 0 );
mypMapCanvas->setExtent(mypLayer2->extent() );
mypMapCanvas->enableAntiAliasing( true);
mypMapCanvas->setCanvasColor( QColor(255, 255, 255 ) );
mypMapCanvas->freeze( false );
mypMapCanvas->setLayerSet( myLayerSet);
mypMapCanvas->setVisible( true );
mypMapCanvas->refresh();
mypMapCanvas->show();
 
MouseProcess *mouseProcess = new MouseProcess();
PaintProcess *paintProcess = new PaintProcess();
QObject::connect(mypMapCanvas, SIGNAL(xyCoordinates(QgsPoint)), mouseProcess, SLOT(xyCoordinates(QgsPoint)));
QObject::connect(mypMapCanvas, SIGNAL(renderComplete(QPainter*)), paintProcess, SLOT(renderComplete(QPainter*)));
return a.exec();
}
 
 
 

执行结果

你可能感兴趣的文章
NHibernate 2.0 Beta 1 Released和一些工具
查看>>
【每天一个Linux命令】12. Linux中which命令的用法
查看>>
软件接口数据一致性机制
查看>>
微服务架构介绍和RPC框架对比
查看>>
Debian下使用OpenLDAP 管理端
查看>>
泛型排序器TComparer
查看>>
9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路...
查看>>
创建符合标准的、有语意的HTML页面——ASP.NET 2.0 CSS Friendly Control Adapters 1.0发布...
查看>>
Adobe驳斥Flash过度耗电论 称HTML5更耗电
查看>>
No!No!No! It's not fashion!
查看>>
艰困之道中学到的经验教训
查看>>
互联网生态建设落地五大挑战——保险科技生态建设 ...
查看>>
进行短视频app开发工作时,可以加入它来保护青少年 ...
查看>>
25G DAC无源高速线缆和25G光模块之间的区别
查看>>
乐乐茶完成近2亿元Pre-A轮融资,祥峰投资领投
查看>>
clickhouse修改时区
查看>>
CSS_定位
查看>>
第二十四章:页面导航(六)
查看>>
IP_VFR-4-FRAG_TABLE_OVERFLOW【cisco设备报错】碎片***
查看>>
Codeforces Round #256 (Div. 2) D. Multiplication Table 【二分】
查看>>