21 #include <QDomDocument> 30 #include "qgis_core.h" 109 Q_PROPERTY(
bool isNull READ isNull )
121 NothingHappened = 1000,
258 static QgsGeometry collectGeometry(
const QVector<QgsGeometry> &geometries );
275 static QgsGeometry createWedgeBuffer(
const QgsPoint ¢er,
double azimuth,
double angularWidth,
276 double outerRadius,
double innerRadius = 0 );
283 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
289 void fromWkb(
const QByteArray &wkb );
309 bool isEmpty()
const;
312 bool isMultipart()
const;
352 bool isGeosValid()
const;
362 bool isSimple()
const;
374 double length()
const;
557 double hausdorffDistance(
const QgsGeometry &geom )
const;
577 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
593 QgsPointXY closestVertex(
const QgsPointXY &point,
int &atVertex
SIP_OUT,
int &beforeVertex SIP_OUT,
int &afterVertex SIP_OUT,
double &sqrDist SIP_OUT )
const;
601 double distanceToVertex(
int vertex )
const;
610 double angleAtVertex(
int vertex )
const;
624 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex SIP_OUT )
const;
638 bool insertVertex(
double x,
double y,
int beforeVertex );
652 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
661 bool moveVertex(
double x,
double y,
int atVertex );
670 bool moveVertex(
const QgsPoint &p,
int atVertex );
683 bool deleteVertex(
int atVertex );
690 QgsPoint vertexAt(
int atVertex )
const;
719 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
785 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
791 OperationResult translate(
double dx,
double dy,
double dz = 0.0,
double dm = 0.0 );
817 OperationResult transform( const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
848 int makeDifferenceInPlace( const
QgsGeometry &other ) SIP_SKIP;
872 QgsGeometry orientedMinimumBoundingBox(
double &area SIP_OUT,
double &
angle SIP_OUT,
double &width SIP_OUT,
double &height SIP_OUT ) const;
879 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
889 QgsGeometry minimalEnclosingCircle(
QgsPointXY ¢er SIP_OUT,
double &radius SIP_OUT,
unsigned int segments = 36 ) const;
896 QgsGeometry minimalEnclosingCircle(
unsigned int segments = 36 ) const SIP_SKIP;
906 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
920 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
942 bool removeDuplicateNodes(
double epsilon = 4 * std::numeric_limits<
double>::epsilon(),
bool useZValues = false );
964 bool intersects( const
QgsGeometry &geometry ) const;
975 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
986 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
995 bool contains( const
QgsGeometry &geometry ) const;
1001 bool disjoint( const
QgsGeometry &geometry ) const;
1007 bool touches( const
QgsGeometry &geometry ) const;
1013 bool overlaps( const
QgsGeometry &geometry ) const;
1025 bool crosses( const
QgsGeometry &geometry ) const;
1060 QgsGeometry buffer(
double distance,
int segments )
const;
1084 QgsGeometry offsetCurve(
double distance,
int segments,
JoinStyle joinStyle,
double miterLimit )
const;
1103 double miterLimit = 2.0 )
const;
1122 QgsGeometry taperedBuffer(
double startWidth,
double endWidth,
int segments )
const;
1138 QgsGeometry variableWidthBufferByM(
int segments )
const;
1146 QgsGeometry extendLine(
double startDistance,
double endDistance )
const;
1160 QgsGeometry densifyByCount(
int extraNodesPerSegment )
const;
1176 QgsGeometry densifyByDistance(
double distance )
const;
1258 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly =
false )
const;
1279 QgsGeometry subdivide(
int maxNodes = 256 )
const;
1309 double lineLocatePoint(
const QgsGeometry &point )
const;
1320 double interpolateAngle(
double distance )
const;
1391 QByteArray asWkb()
const;
1398 QString asWkt(
int precision = 17 )
const;
1401 SIP_PYOBJECT __repr__();
1404 if ( sipCpp->isNull() )
1405 str = QStringLiteral(
"<QgsGeometry: null>" );
1408 QString wkt = sipCpp->asWkt();
1409 if ( wkt.length() > 1000 )
1410 wkt = wkt.left( 1000 ) + QStringLiteral(
"..." );
1411 str = QStringLiteral(
"<QgsGeometry: %1>" ).arg( wkt );
1413 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1420 QString asJson(
int precision = 17 )
const;
1457 if ( sipCpp->isNull() )
1459 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a point." ).toUtf8().constData() );
1464 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a point. Only Point types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1469 sipRes = sipConvertFromNewType(
new QgsPointXY( sipCpp->asPoint() ), sipType_QgsPointXY, Py_None );
1500 if ( sipCpp->isNull() )
1502 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polyline." ).toUtf8().constData() );
1507 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() );
1512 const sipMappedType *qvector_type = sipFindMappedType(
"QVector< QgsPointXY >" );
1513 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asPolyline() ), qvector_type, Py_None );
1544 if ( sipCpp->isNull() )
1546 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a polygon." ).toUtf8().constData() );
1551 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() );
1556 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QgsPointXY>>" );
1557 sipRes = sipConvertFromNewType(
new QgsPolygonXY( sipCpp->asPolygon() ), qvector_type, Py_None );
1586 if ( sipCpp->isNull() )
1588 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipoint." ).toUtf8().constData() );
1593 PyErr_SetString( PyExc_TypeError, QStringLiteral(
"%1 geometry cannot be converted to a multipoint. Only multipoint types are permitted." ).arg(
QgsWkbTypes::displayString( type ) ).toUtf8().constData() );
1598 const sipMappedType *qvector_type = sipFindMappedType(
"QVector< QgsPointXY >" );
1599 sipRes = sipConvertFromNewType(
new QgsPolylineXY( sipCpp->asMultiPoint() ), qvector_type, Py_None );
1630 if ( sipCpp->isNull() )
1632 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multilinestring." ).toUtf8().constData() );
1637 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() );
1642 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QgsPointXY>>" );
1643 sipRes = sipConvertFromNewType(
new QgsMultiPolylineXY( sipCpp->asMultiPolyline() ), qvector_type, Py_None );
1674 if ( sipCpp->isNull() )
1676 PyErr_SetString( PyExc_ValueError, QStringLiteral(
"Null geometry cannot be converted to a multipolygon." ).toUtf8().constData() );
1681 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() );
1686 const sipMappedType *qvector_type = sipFindMappedType(
"QVector<QVector<QVector<QgsPointXY>>>" );
1687 sipRes = sipConvertFromNewType(
new QgsMultiPolygonXY( sipCpp->asMultiPolygon() ), qvector_type, Py_None );
1696 QVector<QgsGeometry> asGeometryCollection()
const;
1703 QPointF asQPointF()
const;
1711 QPolygonF asQPolygonF()
const;
1719 bool deleteRing(
int ringNum,
int partNum = 0 );
1726 bool deletePart(
int partNum );
1736 bool convertToMultiType();
1747 bool convertToSingleType();
1770 int avoidIntersections(
const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
1809 : mMessage( QStringLiteral(
"none" ) )
1816 Error(
const QString &m,
const QgsPointXY &p )
1819 , mHasLocation( true ) {}
1824 QString what()
const;
1829 QgsPointXY where()
const;
1834 bool hasWhere()
const;
1837 SIP_PYOBJECT __repr__();
1839 QString str = QStringLiteral(
"<QgsGeometry.Error: %1>" ).arg( sipCpp->what() );
1840 sipRes = PyUnicode_FromString( str.toUtf8().data() );
1846 QgsPointXY mLocation;
1847 bool mHasLocation =
false;
1866 void validateGeometry( QVector<QgsGeometry::Error> &errors
SIP_OUT,
ValidationMethod method = ValidatorQgisInternal )
const;
1873 static QgsGeometry unaryUnion(
const QVector<QgsGeometry> &geometries );
1883 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
1900 bool requiresConversionToStraightSegments()
const;
1914 void draw( QPainter &p )
const;
1948 QString lastError()
const;
1959 void filterVertices(
const std::function<
bool(
const QgsPoint & ) > &filter )
SIP_SKIP;
1991 static QgsGeometry fromQPolygonF(
const QPolygonF &polygon );
1999 static QgsPolylineXY createPolylineFromQPolygonF(
const QPolygonF &polygon )
SIP_FACTORY;
2007 static QgsPolygonXY createPolygonFromQPolygonF(
const QPolygonF &polygon )
SIP_FACTORY;
2020 static bool compare(
const QgsPolylineXY &p1,
const QgsPolylineXY &p2,
2021 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2032 static bool compare(
const QgsPolygonXY &p1,
const QgsPolygonXY &p2,
2033 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2045 static bool compare(
const QgsMultiPolygonXY &p1,
const QgsMultiPolygonXY &p2,
2046 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2067 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * std::numeric_limits<double>::epsilon() );
2075 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
2076 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
2078 PyObject *o0 = PyList_GetItem( a0, 0 );
2079 PyObject *o1 = PyList_GetItem( a1, 0 );
2083 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2084 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2085 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2086 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2090 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2091 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2094 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
2095 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
2102 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
2103 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
2105 PyObject *oo0 = PyList_GetItem( o0, 0 );
2106 PyObject *oo1 = PyList_GetItem( o1, 0 );
2110 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2111 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2112 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2113 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2117 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2118 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2121 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
2122 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
2129 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
2130 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
2132 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
2133 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
2137 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2138 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
2139 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
2140 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
2142 QgsMultiPolygonXY *p0;
2143 QgsMultiPolygonXY *p1;
2144 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
2145 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
2148 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
2149 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
2182 QgsGeometry smooth(
unsigned int iterations = 1,
double offset = 0.25,
2183 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
2195 static void convertPointList(
const QVector<QgsPointXY> &input,
QgsPointSequence &output );
2202 static void convertPointList(
const QgsPointSequence &input, QVector<QgsPointXY> &output );
2205 operator QVariant()
const 2207 return QVariant::fromValue( *
this );
2215 mutable QString mLastError;
2227 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
2229 static void convertToPolyline(
const QgsPointSequence &input, QgsPolylineXY &output );
2230 static void convertPolygon(
const QgsPolygon &input, QgsPolygonXY &output );
2233 QgsGeometry convertToPoint(
bool destMultipart )
const;
2235 QgsGeometry convertToLine(
bool destMultipart )
const;
2237 QgsGeometry convertToPolygon(
bool destMultipart )
const;
2250 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
unsigned int iterations = 1,
double offset = 0.25,
2251 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
2264 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
unsigned int iterations = 1,
double offset = 0.25,
2265 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
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.
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)
Q_DECLARE_METATYPE(QModelIndex)
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.
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.
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.