本页内容

QGeoPolygon Class

QGeoPolygon 类定义了一个地理多边形。更多内容...

头文件: #include <QGeoPolygon>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning
继承自: QGeoShape

属性

公共函数

QGeoPolygon()
QGeoPolygon(const QGeoShape &other)
QGeoPolygon(const QList<QGeoCoordinate> &path)
QGeoPolygon(const QGeoPolygon &other)
~QGeoPolygon()
void addCoordinate(const QGeoCoordinate &coordinate)
void addHole(const QList<QGeoCoordinate> &holePath)
void addHole(const QVariant &holePath)
bool containsCoordinate(const QGeoCoordinate &coordinate) const
QGeoCoordinate coordinateAt(qsizetype index) const
const QVariantList hole(qsizetype index) const
const QList<QGeoCoordinate> holePath(qsizetype index) const
qsizetype holesCount() const
void insertCoordinate(qsizetype index, const QGeoCoordinate &coordinate)
double length(qsizetype indexFrom = 0, qsizetype indexTo = -1) const
(since QtPositioning 5.12) const QList<QGeoCoordinate> &perimeter() const
void removeCoordinate(const QGeoCoordinate &coordinate)
void removeCoordinate(qsizetype index)
void removeHole(qsizetype index)
void replaceCoordinate(qsizetype index, const QGeoCoordinate &coordinate)
(since QtPositioning 5.12) void setPerimeter(const QList<QGeoCoordinate> &path)
qsizetype size() const
QString toString() const
void translate(double degreesLatitude, double degreesLongitude)
QGeoPolygon translated(double degreesLatitude, double degreesLongitude) const
QGeoPolygon &operator=(const QGeoPolygon &other)

详细说明

该多边形由一组有序的QGeoCoordinate 对象列表定义,这些对象代表其周长。

该列表中任意两个相邻元素应通过一条恒定方位角且穿过这两个元素的最短线段连接起来。此类连接可在经度方向上跨越国际日期变更线,但绝不会穿越两极。

这与计算QGeoShape::boundingGeoRectangle() 针对该形状返回的边界框有关,该边界框的左上角纬度将设置为路径点集中的最大纬度。同样,右下角的纬度将设置为路径点集中的最小纬度。

在 QML 中,该类也可通过geoPolygon 访问。

属性文档

perimeter : QList<QGeoCoordinate>

该属性存储多边形周长的坐标。

访问函数:

const QList<QGeoCoordinate> &perimeter() const
void setPerimeter(const QList<QGeoCoordinate> &path)

成员函数文档

QGeoPolygon::QGeoPolygon()

创建一个新的、空的多边形几何体。

QGeoPolygon::QGeoPolygon(const QGeoShape &other)

根据other 中的内容构建一个新的地理多边形。

QGeoPolygon::QGeoPolygon(const QList<QGeoCoordinate> &path)

根据path 中指定的坐标,构建一个新的几何多边形。

QGeoPolygon::QGeoPolygon(const QGeoPolygon &other)

根据other 中的内容构建一个新的地理多边形。

[noexcept] QGeoPolygon::~QGeoPolygon()

删除该多边形。

[invokable] void QGeoPolygon::addCoordinate(const QGeoCoordinate &coordinate)

将coordinate 追加到多边形中。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

void QGeoPolygon::addHole(const QList<QGeoCoordinate> &holePath)

重载方法。为多边形内的孔设置holePath 。该孔是一个QList<QGeoCoordinate>。

[invokable] void QGeoPolygon::addHole(const QVariant &holePath)

设置多边形内部孔洞的holePath 。该孔洞是一个QVariant ,其中包含一个QList<QGeoCoordinate>。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] bool QGeoPolygon::containsCoordinate(const QGeoCoordinate &coordinate) const

如果多边形的周长包含coordinate 作为其中一个元素,则返回true。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QGeoCoordinate QGeoPolygon::coordinateAt(qsizetype index) const

返回坐标index 。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] const QVariantList QGeoPolygon::hole(qsizetype index) const

返回一个QVariant ,其中包含一个QList<QGeoCoordinate>,该对象表示位于index 的孔洞。

注意: 可以通过元对象系统以及从 QML 中调用此 函数。参见Q_INVOKABLE 。

const QList<QGeoCoordinate> QGeoPolygon::holePath(qsizetype index) const

返回一个QList<QGeoCoordinate>,它表示index 处的空洞。

[invokable] qsizetype QGeoPolygon::holesCount() const

返回孔的数量。

注意: 可以通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。

[invokable] void QGeoPolygon::insertCoordinate(qsizetype index, const QGeoCoordinate &coordinate)

在指定的index 位置插入coordinate 。

注意: 可通过元对象系统以及从 QML 中调用此 函数。参见Q_INVOKABLE 。

[invokable] double QGeoPolygon::length(qsizetype indexFrom = 0, qsizetype indexTo = -1) const

返回多边形周长(单位:米),起始点为元素indexFrom ,终点为元素indexTo 。该长度应为每对相邻点之间最短距离之和。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[since QtPositioning 5.12] const QList<QGeoCoordinate> &QGeoPolygon::perimeter() const

返回多边形周长中的所有元素。

注意: 这是属性 perimeter 的获取 函数。

该函数在 QtPositioning 5.12 中引入。

另请参阅 setPerimeter()。

[invokable] void QGeoPolygon::removeCoordinate(const QGeoCoordinate &coordinate)

从多边形中移除最后一个coordinate 实例。

注意: 可通过元对象系统或从 QML 中调用此 函数。请参阅Q_INVOKABLE 。

[invokable] void QGeoPolygon::removeCoordinate(qsizetype index)

从多边形中移除位于坐标index 处的元素。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPolygon::removeHole(qsizetype index)

从孔列表中移除位于位置index 的元素。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPolygon::replaceCoordinate(qsizetype index, const QGeoCoordinate &coordinate)

将位于指定index 处的path元素替换为coordinate 。

注意: 可通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。

[since QtPositioning 5.12] void QGeoPolygon::setPerimeter(const QList<QGeoCoordinate> &path)

根据坐标列表path 设置多边形的边界。

注意: 这是属性perimeter 的设置 函数。

该函数在 QtPositioning 5.12 版本中引入。

另请参阅 perimeter()。

[invokable] qsizetype QGeoPolygon::size() const

返回多边形中的元素个数。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QString QGeoPolygon::toString() const

返回地理多边形属性,格式为字符串。

注意: 可通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。

[invokable] void QGeoPolygon::translate(double degreesLatitude, double degreesLongitude)

将该地理多边形向北平移degreesLatitude ,向东平移degreesLongitude 。

degreesLatitude 和degreesLongitude 的负值分别对应向南和向西的平移。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QGeoPolygon QGeoPolygon::translated(double degreesLatitude, double degreesLongitude) const

返回该地理多边形的副本,该副本经过了degreesLatitude 向北平移和degreesLongitude 向东平移。

degreesLatitude 和degreesLongitude 的负值分别对应向南和向西的平移。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

另请参阅 translate()。

QGeoPolygon &QGeoPolygon::operator=(const QGeoPolygon &other)

将other 分配给该地理多边形,并返回该地理多边形的引用。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.