19 #include <QDomDocument> 29 #include "qgis_core.h" 33 #if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3) 34 #define GEOSGeometry struct GEOSGeom_t 35 #define GEOSCoordSequence struct GEOSCoordSeq_t 123 NothingHappened = 1000,
257 static QgsGeometry collectGeometry(
const QVector<QgsGeometry> &geometries );
271 void fromWkb(
unsigned char *wkb,
int length )
SIP_SKIP;
277 void fromWkb(
const QByteArray &wkb );
285 GEOSGeometry *exportToGeos(
double precision = 0 ) const SIP_SKIP;
305 bool isEmpty() const;
308 bool isMultipart() const;
348 bool isGeosValid() const;
358 bool isSimple() const;
370 double length() const;
418 double hausdorffDistance(
const QgsGeometry &geom )
const;
438 double hausdorffDistanceDensify(
const QgsGeometry &geom,
double densifyFraction )
const;
453 QgsPointXY closestVertex(
const QgsPointXY &point,
int &atVertex
SIP_OUT,
int &beforeVertex SIP_OUT,
int &afterVertex SIP_OUT,
double &sqrDist SIP_OUT )
const;
461 double distanceToVertex(
int vertex )
const;
470 double angleAtVertex(
int vertex )
const;
484 void adjacentVertices(
int atVertex,
int &beforeVertex
SIP_OUT,
int &afterVertex SIP_OUT )
const;
498 bool insertVertex(
double x,
double y,
int beforeVertex );
512 bool insertVertex(
const QgsPoint &point,
int beforeVertex );
521 bool moveVertex(
double x,
double y,
int atVertex );
530 bool moveVertex(
const QgsPoint &p,
int atVertex );
543 bool deleteVertex(
int atVertex );
550 QgsPoint vertexAt(
int atVertex )
const;
579 double closestVertexWithContext(
const QgsPointXY &point,
int &atVertex
SIP_OUT )
const;
653 QgsGeometry removeInteriorRings(
double minimumAllowedArea = -1 )
const;
659 OperationResult translate(
double dx,
double dy,
double dz = 0.0,
double dm = 0.0 );
677 bool transformZ =
false );
687 OperationResult transform(
const QTransform &t,
double zTranslate = 0.0,
double zScale = 1.0,
double mTranslate = 0.0,
double mScale = 1.0 );
705 OperationResult splitGeometry(
const QVector<QgsPointXY> &splitLine, QVector<QgsGeometry> &newGeometries
SIP_OUT,
bool topological, QVector<QgsPointXY> &topologyTestPoints SIP_OUT );
742 QgsGeometry orientedMinimumBoundingBox(
double &area
SIP_OUT,
double &
angle SIP_OUT,
double &width SIP_OUT,
double &height SIP_OUT )
const;
749 QgsGeometry orientedMinimumBoundingBox() const SIP_SKIP;
765 QgsGeometry minimalEnclosingCircle(
unsigned int segments = 36 ) const SIP_SKIP;
775 QgsGeometry orthogonalize(
double tolerance = 1.0E-8,
int maxIterations = 1000,
double angleThreshold = 15.0 ) const;
789 QgsGeometry snappedToGrid(
double hSpacing,
double vSpacing,
double dSpacing = 0,
double mSpacing = 0 ) const;
811 bool removeDuplicateNodes(
double epsilon = 4 * DBL_EPSILON,
bool useZValues = false );
833 bool intersects( const
QgsGeometry &geometry ) const;
844 bool boundingBoxIntersects( const
QgsRectangle &rectangle ) const;
855 bool boundingBoxIntersects( const
QgsGeometry &geometry ) const;
864 bool contains( const
QgsGeometry &geometry ) const;
870 bool disjoint( const
QgsGeometry &geometry ) const;
882 bool overlaps( const
QgsGeometry &geometry ) const;
926 QgsGeometry buffer(
double distance,
int segments )
const;
947 QgsGeometry offsetCurve(
double distance,
int segments,
JoinStyle joinStyle,
double miterLimit )
const;
963 double miterLimit = 2.0 )
const;
971 QgsGeometry extendLine(
double startDistance,
double endDistance )
const;
985 QgsGeometry densifyByCount(
int extraNodesPerSegment )
const;
1001 QgsGeometry densifyByDistance(
double distance )
const;
1045 QgsGeometry poleOfInaccessibility(
double precision,
double *distanceToBoundary
SIP_OUT =
nullptr )
const;
1083 QgsGeometry delaunayTriangulation(
double tolerance = 0.0,
bool edgesOnly =
false )
const;
1104 QgsGeometry subdivide(
int maxNodes = 256 )
const;
1130 double lineLocatePoint(
const QgsGeometry &point )
const;
1141 double interpolateAngle(
double distance )
const;
1212 QByteArray asWkb()
const;
1219 QString asWkt(
int precision = 17 )
const;
1224 QString asJson(
int precision = 17 )
const;
1277 QVector<
QgsGeometry> asGeometryCollection() const;
1284 QPointF asQPointF() const;
1292 QPolygonF asQPolygonF() const;
1300 bool deleteRing(
int ringNum,
int partNum = 0 );
1307 bool deletePart(
int partNum );
1317 bool convertToMultiType();
1328 bool convertToSingleType();
1340 int avoidIntersections( const QList<
QgsVectorLayer *> &avoidIntersectionsLayers,
1370 bool hasLocation =
false;
1374 : message( QStringLiteral(
"none" ) )
1384 , hasLocation( true ) {}
1407 void validateGeometry( QVector<QgsGeometry::Error> &errors
SIP_OUT,
ValidationMethod method = ValidatorQgisInternal )
const;
1414 static QgsGeometry unaryUnion(
const QVector<QgsGeometry> &geometries );
1424 static QgsGeometry polygonize(
const QVector<QgsGeometry> &geometries );
1431 void convertToStraightSegment();
1439 bool requiresConversionToStraightSegments()
const;
1453 void draw( QPainter &p )
const;
1487 QString lastError()
const;
1494 static GEOSContextHandle_t getGEOSHandler() SIP_SKIP;
1510 static
QgsGeometry fromQPolygonF( const QPolygonF &polygon );
1526 static
QgsPolygonXY createPolygonFromQPolygonF( const QPolygonF &polygon ) SIP_FACTORY;
1540 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1552 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1565 double epsilon = 4 * std::numeric_limits<double>::epsilon() );
1586 static bool compare( PyObject *obj1, PyObject *obj2,
double epsilon = 4 * DBL_EPSILON );
1594 if ( PyList_Check( a0 ) && PyList_Check( a1 ) &&
1595 PyList_GET_SIZE( a0 ) && PyList_GET_SIZE( a1 ) )
1597 PyObject *o0 = PyList_GetItem( a0, 0 );
1598 PyObject *o1 = PyList_GetItem( a1, 0 );
1602 if ( sipCanConvertToType( o0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1603 sipCanConvertToType( o1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1604 sipCanConvertToType( a0, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1605 sipCanConvertToType( a1, sipType_QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1609 p0 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a0, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1610 p1 =
reinterpret_cast<QgsPolylineXY *
>( sipConvertToType( a1, sipType_QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1613 sipReleaseType( p0, sipType_QVector_0100QgsPointXY, state0 );
1614 sipReleaseType( p1, sipType_QVector_0100QgsPointXY, state1 );
1621 else if ( PyList_Check( o0 ) && PyList_Check( o1 ) &&
1622 PyList_GET_SIZE( o0 ) && PyList_GET_SIZE( o1 ) )
1624 PyObject *oo0 = PyList_GetItem( o0, 0 );
1625 PyObject *oo1 = PyList_GetItem( o1, 0 );
1629 if ( sipCanConvertToType( oo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1630 sipCanConvertToType( oo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1631 sipCanConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1632 sipCanConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1636 p0 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1637 p1 =
reinterpret_cast<QgsPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1640 sipReleaseType( p0, sipType_QVector_0600QVector_0100QgsPointXY, state0 );
1641 sipReleaseType( p1, sipType_QVector_0600QVector_0100QgsPointXY, state1 );
1648 else if ( PyList_Check( oo0 ) && PyList_Check( oo1 ) &&
1649 PyList_GET_SIZE( oo0 ) && PyList_GET_SIZE( oo1 ) )
1651 PyObject *ooo0 = PyList_GetItem( oo0, 0 );
1652 PyObject *ooo1 = PyList_GetItem( oo1, 0 );
1656 if ( sipCanConvertToType( ooo0, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1657 sipCanConvertToType( ooo1, sipType_QgsPointXY, SIP_NOT_NONE ) &&
1658 sipCanConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) &&
1659 sipCanConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, SIP_NOT_NONE ) )
1663 p0 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state0, &sipIsErr ) );
1664 p1 =
reinterpret_cast<QgsMultiPolygonXY *
>( sipConvertToType( a1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, 0, SIP_NOT_NONE, &state1, &sipIsErr ) );
1667 sipReleaseType( p0, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state0 );
1668 sipReleaseType( p1, sipType_QVector_0600QVector_0600QVector_0100QgsPointXY, state1 );
1697 QgsGeometry smooth(
const unsigned int iterations = 1,
const double offset = 0.25,
1698 double minimumDistance = -1.0,
double maxAngle = 180.0 )
const;
1710 static void convertPointList(
const QVector<QgsPointXY> &input,
QgsPointSequence &output );
1717 static void convertPointList(
const QgsPointSequence &input, QVector<QgsPointXY> &output );
1720 operator QVariant()
const 1722 return QVariant::fromValue( *
this );
1730 operator bool()
const;
1737 mutable QString mLastError;
1749 void reset( std::unique_ptr< QgsAbstractGeometry > newGeometry );
1755 QgsGeometry convertToPoint(
bool destMultipart )
const;
1757 QgsGeometry convertToLine(
bool destMultipart )
const;
1759 QgsGeometry convertToPolygon(
bool destMultipart )
const;
1772 std::unique_ptr< QgsLineString > smoothLine(
const QgsLineString &line,
const unsigned int iterations = 1,
const double offset = 0.25,
1773 double minimumDistance = -1,
double maxAngle = 180.0 )
const;
1786 std::unique_ptr< QgsPolygon > smoothPolygon(
const QgsPolygon &polygon,
const unsigned int iterations = 1,
const double offset = 0.25,
1787 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.
The input ring doesn't have any existing ring to fit into.
Java-style iterator for traversal of vertices of a geometry.
The source geometry is not multi.
Use GEOS validation methods.
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.
EndCapStyle
End cap styles for buffers.
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.
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)
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.
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsGeometry &geometry)
Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed.
Contains geos related utilities and functions.
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.
The input ring is not valid.
Contains geometry relation and modification algorithms.
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.
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.