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;
649 double distanceToVertex(
int vertex )
const;
658 double angleAtVertex(
int vertex )
const;
672 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex
SIP_OUT )
const;
686 bool insertVertex(
double x,
double y,
int beforeVertex );
700 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
709 bool moveVertex(
double x,
double y,
int atVertex );
718 bool moveVertex(
const QgsPoint &p,
int atVertex );
731 bool deleteVertex(
int atVertex );
738 QgsPoint vertexAt(
int atVertex )
const;
772 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
792 OperationResult addRing(
const QVector<QgsPointXY> &ring );
838 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
844 OperationResult translate(
double dx,
double dy,
double dz = 0.0,
double dm = 0.0 );
870 OperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
878 OperationResult rotate(
double rotation, const
QgsPointXY ¢er );
933 OperationResult reshapeGeometry( const
QgsLineString &reshapeLineString );
1006 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
1020 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
1042 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
1053 bool intersects( const
QgsRectangle &rectangle ) const;
1064 bool intersects( const
QgsGeometry &geometry ) const;
1075 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
1086 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
1097 bool contains( const
QgsGeometry &geometry ) const;
1103 bool disjoint( const
QgsGeometry &geometry ) const;
1109 bool touches( const
QgsGeometry &geometry ) const;
1115 bool overlaps( const
QgsGeometry &geometry ) const;
1128 bool crosses( const
QgsGeometry &geometry ) const;
1136 Q_ENUM( BufferSide )
1145 Q_ENUM( EndCapStyle )
1163 QgsGeometry buffer(
double distance,
int segments )
const;
1177 QgsGeometry buffer(
double distance,
int segments, EndCapStyle endCapStyle, JoinStyle joinStyle,
double miterLimit )
const;
1187 QgsGeometry offsetCurve(
double distance,
int segments, JoinStyle joinStyle,
double miterLimit )
const;
1204 QgsGeometry singleSidedBuffer(
double distance,
int segments, BufferSide side,
1205 JoinStyle joinStyle = JoinStyleRound,
1206 double miterLimit = 2.0 )
const;
1225 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments )
const;
1241 QgsGeometry variableWidthBufferByM(
int segments )
const;
1249 QgsGeometry extendLine(
double startDistance,
double endDistance )
const;
1263 QgsGeometry densifyByCount(
int extraNodesPerSegment )
const;
1279 QgsGeometry densifyByDistance(
double distance )
const;
1296 QgsGeometry convertToCurves(
double distanceTolerance = 1e-8,
double angleTolerance = 1e-8 )
const;
1378 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly =
false )
const;
1399 QgsGeometry subdivide(
int maxNodes = 256 )
const;
1429 double lineLocatePoint(
const QgsGeometry &point )
const;
1440 double interpolateAngle(
double distance )
const;
1563 const
QgsWkbTypes::GeometryType type = sipCpp->type();
1564 if ( sipCpp->isNull() )
1566 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Cannot generate points inside a null geometry." ).toUtf8().constData() );
1571 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"Cannot generate points inside a %1 geometry. Only Polygon types are permitted." ).arg(
QgsWkbTypes::displayString( sipCpp->wkbType() ) ).toUtf8().constData() );
1576 const sipTypeDef *qvector_type = sipFindType(
"QVector<QgsPointXY>" );
1577 sipRes = sipConvertFromNewType(
new QVector< QgsPointXY >( sipCpp->randomPointsInPolygon( a0, a1 ) ), qvector_type, Py_None );
1592 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() )
const;
1601 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() )
const;
1608 QString asWkt(
int precision = 17 )
const;
1611 SIP_PYOBJECT __repr__();
1614 if ( sipCpp->isNull() )
1615 str = QStringLiteral(
"<QgsGeometry: null>" );
1618 QString wkt = sipCpp->asWkt();
1619 if ( wkt.length() > 1000 )
1620 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
1621 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
1623 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1630 QString asJson(
int precision = 17 )
const;
1703 if ( sipCpp->isNull() )
1705 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
1710 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1715 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1746 if ( sipCpp->isNull() )
1748 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1753 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() );
1758 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
1759 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1790 if ( sipCpp->isNull() )
1792 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1797 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() );
1802 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
1803 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1832 if ( sipCpp->isNull() )
1834 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
1839 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1844 const sipTypeDef *qvector_type = sipFindType(
"QVector< QgsPointXY >" );
1845 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
1876 if ( sipCpp->isNull() )
1878 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
1883 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() );
1888 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QgsPointXY>>" );
1889 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
1920 if ( sipCpp->isNull() )
1922 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
1927 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() );
1932 const sipTypeDef *qvector_type = sipFindType(
"QVector<QVector<QVector<QgsPointXY>>>" );
1933 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
1942 QVector<QgsGeometry> asGeometryCollection()
const;
1971 bool deleteRing(
int ringNum,
int partNum = 0 );
1978 bool deletePart(
int partNum );
1988 bool convertToMultiType();
1999 bool convertToSingleType();
2010 bool convertGeometryCollectionToSubclass(
QgsWkbTypes::GeometryType geomType );
2022 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;
The part_iterator class provides STL-style iterator for const references to geometry parts.
The part_iterator class provides STL-style iterator for geometry parts.
The vertex_iterator class provides STL-style iterator for vertices.
Abstract base class for all geometries.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Java-style iterator for const traversal of parts of a geometry.
Contains geometry relation and modification algorithms.
Java-style iterator for traversal of parts of a geometry.
Error(const QString &m, const QgsPointXY &p)
bool operator==(const QgsGeometry::Error &other) const
A geometry is the spatial representation of a feature.
QVector< QgsPointXY > randomPointsInPolygon(int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0) const
Returns a list of count random points generated inside a (multi)polygon geometry (if acceptPoint is s...
JoinStyle
Join styles for buffers.
@ JoinStyleMiter
Use mitered joins.
@ JoinStyleBevel
Use beveled joins.
QVector< QgsPointXY > randomPointsInPolygon(int count, unsigned long seed=0, QgsFeedback *feedback=nullptr) const
Returns a list of count random points generated inside a (multi)polygon geometry.
static bool compare(const QgsPolylineXY &p1, const QgsPolylineXY &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compares two polylines for equality within a specified tolerance.
BufferSide
Side of line to buffer.
@ SideRight
Buffer to right of line.
EndCapStyle
End cap styles for buffers.
@ CapSquare
Square cap (extends past start/end of line by buffer distance)
@ CapFlat
Flat cap (in line with start/end of line)
OperationResult
Success or failure of a geometry operation.
@ InvalidBaseGeometry
The base geometry on which the operation is done is invalid or empty.
@ SplitCannotSplitPoint
Cannot split points.
@ AddRingNotInExistingFeature
The input ring doesn't have any existing ring to fit into.
@ AddRingNotClosed
The input ring is not closed.
@ AddPartSelectedGeometryNotFound
The selected geometry cannot be found.
@ GeometryEngineError
Geometry engine misses a method implemented or an error occurred in the geometry engine.
@ AddPartNotMultiGeometry
The source geometry is not multi.
@ InvalidInputGeometryType
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
@ SelectionIsEmpty
No features were selected.
@ AddRingCrossesExistingRings
The input ring crosses existing rings (it is not disjoint)
@ SelectionIsGreaterThanOne
More than one features were selected.
@ LayerNotEditable
Cannot edit layer.
@ AddRingNotValid
The input ring is not valid.
ValidityFlag
Validity check flags.
ValidationMethod
Available methods for validating geometries.
@ ValidatorQgisInternal
Use internal QgsGeometryValidator method.
@ ValidatorGeos
Use GEOS validation methods.
This class offers geometry processing methods.
Line string geometry type, with support for z-dimension and m-values.
Perform transforms between map coordinates and device coordinates.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
Represents a vector layer which manages a vector based data sets.
Java-style iterator for traversal of vertices of a geometry.
Handles storage of information regarding WKB types and their properties.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static QString displayString(Type type) SIP_HOLDGIL
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
#define SIP_TYPEHINT(type)
QVector< QgsPoint > QgsPointSequence
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsPointSequence QgsPolyline
Polyline as represented as a vector of points.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
Utility class for identifying a unique vertex within a geometry.