为了实现在已经给定的矢量图层(地图)上,可以随意标注额外的信息,采用了以下的方案:
新增空白矢量图层(点或线)----向点、线图层加入特征(Feature)
1 新增空白矢量图层
首先关注Qgis里,矢量图层新建的参数列表
https://qgis.org/api/3.10/classQgsVectorLayer.html#details
gsVectorLayer::QgsVectorLayer (const QString & path = QString(),
const QString & baseName = QString(),
const QString & providerLib = "ogr",
const QgsVectorLayer::LayerOptions & options = QgsVectorLayer::LayerOptions()
)
在之前加入已有的矢量图层中,provider采用的为ogr格式,为了可以新增一个空白的图层,可以采用memory的provider格式。
通过修改path的开头处的类型,即可实现不同图层新建的操作
具体实现代码:
QString path = "multiPoint?";
// 几何类型,"point", "linestring", "polygon", "multipoint","multilinestring","multipolygon"
path.append( QString( "crs=EPSG:4326&")); //参照坐标系
path.append( QString( "field=id:integer&field=name:string(50)&")); //添加字段属性
path.append( QString( "index=yes&" )); // 创建索引
path.append( QString( "memoryid=%1").arg(QUuid::createUuid().toString())); // 临时编码
// 创建新矢量图层
QgsVectorLayer* NewLayer = new QgsVectorLayer( path, QString("Temporary Layer"), QString( "memory"));
<什么是dataprovider(个人理解,可能有误):dataprovider是在Qgis中,是链接源数据格式(例如shp文件)与Qgis内部数据格式的桥梁,用对应的方式进行数据解析。