21 #include <QDomDocument>
22 #include <QJsonObject>
31 #include "qgis_core.h"
40 #include "json_fwd.hpp"
41 using namespace nlohmann;
126 Q_PROPERTY(
bool isNull READ isNull )
138 NothingHappened = 1000,
156 Q_ENUM( OperationResult )
293 static
QgsGeometry createWedgeBuffer( const
QgsPoint ¢er,
double azimuth,
double angularWidth,
294 double outerRadius,
double innerRadius = 0 );
301 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
307 void fromWkb( const QByteArray &wkb );
327 bool isEmpty() const;
369 FlagAllowSelfTouchingHoles = 1 << 0,
371 Q_DECLARE_FLAGS( ValidityFlags, ValidityFlag )
380 bool isGeosValid( QgsGeometry::ValidityFlags flags = QgsGeometry::ValidityFlags() )
const;
390 bool isSimple()
const;
418 double length()
const;
605 double hausdorffDistance(
const QgsGeometry &geom )
const;
625 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
651 double distanceToVertex(
int vertex )
const;
660 double angleAtVertex(
int vertex )
const;
674 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex
SIP_OUT )
const;
688 bool insertVertex(
double x,
double y,
int beforeVertex );
702 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
711 bool moveVertex(
double x,
double y,
int atVertex );
720 bool moveVertex(
const QgsPoint &p,
int atVertex );
733 bool deleteVertex(
int atVertex );
740 QgsPoint vertexAt(
int atVertex )
const;
774 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
794 OperationResult addRing(
const QVector<QgsPointXY> &ring );
840 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
846 OperationResult translate(
double dx,
double dy,
double dz = 0.0,
double dm = 0.0 );
872 OperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
880 OperationResult rotate(
double rotation, const
QgsPointXY ¢er );
934 OperationResult reshapeGeometry( const
QgsLineString &reshapeLineString );
1007 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
1021 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
1043 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
1054 bool intersects( const
QgsRectangle &rectangle ) const;
1065 bool intersects( const
QgsGeometry &geometry ) const;
1076 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
1087 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
1098 bool contains( const
QgsGeometry &geometry ) const;
1104 bool disjoint( const
QgsGeometry &geometry ) const;
1110 bool touches( const
QgsGeometry &geometry ) const;
1116 bool overlaps( const
QgsGeometry &geometry ) const;
1129 bool crosses( const
QgsGeometry &geometry ) const;
1137 Q_ENUM( BufferSide )
1146 Q_ENUM( EndCapStyle )
1164 QgsGeometry buffer(
double distance,
int segments )
const;
1178 QgsGeometry buffer(
double distance,
int segments, EndCapStyle endCapStyle, JoinStyle joinStyle,
double miterLimit )
const;
1188 QgsGeometry offsetCurve(
double distance,
int segments, JoinStyle joinStyle,
double miterLimit )
const;
1205 QgsGeometry singleSidedBuffer(
double distance,
int segments, BufferSide side,
1206 JoinStyle joinStyle = JoinStyleRound,
1207 double miterLimit = 2.0 )
const;
1226 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments )
const;
1242 QgsGeometry variableWidthBufferByM(
int segments )
const;
1250 QgsGeometry extendLine(
double startDistance,
double endDistance )
const;
1264 QgsGeometry densifyByCount(
int extraNodesPerSegment )
const;
1280 QgsGeometry densifyByDistance(
double distance )
const;
1297 QgsGeometry convertToCurves(
double distanceTolerance = 1e-8,
double angleTolerance = 1e-8 )
const;
1379 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly =
false )
const;
1400 QgsGeometry subdivide(
int maxNodes = 256 )
const;
1430 double lineLocatePoint(
const QgsGeometry &point )
const;
1441 double interpolateAngle(
double distance )
const;
1564 const
QgsWkbTypes::GeometryType type = sipCpp->type();
1565 if ( sipCpp->isNull() )
1567 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Cannot generate points inside a null geometry." ).toUtf8().constData() );
1572 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg(
QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
1577 const sipTypeDef *qvector_type = sipFindType(
"QVector<QgsPointXY>" );
1578 sipRes = sipConvertFromNewType(
new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
1593 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() )
const;
1602 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() )
const;
1609 QString asWkt(
int precision = 17 )
const;
1612 SIP_PYOBJECT __repr__();
1615 if ( sipCpp->isNull() )
1616 str = QStringLiteral(
"<QgsGeometry: null>" );
1619 QString wkt = sipCpp->asWkt();
1620 if ( wkt.length() > 1000 )
1621 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
1622 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
1624 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1631 QString asJson(
int precision = 17 )
const;
1704 if ( sipCpp->isNull() )
1706 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
1711 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1716 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1747 if ( sipCpp->isNull() )
1749 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1754 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() );
1759 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
1760 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1791 if ( sipCpp->isNull() )
1793 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1798 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() );
1803 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
1804 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1833 if ( sipCpp->isNull() )
1835 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
1840 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1845 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
1846 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
1877 if ( sipCpp->isNull() )
1879 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
1884 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() );
1889 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
1890 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
1921 if ( sipCpp->isNull() )
1923 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
1928 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() );
1933 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QVector<QgsPointXY>>>" );
1934 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
1943 QVector<QgsGeometry> asGeometryCollection()
const;
1972 bool deleteRing(
int ringNum,
int partNum = 0 );
1979 bool deletePart(
int partNum );
1989 bool convertToMultiType();
2000 bool convertToSingleType();
2011 bool convertGeometryCollectionToSubclass(
QgsWkbTypes::GeometryType geomType );
2023 int avoidIntersections( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
2062 : mMessage( QStringLiteral(
"none" ) )
2072 , mHasLocation( true ) {}
2077 QString what()
const;
2087 bool hasWhere()
const;
2090 SIP_PYOBJECT __repr__();
2092 QString str = QStringLiteral(
"<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
2093 sipRes = PyUnicode_FromString( str.toUtf8().data() );
2099 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
2105 bool mHasLocation =
false;
2126 void validateGeometry( QVector<QgsGeometry::Error> &errors
SIP_OUT, ValidationMethod method = ValidatorQgisInternal, QgsGeometry::ValidityFlags flags = QgsGeometry::ValidityFlags() )
const;
2133 static QgsGeometry unaryUnion(
const QVector<QgsGeometry> &geometries );
2143 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
2160 bool requiresConversionToStraightSegments()
const;
2174 void draw( QPainter &p )
const;
2219 void filterVertices( const std::function<
bool( const
QgsPoint & ) > &filter )
SIP_SKIP;
2251 static
QgsGeometry fromQPolygonF( const QPolygonF &polygon );
2283 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2295 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2308 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2330 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2338 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
2339 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
2341 PyObject *o0 = PyList_GetItem( a0, 0 );
2342 PyObject *o1 = PyList_GetItem( a1, 0 );
2346 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2347 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2348 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2349 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2353 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2354 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2357 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
2358 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
2365 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
2366 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
2368 PyObject *oo0 = PyList_GetItem( o0, 0 );
2369 PyObject *oo1 = PyList_GetItem( o1, 0 );
2373 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2374 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2375 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2376 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2380 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2381 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2384 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2385 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2392 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2393 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2395 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2396 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2400 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2401 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2402 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2403 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2407 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2408 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2411 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2412 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2445 QgsGeometry smooth(
unsigned int iterations = 1,
double offset = 0.25,
2446 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
2458 static void convertPointList(
const QVector<QgsPointXY> &input,
QgsPointSequence &output );
2465 static void convertPointList(
const QgsPointSequence &input, QVector<QgsPointXY> &output );
2468 operator QVariant()
const
2470 return QVariant::fromValue( *
this );
2478 mutable QString mLastError;
2490 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2496 QgsGeometry convertToPoint(
bool destMultipart )
const;
2498 QgsGeometry convertToLine(
bool destMultipart )
const;
2500 QgsGeometry convertToPolygon(
bool destMultipart )
const;
2513 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
unsigned int iterations = 1,
double offset = 0.25,
2514 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
2527 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
unsigned int iterations = 1,
double offset = 0.25,
2528 double minimumDistance = -1,
double maxAngle = 180.0 )
const;