QgsPolygoy没有append方法
时间: 2023-10-11 11:10:46 浏览: 29
非常抱歉,我之前的回答有误。您是正确的,QgsPolygon类没有`append()`方法。要添加点到QgsPolygon对象中,您需要使用QgsCurvePolygon类或QgsPolygon类的构造函数来创建一个新的多边形。
以下是一个示例代码,演示了如何向QgsPolygon对象中添加点:
```cpp
#include <QgsGeometry.h>
#include <QgsFeature.h>
#include <QgsVectorLayer.h>
// 创建一个空的QgsPolygon对象
QgsPolygon polygon;
// 定义一组点
QList<QgsPointXY> points;
// 添加点到points列表中...
// 将点转换为QgsPoint对象,并添加到polygon中
for (const QgsPointXY& point : points)
{
QgsPoint qgsPoint(point.x(), point.y());
polygon << qgsPoint;
}
// 创建一个QgsFeature对象,将polygon设置为其几何属性
QgsFeature feature;
feature.setGeometry(QgsGeometry::fromPolygonXY(polygon));
// 将feature添加到图层中
QgsVectorLayer* vectorLayer; // 替换为实际的矢量图层对象
vectorLayer->dataProvider()->addFeatures({ feature });
```
请注意,在上述示例代码中,我们使用`<<`操作符将点添加到`polygon`中。
希望这次的回答能够帮助到您!如果您还有其他问题,请随时提问。