前言
- 介绍注释(Annotation)图层在QGis中的使用以及二次开发的实现
- 说明:文章中的示例代码均来自开源项目qgis_cpp_api_apps
注释(Annotation)图层
表示包含一组地理参考注释的地图层,例如标记、直线、多边形或文本项。
QGis中的注释(Annotation)图层
- 首先创建一个Annotation图层,如下图所示
- 创建文字类型注释,如下图
二次开发实现线段类型注释(Annotation)
Represents a map layer containing a set of georeferenced annotations, e.g.markers, lines, polygons or text items.
Annotation layers store a set of QgsAnnotationItem items, which are rendered according to the item’s z-order.
- 类
QgsAnnotationLayer
是注释层,详情见文档,类图如下
- 其成员函数
QString addItem (QgsAnnotationItem *item)
用于向图层添加项目 QgsAnnotationItem
是添加注释项目的基类,详情见文档,类图如下
QgsAnnotationItem
的几个基类,分别对应QGis中点、线、多边形和文本注释
文本类型Item
- 类
QgsAnnotationPointTextItem
是文字注释,详情见文档,类图如下
- 测试代码如下
void MainWindow::annotationTextSlot()
{
//添加注释图层
QgsAnnotationLayer *annotationLayer = addTestAnnotationLayer();
//点即Text注释位置
QgsPoint p1(20.33989,-33.86805);
//构造并添加
auto pointText = new QgsAnnotationPointTextItem(QStringLiteral("Test"),p1);
annotationLayer->addItem(pointText);
}
- 效果如下
总结
- 介绍了文本类型注释(Annotation)的应用与二次开发实现