• Qt Qgis 二次开发——鼠标点击识别矢量要素


    Qt Qgis 二次开发——鼠标点击识别矢量要素

    介绍:

    识别矢量要素需要用到QGis的一个工具类:QgsMapToolIdentifyFeature

    一个QgsMapTool的子类的子类,官方文档描述:

    接下来就是如何使用了,直接上代码

    代码:

    • 使用(不知道基本用法的可以参考上一篇
    #include "qgsmaptoolidentifyfeature.h"
    
    /* 第一个参数:使用该工具的画布
     * 第二个参数:要识别的要素的图层
     */
    QgsMapToolIdentifyFeature * m_identify = new QgsMapToolIdentifyFeature(m_canvas,m_pLayer); // 创建识别工具
    
    connect(m_identify,SIGNAL(featureIdentified(QgsFeature)),this,SLOT(slo_selectFeature(QgsFeature))); // 关联识别工具识别后的信号,识别后的操作写在槽函数中
    // connect(m_identify,SIGNAL(featureIdentified(QgsFeatureId)),this,SLOT(slo_selectFeature(QgsFeatureId));
    m_canvas->setMapTool(m_identify); // 设置工具到画布
    
    • 槽函数操作
    void Widget::slo_selectFeature(QgsFeature f)
    {
        QgsAttributes field = f.attributes(); // 保存要素属性
        
        /* 将要素的属性写到表格中
         */
        ui->infoTable->insertRow(ui->infoTable->rowCount());
        ui->infoTable->setItem(ui->infoTable->rowCount()-1,0,new QTableWidgetItem(field.at(0).toString()));
        ui->infoTable->setItem(ui->infoTable->rowCount()-1,1,new QTableWidgetItem(field.at(1).toString()));
        ui->infoTable->setItem(ui->infoTable->rowCount()-1,2,new QTableWidgetItem(field.at(2).toString()));
        ui->infoTable->setItem(ui->infoTable->rowCount()-1,3,new QTableWidgetItem(field.at(3).toString()));
    }
    

    效果:

    上一篇:QT QGIS 二次开发——基本用法

  • 相关阅读:
    linux 错误总结
    linux xampp常见问题
    !WebGL
    !站点列表(无关的站点)
    代码: 瀑布流
    插件:★★★ !!!图片懒加载 lazyload.js 、 jquery.scrollLoading.js
    html调用静态json例子
    !!! jquery mobile常用代码
    国内各类“壳子”浏览器,userAgent 一览
    checkbox的美化(转)
  • 原文地址:https://www.cnblogs.com/Doyoung/p/13656632.html
Copyright © 2020-2023  润新知