164 Q_PROPERTY(
bool isNull READ isNull )
165 Q_PROPERTY(
Qgis::GeometryType type READ type )
243 Q_INVOKABLE static
QgsGeometry fromWkt( const QString &wkt );
328 static QgsGeometry collectGeometry(
const QVector<QgsGeometry> &geometries );
345 static QgsGeometry createWedgeBuffer(
const QgsPoint ¢er,
double azimuth,
double angularWidth,
346 double outerRadius,
double innerRadius = 0 );
353 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
358 void fromWkb(
const QByteArray &wkb );
421 bool isGeosValid(
Qgis::GeometryValidityFlags flags =
Qgis::GeometryValidityFlags() ) const;
430 bool isSimple() const;
445 bool isAxisParallelRectangle(
double maximumDeviation,
bool simpleRectanglesOnly = false ) const;
473 double length() const;
656 double hausdorffDistance(
const QgsGeometry &geom )
const;
675 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
738 double distanceToVertex(
int vertex )
const;
746 double angleAtVertex(
int vertex )
const;
760 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex
SIP_OUT )
const;
774 bool insertVertex(
double x,
double y,
int beforeVertex );
788 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
797 bool addTopologicalPoint(
const QgsPoint &point,
double snappingTolerance = 1e-8,
double segmentSearchEpsilon = 1e-12 );
806 bool moveVertex(
double x,
double y,
int atVertex );
815 bool moveVertex(
const QgsPoint &p,
int atVertex );
828 bool deleteVertex(
int atVertex );
837 bool toggleCircularAtVertex(
int atVertex );
844 QgsPoint vertexAt(
int atVertex )
const;
876 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
971 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
1003 Qgis::GeometryOperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
1011 Qgis::GeometryOperationResult rotate(
double rotation, const
QgsPointXY ¢er );
1023 Q_DECL_DEPRECATED
Qgis::GeometryOperationResult splitGeometry( const QVector<
QgsPointXY> &splitLine, QVector<
QgsGeometry> &newGeometries,
bool topological, QVector<
QgsPointXY> &topologyTestPoints,
bool splitFeature = true )
SIP_SKIP;
1080 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1082 PyObject *p0 = PyList_GetItem( a0, 0 );
1083 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1084 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1086 QVector<QgsGeometry> newGeometries;
1087 QVector<QgsPointXY> topologyTestPoints;
1089 QVector<QgsPointXY> *splitLine =
reinterpret_cast<QVector<QgsPointXY> *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1092 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1098 PyObject *o0 = sipConvertFromEnum(
static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1099 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1100 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1102 sipRes = PyTuple_New( 3 );
1103 PyTuple_SET_ITEM( sipRes, 0, o0 );
1104 PyTuple_SET_ITEM( sipRes, 1, o1 );
1105 PyTuple_SET_ITEM( sipRes, 2, o2 );
1109 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1110 sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1112 QVector<QgsGeometry> newGeometries;
1113 QVector<QgsPoint> topologyTestPoints;
1115 QVector<QgsPoint> *splitLine =
reinterpret_cast<QVector<QgsPoint> *
>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1118 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1124 PyObject *o0 = sipConvertFromEnum(
static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1125 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1126 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1128 sipRes = PyTuple_New( 3 );
1129 PyTuple_SET_ITEM( sipRes, 0, o0 );
1130 PyTuple_SET_ITEM( sipRes, 1, o1 );
1131 PyTuple_SET_ITEM( sipRes, 2, o2 );
1137 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Could not convert first argument to a list of QgsPoint or QgsPointXY." ).toUtf8().constData() );
1143 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"First argument is not a list of points or is empty." ).toUtf8().constData() );
1240 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
1254 QgsGeometry triangularWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1274 QgsGeometry triangularWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1288 QgsGeometry squareWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1308 QgsGeometry squareWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1322 QgsGeometry roundWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1342 QgsGeometry roundWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1357 QgsGeometry applyDashPattern( const QVector<
double > &pattern,
1358 Qgis::DashPatternLineEndingRule startRule =
Qgis::DashPatternLineEndingRule::NoRule,
1359 Qgis::DashPatternLineEndingRule endRule =
Qgis::DashPatternLineEndingRule::NoRule,
1360 Qgis::DashPatternSizeAdjustment adjustment =
Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap,
1361 double patternOffset = 0 ) const;
1374 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
1395 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
1406 bool intersects( const
QgsRectangle &rectangle ) const;
1422 bool intersects( const
QgsGeometry &geometry ) const;
1432 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
1442 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
1454 bool contains(
double x,
double y ) const;
1465 bool contains( const
QgsGeometry &geometry ) const;
1476 bool disjoint( const
QgsGeometry &geometry ) const;
1487 bool touches( const
QgsGeometry &geometry ) const;
1498 bool overlaps( const
QgsGeometry &geometry ) const;
1520 bool crosses( const
QgsGeometry &geometry ) const;
1529 QgsGeometry buffer(
double distance,
int segments ) const;
1542 QgsGeometry buffer(
double distance,
int segments,
Qgis::EndCapStyle endCapStyle,
Qgis::JoinStyle joinStyle,
double miterLimit ) const;
1551 QgsGeometry offsetCurve(
double distance,
int segments,
Qgis::JoinStyle joinStyle,
double miterLimit ) const;
1567 QgsGeometry singleSidedBuffer(
double distance,
int segments,
Qgis::BufferSide side,
1568 Qgis::JoinStyle joinStyle =
Qgis::JoinStyle::Round,
1569 double miterLimit = 2.0 ) const;
1588 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments ) const;
1604 QgsGeometry variableWidthBufferByM(
int segments ) const;
1611 QgsGeometry extendLine(
double startDistance,
double endDistance ) const;
1624 QgsGeometry densifyByCount(
int extraNodesPerSegment ) const;
1639 QgsGeometry densifyByDistance(
double distance ) const;
1656 QgsGeometry convertToCurves(
double distanceTolerance = 1e-8,
double angleTolerance = 1e-8 ) const;
1829 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly = false ) const;
1976 double lineLocatePoint( const
QgsGeometry &point ) const;
1986 double interpolateAngle(
double distance ) const;
2120 const
Qgis::GeometryType type = sipCpp->type();
2121 if ( sipCpp->isNull() )
2123 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Cannot generate points inside a null geometry." ).toUtf8().constData() );
2128 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg(
QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
2133 const sipTypeDef *qvector_type = sipFindType(
"QVector<QgsPointXY>" );
2134 sipRes = sipConvertFromNewType(
new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2164 Q_INVOKABLE QString asWkt(
int precision = 17 )
const;
2167 SIP_PYOBJECT __repr__();
2170 if ( sipCpp->isNull() )
2171 str = QStringLiteral(
"<QgsGeometry: null>" );
2174 QString wkt = sipCpp->asWkt();
2175 if ( wkt.length() > 1000 )
2176 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
2177 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
2179 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
2186 QString asJson(
int precision = 17 )
const;
2221 QVector<
QgsGeometry > coerceToType(
Qgis::WkbType type,
double defaultZ = 0,
double defaultM = 0 ) const;
2234 QgsGeometry convertToType(
Qgis::GeometryType destType,
bool destMultipart = false ) const;
2263 if ( sipCpp->isNull() )
2265 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
2273 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg(
QgsWkbTypes::displayString( geom->
wkbType() ) ).toUtf8().constData() );
2278 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2310 const
Qgis::WkbType type = sipCpp->wkbType();
2311 if ( sipCpp->isNull() )
2313 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
2318 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a polyline. Only single line or curve types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2323 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
2324 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2355 const
Qgis::WkbType type = sipCpp->wkbType();
2356 if ( sipCpp->isNull() )
2358 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
2363 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a polygon. Only single polygon or curve polygon types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2368 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
2369 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2398 const
Qgis::WkbType type = sipCpp->wkbType();
2399 if ( sipCpp->isNull() )
2401 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
2406 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2411 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
2412 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2443 const
Qgis::WkbType type = sipCpp->wkbType();
2444 if ( sipCpp->isNull() )
2446 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
2451 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multilinestring. Only multi linestring or curves are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2456 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
2457 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2488 const
Qgis::WkbType type = sipCpp->wkbType();
2489 if ( sipCpp->isNull() )
2491 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
2496 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipolygon. Only multi polygon or curves are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2501 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QVector<QgsPointXY>>>" );
2502 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2510 QVector<QgsGeometry> asGeometryCollection()
const;
2536 bool deleteRing(
int ringNum,
int partNum = 0 );
2542 bool deletePart(
int partNum );
2552 bool convertToMultiType();
2569 bool convertToCurvedMultiType();
2580 bool convertToSingleType();
2591 bool convertGeometryCollectionToSubclass(
Qgis::GeometryType geomType );
2604 Q_DECL_DEPRECATED
int avoidIntersections( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
2618 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
2652 Qgis::AngularDirection polygonOrientation() const;
2733 : mMessage( QStringLiteral(
"none" ) )
2743 , mHasLocation( true ) {}
2748 QString what()
const;
2758 bool hasWhere()
const;
2761 SIP_PYOBJECT __repr__();
2763 QString
str = QStringLiteral(
"<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
2764 sipRes = PyUnicode_FromString(
str.toUtf8().data() );
2771 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2777 bool mHasLocation =
false;
2817 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
2832 bool requiresConversionToStraightSegments()
const;
2844 void draw( QPainter &p )
const;
2886 void filterVertices( const std::function<
bool( const
QgsPoint & ) > &filter )
SIP_SKIP;
2916 static
QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2947 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2958 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2970 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2991 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2999 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
3000 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3002 PyObject *o0 = PyList_GetItem( a0, 0 );
3003 PyObject *o1 = PyList_GetItem( a1, 0 );
3007 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3008 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3009 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3010 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3014 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3015 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3018 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3019 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3026 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
3027 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3029 PyObject *oo0 = PyList_GetItem( o0, 0 );
3030 PyObject *oo1 = PyList_GetItem( o1, 0 );
3034 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3035 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3036 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3037 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3041 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3042 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3045 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3046 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3053 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
3054 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3056 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3057 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3061 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3062 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3063 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3064 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3068 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3069 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3072 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3073 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3105 QgsGeometry smooth(
unsigned int iterations = 1,
double offset = 0.25,
3106 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
3162 operator QVariant()
const
3164 return QVariant::fromValue( *
this );
3172 mutable QString mLastError;
3184 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3189 QgsGeometry convertToPoint(
bool destMultipart )
const;
3191 QgsGeometry convertToLine(
bool destMultipart )
const;
3193 QgsGeometry convertToPolygon(
bool destMultipart )
const;
3206 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
unsigned int iterations = 1,
double offset = 0.25,
3207 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
3220 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
unsigned int iterations = 1,
double offset = 0.25,
3221 double minimumDistance = -1,
double maxAngle = 180.0 )
const;