164 Q_PROPERTY(
bool isNull READ isNull )
165 Q_PROPERTY(
Qgis::GeometryType type READ type )
244 Q_INVOKABLE static
QgsGeometry fromWkt( const QString &wkt );
329 static QgsGeometry collectGeometry(
const QVector<QgsGeometry> &geometries );
346 static QgsGeometry createWedgeBuffer(
const QgsPoint ¢er,
double azimuth,
double angularWidth,
347 double outerRadius,
double innerRadius = 0 );
354 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
359 void fromWkb(
const QByteArray &wkb );
422 bool isGeosValid(
Qgis::GeometryValidityFlags flags =
Qgis::GeometryValidityFlags() ) const;
431 bool isSimple() const;
446 bool isAxisParallelRectangle(
double maximumDeviation,
bool simpleRectanglesOnly = false ) const;
474 double length() const;
657 double hausdorffDistance(
const QgsGeometry &geom )
const;
676 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
739 double distanceToVertex(
int vertex )
const;
747 double angleAtVertex(
int vertex )
const;
761 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex
SIP_OUT )
const;
775 bool insertVertex(
double x,
double y,
int beforeVertex );
789 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
798 bool addTopologicalPoint(
const QgsPoint &point,
double snappingTolerance = 1e-8,
double segmentSearchEpsilon = 1e-12 );
807 bool moveVertex(
double x,
double y,
int atVertex );
816 bool moveVertex(
const QgsPoint &p,
int atVertex );
829 bool deleteVertex(
int atVertex );
838 bool toggleCircularAtVertex(
int atVertex );
845 QgsPoint vertexAt(
int atVertex )
const;
877 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
972 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
1004 Qgis::GeometryOperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
1012 Qgis::GeometryOperationResult rotate(
double rotation, const
QgsPointXY ¢er );
1024 Q_DECL_DEPRECATED
Qgis::GeometryOperationResult splitGeometry( const QVector<
QgsPointXY> &splitLine, QVector<
QgsGeometry> &newGeometries,
bool topological, QVector<
QgsPointXY> &topologyTestPoints,
bool splitFeature = true )
SIP_SKIP;
1081 if ( PyList_Check( a0 ) && PyList_GET_SIZE( a0 ) )
1083 PyObject *p0 = PyList_GetItem( a0, 0 );
1084 if ( sipCanConvertToType( p0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1085 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1087 QVector<QgsGeometry> newGeometries;
1088 QVector<QgsPointXY> topologyTestPoints;
1090 QVector<QgsPointXY> *splitLine =
reinterpret_cast<QVector<QgsPointXY> *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1093 sipReleaseType( splitLine, sipType_QVector_0100QgsPointXY, state );
1099 PyObject *o0 = sipConvertFromEnum(
static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1100 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1101 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPointXY, Py_None );
1103 sipRes = PyTuple_New( 3 );
1104 PyTuple_SET_ITEM( sipRes, 0, o0 );
1105 PyTuple_SET_ITEM( sipRes, 1, o1 );
1106 PyTuple_SET_ITEM( sipRes, 2, o2 );
1110 else if ( sipCanConvertToType( p0, sipType_QgsPoint, SIP_NOT_NONE ) &&
1111 sipCanConvertToType( a0, sipType_QVector_0100QgsPoint, SIP_NOT_NONE ) )
1113 QVector<QgsGeometry> newGeometries;
1114 QVector<QgsPoint> topologyTestPoints;
1116 QVector<QgsPoint> *splitLine =
reinterpret_cast<QVector<QgsPoint> *
>( sipConvertToType( a0, sipType_QVector_0100QgsPoint, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1119 sipReleaseType( splitLine, sipType_QVector_0100QgsPoint, state );
1125 PyObject *o0 = sipConvertFromEnum(
static_cast<int>( result ), sipType_Qgis_GeometryOperationResult );
1126 PyObject *o1 = sipConvertFromType( &newGeometries, sipType_QVector_0100QgsGeometry, Py_None );
1127 PyObject *o2 = sipConvertFromType( &topologyTestPoints, sipType_QVector_0100QgsPoint, Py_None );
1129 sipRes = PyTuple_New( 3 );
1130 PyTuple_SET_ITEM( sipRes, 0, o0 );
1131 PyTuple_SET_ITEM( sipRes, 1, o1 );
1132 PyTuple_SET_ITEM( sipRes, 2, o2 );
1138 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Could not convert first argument to a list of QgsPoint or QgsPointXY." ).toUtf8().constData() );
1144 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"First argument is not a list of points or is empty." ).toUtf8().constData() );
1241 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
1255 QgsGeometry triangularWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1275 QgsGeometry triangularWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1289 QgsGeometry squareWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1309 QgsGeometry squareWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1323 QgsGeometry roundWaves(
double wavelength,
double amplitude,
bool strictWavelength = false ) const;
1343 QgsGeometry roundWavesRandomized(
double minimumWavelength,
double maximumWavelength,
double minimumAmplitude,
double maximumAmplitude,
unsigned long seed = 0 ) const;
1358 QgsGeometry applyDashPattern( const QVector<
double > &pattern,
1359 Qgis::DashPatternLineEndingRule startRule =
Qgis::DashPatternLineEndingRule::NoRule,
1360 Qgis::DashPatternLineEndingRule endRule =
Qgis::DashPatternLineEndingRule::NoRule,
1361 Qgis::DashPatternSizeAdjustment adjustment =
Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap,
1362 double patternOffset = 0 ) const;
1375 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
1396 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
1407 bool intersects( const
QgsRectangle &rectangle ) const;
1423 bool intersects( const
QgsGeometry &geometry ) const;
1433 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
1443 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
1455 bool contains(
double x,
double y ) const;
1466 bool contains( const
QgsGeometry &geometry ) const;
1477 bool disjoint( const
QgsGeometry &geometry ) const;
1488 bool touches( const
QgsGeometry &geometry ) const;
1499 bool overlaps( const
QgsGeometry &geometry ) const;
1521 bool crosses( const
QgsGeometry &geometry ) const;
1530 QgsGeometry buffer(
double distance,
int segments ) const;
1543 QgsGeometry buffer(
double distance,
int segments,
Qgis::EndCapStyle endCapStyle,
Qgis::JoinStyle joinStyle,
double miterLimit ) const;
1552 QgsGeometry offsetCurve(
double distance,
int segments,
Qgis::JoinStyle joinStyle,
double miterLimit ) const;
1568 QgsGeometry singleSidedBuffer(
double distance,
int segments,
Qgis::BufferSide side,
1569 Qgis::JoinStyle joinStyle =
Qgis::JoinStyle::Round,
1570 double miterLimit = 2.0 ) const;
1589 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments ) const;
1605 QgsGeometry variableWidthBufferByM(
int segments ) const;
1612 QgsGeometry extendLine(
double startDistance,
double endDistance ) const;
1625 QgsGeometry densifyByCount(
int extraNodesPerSegment ) const;
1640 QgsGeometry densifyByDistance(
double distance ) const;
1657 QgsGeometry convertToCurves(
double distanceTolerance = 1e-8,
double angleTolerance = 1e-8 ) const;
1830 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly = false ) const;
1977 double lineLocatePoint( const
QgsGeometry &point ) const;
1987 double interpolateAngle(
double distance ) const;
2121 const
Qgis::GeometryType type = sipCpp->type();
2122 if ( sipCpp->isNull() )
2124 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Cannot generate points inside a null geometry." ).toUtf8().constData() );
2129 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg(
QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
2134 const sipTypeDef *qvector_type = sipFindType(
"QVector<QgsPointXY>" );
2135 sipRes = sipConvertFromNewType(
new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
2165 Q_INVOKABLE QString asWkt(
int precision = 17 )
const;
2168 SIP_PYOBJECT __repr__();
2171 if ( sipCpp->isNull() )
2172 str = QStringLiteral(
"<QgsGeometry: null>" );
2175 QString wkt = sipCpp->asWkt();
2176 if ( wkt.length() > 1000 )
2177 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
2178 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
2180 sipRes = PyUnicode_FromString(
str.toUtf8().constData() );
2187 QString asJson(
int precision = 17 )
const;
2222 QVector<
QgsGeometry > coerceToType(
Qgis::WkbType type,
double defaultZ = 0,
double defaultM = 0 ) const;
2235 QgsGeometry convertToType(
Qgis::GeometryType destType,
bool destMultipart = false ) const;
2264 if ( sipCpp->isNull() )
2266 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
2274 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() );
2279 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
2311 const
Qgis::WkbType type = sipCpp->wkbType();
2312 if ( sipCpp->isNull() )
2314 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
2319 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() );
2324 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
2325 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
2356 const
Qgis::WkbType type = sipCpp->wkbType();
2357 if ( sipCpp->isNull() )
2359 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
2364 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() );
2369 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
2370 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
2399 const
Qgis::WkbType type = sipCpp->wkbType();
2400 if ( sipCpp->isNull() )
2402 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
2407 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
2412 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
2413 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
2444 const
Qgis::WkbType type = sipCpp->wkbType();
2445 if ( sipCpp->isNull() )
2447 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
2452 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() );
2457 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
2458 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
2489 const
Qgis::WkbType type = sipCpp->wkbType();
2490 if ( sipCpp->isNull() )
2492 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
2497 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() );
2502 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QVector<QgsPointXY>>>" );
2503 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
2511 QVector<QgsGeometry> asGeometryCollection()
const;
2537 bool deleteRing(
int ringNum,
int partNum = 0 );
2543 bool deletePart(
int partNum );
2553 bool convertToMultiType();
2570 bool convertToCurvedMultiType();
2581 bool convertToSingleType();
2592 bool convertGeometryCollectionToSubclass(
Qgis::GeometryType geomType );
2605 Q_DECL_DEPRECATED
int avoidIntersections( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
2619 Qgis::GeometryOperationResult avoidIntersectionsV2( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
2653 Qgis::AngularDirection polygonOrientation() const;
2734 : mMessage( QStringLiteral(
"none" ) )
2744 , mHasLocation( true ) {}
2749 QString what()
const;
2759 bool hasWhere()
const;
2762 SIP_PYOBJECT __repr__();
2764 QString
str = QStringLiteral(
"<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
2765 sipRes = PyUnicode_FromString(
str.toUtf8().data() );
2772 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2778 bool mHasLocation =
false;
2818 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
2833 bool requiresConversionToStraightSegments()
const;
2845 void draw( QPainter &p )
const;
2887 void filterVertices( const std::function<
bool( const
QgsPoint & ) > &filter )
SIP_SKIP;
2917 static
QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2948 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2959 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2971 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2992 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
3000 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
3001 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
3003 PyObject *o0 = PyList_GetItem( a0, 0 );
3004 PyObject *o1 = PyList_GetItem( a1, 0 );
3008 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3009 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3010 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3011 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3015 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3016 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3019 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
3020 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
3027 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
3028 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
3030 PyObject *oo0 = PyList_GetItem( o0, 0 );
3031 PyObject *oo1 = PyList_GetItem( o1, 0 );
3035 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3036 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3037 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3038 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3042 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3043 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3046 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
3047 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
3054 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
3055 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
3057 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
3058 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
3062 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3063 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
3064 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
3065 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
3069 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
3070 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
3073 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
3074 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
3106 QgsGeometry smooth(
unsigned int iterations = 1,
double offset = 0.25,
3107 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
3163 operator QVariant()
const
3165 return QVariant::fromValue( *
this );
3173 mutable QString mLastError;
3185 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
3190 QgsGeometry convertToPoint(
bool destMultipart )
const;
3192 QgsGeometry convertToLine(
bool destMultipart )
const;
3194 QgsGeometry convertToPolygon(
bool destMultipart )
const;
3207 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
unsigned int iterations = 1,
double offset = 0.25,
3208 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
3221 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
unsigned int iterations = 1,
double offset = 0.25,
3222 double minimumDistance = -1,
double maxAngle = 180.0 )
const;