21 #include <QDomDocument> 22 #include <QJsonObject> 31 #include "qgis_core.h" 40 #include <nlohmann/json_fwd.hpp> 114 Q_PROPERTY(
bool isNull READ isNull )
126 NothingHappened = 1000,
263 static QgsGeometry collectGeometry(
const QVector<QgsGeometry> &geometries );
280 static QgsGeometry createWedgeBuffer(
const QgsPoint ¢er,
double azimuth,
double angularWidth,
281 double outerRadius,
double innerRadius = 0 );
288 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
294 void fromWkb(
const QByteArray &wkb );
314 bool isEmpty()
const;
317 bool isMultipart()
const;
356 FlagAllowSelfTouchingHoles = 1 << 0,
367 bool isGeosValid( QgsGeometry::ValidityFlags flags =
nullptr )
const;
377 bool isSimple()
const;
389 double length()
const;
572 double hausdorffDistance(
const QgsGeometry &geom )
const;
592 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
608 QgsPointXY closestVertex(
const QgsPointXY &point,
int &atVertex
SIP_OUT,
int &beforeVertex SIP_OUT,
int &afterVertex SIP_OUT,
double &sqrDist SIP_OUT )
const;
616 double distanceToVertex(
int vertex )
const;
625 double angleAtVertex(
int vertex )
const;
639 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex SIP_OUT )
const;
653 bool insertVertex(
double x,
double y,
int beforeVertex );
667 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
676 bool moveVertex(
double x,
double y,
int atVertex );
685 bool moveVertex(
const QgsPoint &p,
int atVertex );
698 bool deleteVertex(
int atVertex );
705 QgsPoint vertexAt(
int atVertex )
const;
734 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
800 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
806 OperationResult translate(
double dx,
double dy,
double dz = 0.0,
double dm = 0.0 );
832 OperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
863 int makeDifferenceInPlace( const
QgsGeometry &other ) SIP_SKIP;
887 QgsGeometry orientedMinimumBoundingBox(
double &area SIP_OUT,
double &
angle SIP_OUT,
double &width SIP_OUT,
double &height SIP_OUT ) const;
894 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
904 QgsGeometry minimalEnclosingCircle(
QgsPointXY ¢er SIP_OUT,
double &radius SIP_OUT,
unsigned int segments = 36 ) const;
911 QgsGeometry minimalEnclosingCircle(
unsigned int segments = 36 ) const SIP_SKIP;
921 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
935 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
957 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
979 bool intersects( const
QgsGeometry &geometry ) const;
990 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
1001 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
1010 bool contains( const
QgsGeometry &geometry ) const;
1016 bool disjoint( const
QgsGeometry &geometry ) const;
1022 bool touches( const
QgsGeometry &geometry ) const;
1028 bool overlaps( const
QgsGeometry &geometry ) const;
1040 bool crosses( const
QgsGeometry &geometry ) const;
1075 QgsGeometry buffer(
double distance,
int segments )
const;
1099 QgsGeometry offsetCurve(
double distance,
int segments,
JoinStyle joinStyle,
double miterLimit )
const;
1118 double miterLimit = 2.0 )
const;
1137 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments )
const;
1153 QgsGeometry variableWidthBufferByM(
int segments )
const;
1161 QgsGeometry extendLine(
double startDistance,
double endDistance )
const;
1175 QgsGeometry densifyByCount(
int extraNodesPerSegment )
const;
1191 QgsGeometry densifyByDistance(
double distance )
const;
1273 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly =
false )
const;
1294 QgsGeometry subdivide(
int maxNodes = 256 )
const;
1324 double lineLocatePoint(
const QgsGeometry &point )
const;
1335 double interpolateAngle(
double distance )
const;
1406 QByteArray asWkb()
const;
1413 QString asWkt(
int precision = 17 )
const;
1416 SIP_PYOBJECT __repr__();
1419 if ( sipCpp->isNull() )
1420 str = QStringLiteral(
"<QgsGeometry: null>" );
1423 QString wkt = sipCpp->asWkt();
1424 if ( wkt.length() > 1000 )
1425 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
1426 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
1428 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1435 QString asJson(
int precision = 17 )
const;
1442 virtual json asJsonObject(
int precision = 17 ) const SIP_SKIP;
1479 if ( sipCpp->isNull() )
1481 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
1486 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1491 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1522 if ( sipCpp->isNull() )
1524 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1529 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() );
1534 const sipMappedType *qvector_type = sipFindMappedType(
"QVector< QgsPointXY >" );
1535 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1566 if ( sipCpp->isNull() )
1568 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1573 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() );
1578 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QgsPointXY>>" );
1579 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1608 if ( sipCpp->isNull() )
1610 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
1615 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1620 const sipMappedType *qvector_type = sipFindMappedType(
"QVector< QgsPointXY >" );
1621 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
1652 if ( sipCpp->isNull() )
1654 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
1659 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() );
1664 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QgsPointXY>>" );
1665 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
1696 if ( sipCpp->isNull() )
1698 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
1703 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() );
1708 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QVector<QgsPointXY>>>" );
1709 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
1718 QVector<QgsGeometry> asGeometryCollection()
const;
1725 QPointF asQPointF()
const;
1733 QPolygonF asQPolygonF()
const;
1741 bool deleteRing(
int ringNum,
int partNum = 0 );
1748 bool deletePart(
int partNum );
1758 bool convertToMultiType();
1769 bool convertToSingleType();
1792 int avoidIntersections(
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
1831 : mMessage( QStringLiteral(
"none" ) )
1838 Error(
const QString &m,
const QgsPointXY &p )
1841 , mHasLocation( true ) {}
1846 QString what()
const;
1851 QgsPointXY where()
const;
1856 bool hasWhere()
const;
1859 SIP_PYOBJECT __repr__();
1861 QString str = QStringLiteral(
"<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
1862 sipRes = PyUnicode_FromString( str.toUtf8().data() );
1868 return other.mMessage == mMessage && other.mHasLocation == mHasLocation && other.mLocation == mLocation;
1873 QgsPointXY mLocation;
1874 bool mHasLocation =
false;
1895 void validateGeometry( QVector<QgsGeometry::Error> &errors
SIP_OUT,
ValidationMethod method = ValidatorQgisInternal, QgsGeometry::ValidityFlags flags =
nullptr )
const;
1902 static QgsGeometry unaryUnion(
const QVector<QgsGeometry> &geometries );
1912 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
1929 bool requiresConversionToStraightSegments()
const;
1943 void draw( QPainter &p )
const;
1977 QString lastError()
const;
1988 void filterVertices(
const std::function<
bool(
const QgsPoint & ) > &filter )
SIP_SKIP;
2020 static QgsGeometry fromQPolygonF(
const QPolygonF &polygon );
2028 static QgsPolylineXY createPolylineFromQPolygonF(
const QPolygonF &polygon )
SIP_FACTORY;
2036 static QgsPolygonXY createPolygonFromQPolygonF(
const QPolygonF &polygon )
SIP_FACTORY;
2049 static bool compare(
const QgsPolylineXY &p1,
const QgsPolylineXY &p2,
2050 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2061 static bool compare(
const QgsPolygonXY &p1,
const QgsPolygonXY &p2,
2062 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2074 static bool compare(
const QgsMultiPolygonXY &p1,
const QgsMultiPolygonXY &p2,
2075 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2096 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2104 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
2105 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
2107 PyObject *o0 = PyList_GetItem( a0, 0 );
2108 PyObject *o1 = PyList_GetItem( a1, 0 );
2112 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2113 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2114 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2115 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2119 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2120 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2123 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
2124 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
2131 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
2132 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
2134 PyObject *oo0 = PyList_GetItem( o0, 0 );
2135 PyObject *oo1 = PyList_GetItem( o1, 0 );
2139 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2140 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2141 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2142 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2146 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2147 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2150 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2151 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2158 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2159 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2161 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2162 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2166 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2167 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2168 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2169 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2171 QgsMultiPolygonXY *p0;
2172 QgsMultiPolygonXY *p1;
2173 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2174 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2177 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2178 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2211 QgsGeometry smooth(
unsigned int iterations = 1,
double offset = 0.25,
2212 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
2224 static void convertPointList(
const QVector<QgsPointXY> &input,
QgsPointSequence &output );
2231 static void convertPointList(
const QgsPointSequence &input, QVector<QgsPointXY> &output );
2234 operator QVariant()
const 2236 return QVariant::fromValue( *
this );
2244 mutable QString mLastError;
2256 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2258 static void convertToPolyline(
const QgsPointSequence &input, QgsPolylineXY &output );
2259 static void convertPolygon(
const QgsPolygon &input, QgsPolygonXY &output );
2262 QgsGeometry convertToPoint(
bool destMultipart )
const;
2264 QgsGeometry convertToLine(
bool destMultipart )
const;
2266 QgsGeometry convertToPolygon(
bool destMultipart )
const;
2279 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
unsigned int iterations = 1,
double offset = 0.25,
2280 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
2293 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
unsigned int iterations = 1,
double offset = 0.25,
2294 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
2302 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsGeometry::ValidityFlags )
Geometry engine misses a method implemented or an error occurred in the geometry engine.
A rectangle specified with double values.
Java-style iterator for traversal of parts of a geometry.
The input ring doesn't have any existing ring to fit into.
Java-style iterator for traversal of vertices of a geometry.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
The source geometry is not multi.
Maximum angle between generating radii (lines from arc center to output vertices) ...
Use GEOS validation methods.
bool operator==(const QgsGeometry::Error &other) const
Java-style iterator for const traversal of parts of a geometry.
Handles storage of information regarding WKB types and their properties.
A class to represent a 2D point.
QVector< QgsPoint > QgsPolyline
Polyline as represented as a vector of points.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
A geometry is the spatial representation of a feature.
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
The part_iterator class provides STL-style iterator for const references to geometry parts...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
EndCapStyle
End cap styles for buffers.
#define SIP_TYPEHINT(type)
OperationResult
Success or failure of a geometry operation.
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)
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
Error(const QString &m, const QgsPointXY &p)
QVector< QgsPolylineXY > QgsMultiPolylineXY
A collection of QgsPolylines that share a common collection of attributes.
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsGeometry &geometry)
Writes the geometry to stream out. QGIS version compatibility is not guaranteed.
Perform transforms between map coordinates and device coordinates.
The selected geometry cannot be found.
No features were selected.
More than one features were selected.
Type
The WKB type describes the number of dimensions a geometry has.
Utility class for identifying a unique vertex within a geometry.
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
The input ring crosses existing rings (it is not disjoint)
The part_iterator class provides STL-style iterator for geometry parts.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Use internal QgsGeometryValidator method.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
The input ring is not closed.
Square cap (extends past start/end of line by buffer distance)
Abstract base class for curved geometry type.
Abstract base class for all geometries.
The vertex_iterator class provides STL-style iterator for vertices.
Point geometry type, with support for z-dimension and m-values.
This class offers geometry processing methods.
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
BufferSide
Side of line to buffer.
QVector< QgsPoint > QgsPointSequence
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
The base geometry on which the operation is done is invalid or empty.
The input geometry (ring, part, split line, etc.) has not the correct geometry type.
Line string geometry type, with support for z-dimension and m-values.
ValidationMethod
Available methods for validating geometries.
ValidityFlag
Validity check flags.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
The input ring is not valid.
Contains geometry relation and modification algorithms.
Custom exception class for Coordinate Reference System related exceptions.
JoinStyle
Join styles for buffers.
Flat cap (in line with start/end of line)
Represents a vector layer which manages a vector based data sets.
static Type flatType(Type type)
Returns the flat type for a WKB type.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negativ values mean left a...
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.