shp文件显示

开发环境

Win7, VS2010 Sp1

QGIS 2.01

#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrendererv2.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>

#pragma comment(lib, "qgis_core.lib")
#pragma comment(lib, "qgis_gui.lib")

int main(int argc, char ** argv)
{
    QgsApplication app(argc, argv, true);
    QString pluginPath = "D:/Soft/QGIS-master/build/output/plugins/Debug";
    QString layerPath = "D:/temp/1_hello_world_qgis_style/3.china";
    QString layerName = "CHN_adm3.shx";
    QString pluginName = "ogr";

    //初始化插件
    QgsProviderRegistry::instance(pluginPath);
    
    //初始化矢量图层
    QgsVectorLayer * vectorLayer = new QgsVectorLayer(layerPath, layerName, pluginName);
    //注册图层
    QgsMapLayerRegistry::instance()->addMapLayer(vectorLayer, TRUE);

    //创建图层表
    QList<QgsMapCanvasLayer> layerSet;
    //添加图层到图形表中
    layerSet.append(QgsMapCanvasLayer(vectorLayer, true));

    QgsMapCanvas * canvas = new QgsMapCanvas();
    canvas->setExtent(vectorLayer->extent());
    canvas->setLayerSet(layerSet);
    canvas->show();
    return app.exec();
}

 

posted @ 2013-12-01 15:16  20118281131  阅读(1050)  评论(0编辑  收藏  举报