QGIS API Documentation  2.99.0-Master (e077efd)
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsGeometry Class Reference

A geometry is the spatial representation of a feature. More...

#include <qgsgeometry.h>

Classes

class  Error
 

Public Types

enum  BufferSide { SideLeft = 0, SideRight }
 Side of line to buffer. More...
 
enum  EndCapStyle { CapRound = 1, CapFlat, CapSquare }
 End cap styles for buffers. More...
 
enum  JoinStyle { JoinStyleRound = 1, JoinStyleMitre, JoinStyleBevel }
 Join styles for buffers. More...
 

Public Member Functions

 QgsGeometry ()
 Constructor. More...
 
 QgsGeometry (const QgsGeometry &)
 Copy constructor will prompt a deep copy of the object. More...
 
 QgsGeometry (QgsAbstractGeometry *geom)
 Creates a geometry from an abstract geometry object. More...
 
 ~QgsGeometry ()
 Destructor. More...
 
int addPart (const QList< QgsPoint > &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
 Adds a new part to a the geometry. More...
 
int addPart (const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
 Adds a new part to a the geometry. More...
 
int addPart (QgsAbstractGeometry *part, QgsWkbTypes::GeometryType geomType=QgsWkbTypes::UnknownGeometry)
 Adds a new part to this geometry. More...
 
int addPart (GEOSGeometry *newPart)
 Adds a new island polygon to a multipolygon feature. More...
 
int addPart (const QgsGeometry &newPart)
 Adds a new island polygon to a multipolygon feature. More...
 
int addRing (const QList< QgsPoint > &ring)
 Adds a new ring to this geometry. More...
 
int addRing (QgsCurve *ring)
 Adds a new ring to this geometry. More...
 
void adjacentVertices (int atVertex, int &beforeVertex, int &afterVertex) const
 Returns the indexes of the vertices before and after the given vertex index. More...
 
double angleAtVertex (int vertex) const
 Returns the bisector angle for this geometry at the specified vertex. More...
 
double area () const
 Returns the area of the geometry using GEOS. More...
 
QList< QgsGeometryasGeometryCollection () const
 Return contents of the geometry as a list of geometries. More...
 
QgsMultiPoint asMultiPoint () const
 Return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list. More...
 
QgsMultiPolygon asMultiPolygon () const
 Return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list. More...
 
QgsMultiPolyline asMultiPolyline () const
 Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list. More...
 
QgsPoint asPoint () const
 Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0,0]. More...
 
QgsPolygon asPolygon () const
 Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list. More...
 
QgsPolyline asPolyline () const
 Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list. More...
 
QPointF asQPointF () const
 Return contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPointF. More...
 
QPolygonF asQPolygonF () const
 Return contents of the geometry as a QPolygonF. More...
 
int avoidIntersections (const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QHash< QgsVectorLayer *, QSet< QgsFeatureId > >()))
 Modifies geometry to avoid intersections with the layers specified in project properties. More...
 
QgsRectangle boundingBox () const
 Returns the bounding box of the geometry. More...
 
QgsGeometry buffer (double distance, int segments) const
 Returns a buffer region around this geometry having the given width and with a specified number of segments used to approximate curves. More...
 
QgsGeometry buffer (double distance, int segments, EndCapStyle endCapStyle, JoinStyle joinStyle, double mitreLimit) const
 Returns a buffer region around the geometry, with additional style options. More...
 
QgsGeometry centroid () const
 Returns the center of mass of a geometry. More...
 
double closestSegmentWithContext (const QgsPoint &point, QgsPoint &minDistPoint, int &afterVertex, double *leftOf=nullptr, double epsilon=DEFAULT_SEGMENT_EPSILON) const
 Searches for the closest segment of geometry to the given point. More...
 
QgsPoint closestVertex (const QgsPoint &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist) const
 Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap point / target point and the indices of the vertices before and after the closest vertex. More...
 
double closestVertexWithContext (const QgsPoint &point, int &atVertex) const
 Searches for the closest vertex in this geometry to the given point. More...
 
QgsGeometry combine (const QgsGeometry &geometry) const
 Returns a geometry representing all the points in this geometry and other (a union geometry operation). More...
 
bool contains (const QgsPoint *p) const
 Test for containment of a point (uses GEOS) More...
 
bool contains (const QgsGeometry &geometry) const
 Test for if geometry is contained in another (uses GEOS) More...
 
bool convertToMultiType ()
 Converts single type geometry into multitype geometry e.g. More...
 
bool convertToSingleType ()
 Converts multi type geometry into single type geometry e.g. More...
 
void convertToStraightSegment ()
 Converts the geometry to straight line segments, if it is a curved geometry type. More...
 
QgsGeometry convertToType (QgsWkbTypes::GeometryType destType, bool destMultipart=false) const
 Try to convert the geometry to the requested type. More...
 
QgsGeometry convexHull () const
 Returns the smallest convex polygon that contains all the points in the geometry. More...
 
bool crosses (const QgsGeometry &geometry) const
 Test for if geometry crosses another (uses GEOS) More...
 
bool deletePart (int partNum)
 Delete part identified by the part number. More...
 
bool deleteRing (int ringNum, int partNum=0)
 Delete a ring in polygon or multipolygon. More...
 
bool deleteVertex (int atVertex)
 Deletes the vertex at the given position number and item (first number is index 0) Returns false if atVertex does not correspond to a valid vertex on this geometry (including if this geometry is a Point), or if the number of remaining verticies in the linestring would be less than two. More...
 
QgsGeometry difference (const QgsGeometry &geometry) const
 Returns a geometry representing the points making up this geometry that do not make up other. More...
 
bool disjoint (const QgsGeometry &geometry) const
 Test for if geometry is disjoint of another (uses GEOS) More...
 
double distance (const QgsGeometry &geom) const
 Returns the minimum distance between this geometry and another geometry, using GEOS. More...
 
double distanceToVertex (int vertex) const
 Returns the distance along this geometry from its first vertex to the specified vertex. More...
 
void draw (QPainter &p) const
 Draws the geometry onto a QPainter. More...
 
bool equals (const QgsGeometry &geometry) const
 Test for if geometry equals another (uses GEOS) More...
 
QString exportToGeoJSON (int precision=17) const
 Exports the geometry to GeoJSON. More...
 
GEOSGeometry * exportToGeos (double precision=0) const
 Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r) More...
 
QByteArray exportToWkb () const
 Export the geometry to WKB. More...
 
QString exportToWkt (int precision=17) const
 Exports the geometry to WKT. More...
 
QgsGeometry extendLine (double startDistance, double endDistance) const
 Extends a (multi)line geometry by extrapolating out the start or end of the line by a specified distance. More...
 
QgsGeometry extrude (double x, double y)
 Returns an extruded version of this geometry. More...
 
void fromGeos (GEOSGeometry *geos)
 Set the geometry, feeding in a geometry in GEOS format. More...
 
void fromWkb (unsigned char *wkb, int length)
 Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length. More...
 
void fromWkb (const QByteArray &wkb)
 Set the geometry, feeding in the buffer containing OGC Well-Known Binary. More...
 
QgsAbstractGeometrygeometry () const
 Returns the underlying geometry store. More...
 
bool insertVertex (double x, double y, int beforeVertex)
 Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the requested vertex number (beforeVertex.back()) is greater than the last actual vertex on the requested ring and item, it is assumed that the vertex is to be appended instead of inserted. More...
 
QgsGeometry interpolate (double distance) const
 Return interpolated point on line at distance. More...
 
double interpolateAngle (double distance) const
 Returns the angle parallel to the linestring or polygon boundary at the specified distance along the geometry. More...
 
QgsGeometry intersection (const QgsGeometry &geometry) const
 Returns a geometry representing the points shared by this geometry and other. More...
 
bool intersects (const QgsRectangle &r) const
 Test for intersection with a rectangle (uses GEOS) More...
 
bool intersects (const QgsGeometry &geometry) const
 Test for intersection with a geometry (uses GEOS) More...
 
bool isEmpty () const
 Returns true if the geometry is empty (ie, contains no underlying geometry accessible via geometry). More...
 
bool isGeosEmpty () const
 Check if the geometry is empty using GEOS. More...
 
bool isGeosEqual (const QgsGeometry &) const
 Compares the geometry with another geometry using GEOS. More...
 
bool isGeosValid () const
 Checks validity of the geometry using GEOS. More...
 
bool isMultipart () const
 Returns true if WKB of the geometry is of WKBMulti* type. More...
 
double length () const
 Returns the length of geometry using GEOS. More...
 
double lineLocatePoint (const QgsGeometry &point) const
 Returns a distance representing the location along this linestring of the closest point on this linestring geometry to the specified point. More...
 
int makeDifference (const QgsGeometry *other)
 Changes this geometry such that it does not intersect the other geometry. More...
 
QgsGeometry makeDifference (const QgsGeometry &other) const
 Returns the geometry formed by modifying this geometry such that it does not intersect the other geometry. More...
 
void mapToPixel (const QgsMapToPixel &mtp)
 Transforms the geometry from map units to pixels in place. More...
 
QgsGeometry mergeLines () const
 Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line strings. More...
 
bool moveVertex (double x, double y, int atVertex)
 Moves the vertex at the given position number and item (first number is index 0) to the given coordinates. More...
 
bool moveVertex (const QgsPointV2 &p, int atVertex)
 Moves the vertex at the given position number and item (first number is index 0) to the given coordinates. More...
 
QgsGeometry nearestPoint (const QgsGeometry &other) const
 Returns the nearest point on this geometry to another geometry. More...
 
QgsGeometry offsetCurve (double distance, int segments, JoinStyle joinStyle, double mitreLimit) const
 Returns an offset line at a given distance and side from an input line. More...
 
 operator bool () const
 Returns true if the geometry is non empty (ie, isEmpty() returns false), or false if it is an empty, uninitialised geometry (ie, ieEmpty() returns true). More...
 
 operator QVariant () const
 Allows direct construction of QVariants from geometry. More...
 
QgsGeometryoperator= (QgsGeometry const &rhs)
 Assignments will prompt a deep copy of the object. More...
 
QgsGeometry orientedMinimumBoundingBox (double &area, double &angle, double &width, double &height) const
 Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated rectangle which fully encompasses the geometry. More...
 
bool overlaps (const QgsGeometry &geometry) const
 Test for if geometry overlaps another (uses GEOS) More...
 
QgsGeometry pointOnSurface () const
 Returns a point guaranteed to lie on the surface of a geometry. More...
 
QgsGeometry poleOfInaccessibility (double precision, double *distanceToBoundary=nullptr) const
 Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary of the surface. More...
 
QgsGeometry removeInteriorRings (double minimumAllowedArea=-1) const
 Removes the interior rings from a (multi)polygon geometry. More...
 
bool requiresConversionToStraightSegments () const
 Returns true if the geometry is a curved geometry type which requires conversion to display as straight line segments. More...
 
int reshapeGeometry (const QList< QgsPoint > &reshapeWithLine)
 Replaces a part of this geometry with another line. More...
 
int rotate (double rotation, const QgsPoint &center)
 Rotate this geometry around the Z axis. More...
 
void setGeometry (QgsAbstractGeometry *geometry)
 Sets the underlying geometry store. More...
 
QgsGeometry shortestLine (const QgsGeometry &other) const
 Returns the shortest line joining this geometry to another geometry. More...
 
QgsGeometry simplify (double tolerance) const
 Returns a simplified version of this geometry using a specified tolerance value. More...
 
QgsGeometry singleSidedBuffer (double distance, int segments, BufferSide side, JoinStyle joinStyle=JoinStyleRound, double mitreLimit=2.0) const
 Returns a single sided buffer for a (multi)line geometry. More...
 
QgsGeometry smooth (const unsigned int iterations=1, const double offset=0.25, double minimumDistance=-1.0, double maxAngle=180.0) const
 Smooths a geometry by rounding off corners using the Chaikin algorithm. More...
 
int splitGeometry (const QList< QgsPoint > &splitLine, QList< QgsGeometry > &newGeometries, bool topological, QList< QgsPoint > &topologyTestPoints)
 Splits this geometry according to a given line. More...
 
double sqrDistToVertexAt (QgsPoint &point, int atVertex) const
 Returns the squared cartesian distance between the given point to the given vertex index (vertex at the given position number, ring and item (first number is index 0)) More...
 
QgsGeometry symDifference (const QgsGeometry &geometry) const
 Returns a geometry representing the points making up this geometry that do not make up other. More...
 
bool touches (const QgsGeometry &geometry) const
 Test for if geometry touch another (uses GEOS) More...
 
int transform (const QgsCoordinateTransform &ct)
 Transform this geometry as described by CoordinateTransform ct. More...
 
int transform (const QTransform &ct)
 Transform this geometry as described by QTransform ct. More...
 
int translate (double dx, double dy)
 Translate this geometry by dx, dy. More...
 
QgsWkbTypes::GeometryType type () const
 Returns type of the geometry as a QgsWkbTypes::GeometryType. More...
 
void validateGeometry (QList< Error > &errors)
 Validate geometry and produce a list of geometry errors. More...
 
QgsPoint vertexAt (int atVertex) const
 Returns coordinates of a vertex. More...
 
bool vertexIdFromVertexNr (int nr, QgsVertexId &id) const
 Calculates the vertex ID from a vertex number. More...
 
int vertexNrFromVertexId (QgsVertexId i) const
 Returns the vertex number corresponding to a vertex idd. More...
 
bool within (const QgsGeometry &geometry) const
 Test for if geometry is within another (uses GEOS) More...
 
QgsWkbTypes::Type wkbType () const
 Returns type of the geometry as a WKB type (point / linestring / polygon etc.) More...
 

Static Public Member Functions

static QgsGeometry collectGeometry (const QList< QgsGeometry > &geometries)
 Creates a new multipart geometry from a list of QgsGeometry objects. More...
 
static bool compare (const QgsPolyline &p1, const QgsPolyline &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
 Compares two polylines for equality within a specified tolerance. More...
 
static bool compare (const QgsPolygon &p1, const QgsPolygon &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
 Compares two polygons for equality within a specified tolerance. More...
 
static bool compare (const QgsMultiPolygon &p1, const QgsMultiPolygon &p2, double epsilon=4 *std::numeric_limits< double >::epsilon())
 Compares two multipolygons for equality within a specified tolerance. More...
 
static void convertPointList (const QList< QgsPoint > &input, QgsPointSequence &output)
 Upgrades a point list from QgsPoint to QgsPointV2. More...
 
static void convertPointList (const QgsPointSequence &input, QList< QgsPoint > &output)
 Downgrades a point list from QgsPointV2 to QgsPoint. More...
 
static QgsGeometryEnginecreateGeometryEngine (const QgsAbstractGeometry *geometry)
 Creates and returns a new geometry engine. More...
 
static QgsPolygon createPolygonFromQPolygonF (const QPolygonF &polygon)
 Creates a QgsPolygon from a QPolygonF. More...
 
static QgsPolyline createPolylineFromQPolygonF (const QPolygonF &polygon)
 Creates a QgsPolyline from a QPolygonF. More...
 
static QgsGeometry fromMultiPoint (const QgsMultiPoint &multipoint)
 Creates a new geometry from a QgsMultiPoint object. More...
 
static QgsGeometry fromMultiPolygon (const QgsMultiPolygon &multipoly)
 Creates a new geometry from a QgsMultiPolygon. More...
 
static QgsGeometry fromMultiPolyline (const QgsMultiPolyline &multiline)
 Creates a new geometry from a QgsMultiPolyline object. More...
 
static QgsGeometry fromPoint (const QgsPoint &point)
 Creates a new geometry from a QgsPoint object. More...
 
static QgsGeometry fromPolygon (const QgsPolygon &polygon)
 Creates a new geometry from a QgsPolygon. More...
 
static QgsGeometry fromPolyline (const QgsPolyline &polyline)
 Creates a new geometry from a QgsPolyline object. More...
 
static QgsGeometry fromQPointF (QPointF point)
 Construct geometry from a QPointF. More...
 
static QgsGeometry fromQPolygonF (const QPolygonF &polygon)
 Construct geometry from a QPolygonF. More...
 
static QgsGeometry fromRect (const QgsRectangle &rect)
 Creates a new geometry from a QgsRectangle. More...
 
static QgsGeometry fromWkt (const QString &wkt)
 Creates a new geometry from a WKT string. More...
 
static GEOSContextHandle_t getGEOSHandler ()
 Return GEOS context handle. More...
 
static QgsGeometry unaryUnion (const QList< QgsGeometry > &geometryList)
 Compute the unary union on a list of geometries. More...
 

Detailed Description

A geometry is the spatial representation of a feature.

Since QGIS 2.10, QgsGeometry acts as a generic container for geometry objects. QgsGeometry is implicitly shared, so making copies of geometries is inexpensive. The geometry container class can also be stored inside a QVariant object.

The actual geometry representation is stored as a QgsAbstractGeometry within the container, and can be accessed via the geometry method or set using the setGeometry method.

Definition at line 78 of file qgsgeometry.h.

Member Enumeration Documentation

§ BufferSide

Side of line to buffer.

Enumerator
SideLeft 

Buffer to left of line.

SideRight 

Buffer to right of line.

Definition at line 514 of file qgsgeometry.h.

§ EndCapStyle

End cap styles for buffers.

Enumerator
CapRound 

Round cap.

CapFlat 

Flat cap (in line with start/end of line)

CapSquare 

Square cap (extends past start/end of line by buffer distance)

Definition at line 521 of file qgsgeometry.h.

§ JoinStyle

Join styles for buffers.

Enumerator
JoinStyleRound 

Use rounded joins.

JoinStyleMitre 

Use mitred joins.

JoinStyleBevel 

Use beveled joins.

Definition at line 529 of file qgsgeometry.h.

Constructor & Destructor Documentation

§ QgsGeometry() [1/3]

QgsGeometry::QgsGeometry ( )

Constructor.

Definition at line 57 of file qgsgeometry.cpp.

§ QgsGeometry() [2/3]

QgsGeometry::QgsGeometry ( const QgsGeometry other)

Copy constructor will prompt a deep copy of the object.

Definition at line 73 of file qgsgeometry.cpp.

§ QgsGeometry() [3/3]

QgsGeometry::QgsGeometry ( QgsAbstractGeometry geom)
explicit

Creates a geometry from an abstract geometry object.

Ownership of geom is transferred.

Note
added in QGIS 2.10

Definition at line 67 of file qgsgeometry.cpp.

§ ~QgsGeometry()

QgsGeometry::~QgsGeometry ( )

Destructor.

Definition at line 61 of file qgsgeometry.cpp.

Member Function Documentation

§ addPart() [1/5]

int QgsGeometry::addPart ( const QList< QgsPoint > &  points,
QgsWkbTypes::GeometryType  geomType = QgsWkbTypes::UnknownGeometry 
)

Adds a new part to a the geometry.

Parameters
pointspoints describing part to add
geomTypedefault geometry type to create if no existing geometry
Returns
0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing polygons of the feature

Definition at line 618 of file qgsgeometry.cpp.

§ addPart() [2/5]

int QgsGeometry::addPart ( const QgsPointSequence points,
QgsWkbTypes::GeometryType  geomType = QgsWkbTypes::UnknownGeometry 
)

Adds a new part to a the geometry.

Parameters
pointspoints describing part to add
geomTypedefault geometry type to create if no existing geometry
Returns
0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing polygons of the feature

Definition at line 625 of file qgsgeometry.cpp.

§ addPart() [3/5]

int QgsGeometry::addPart ( QgsAbstractGeometry part,
QgsWkbTypes::GeometryType  geomType = QgsWkbTypes::UnknownGeometry 
)

Adds a new part to this geometry.

Parameters
partpart to add (ownership is transferred)
geomTypedefault geometry type to create if no existing geometry
Returns
0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing polygons of the feature

Definition at line 641 of file qgsgeometry.cpp.

§ addPart() [4/5]

int QgsGeometry::addPart ( GEOSGeometry *  newPart)

Adds a new island polygon to a multipolygon feature.

Parameters
newPartpart to add. Ownership is NOT transferred.
Returns
0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing polygons of the feature
Note
not available in python bindings

Definition at line 715 of file qgsgeometry.cpp.

§ addPart() [5/5]

int QgsGeometry::addPart ( const QgsGeometry newPart)

Adds a new island polygon to a multipolygon feature.

Returns
0 in case of success, 1 if not a multipolygon, 2 if ring is not a valid geometry, 3 if new polygon ring not disjoint with existing polygons of the feature
Note
available in python bindings as addPartGeometry (added in 2.2)

Definition at line 670 of file qgsgeometry.cpp.

§ addRing() [1/2]

int QgsGeometry::addRing ( const QList< QgsPoint > &  ring)

Adds a new ring to this geometry.

This makes only sense for polygon and multipolygons.

Returns
0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, 3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring

Definition at line 594 of file qgsgeometry.cpp.

§ addRing() [2/2]

int QgsGeometry::addRing ( QgsCurve ring)

Adds a new ring to this geometry.

This makes only sense for polygon and multipolygons.

Returns
0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, 3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring

Definition at line 605 of file qgsgeometry.cpp.

§ adjacentVertices()

void QgsGeometry::adjacentVertices ( int  atVertex,
int &  beforeVertex,
int &  afterVertex 
) const

Returns the indexes of the vertices before and after the given vertex index.

This function takes into account the following factors:

  1. If the given vertex index is at the end of a linestring, the adjacent index will be -1 (for "no adjacent vertex")
  2. If the given vertex index is at the end of a linear ring (such as in a polygon), the adjacent index will take into account the first vertex is equal to the last vertex (and will skip equal vertex positions).

Definition at line 395 of file qgsgeometry.cpp.

§ angleAtVertex()

double QgsGeometry::angleAtVertex ( int  vertex) const

Returns the bisector angle for this geometry at the specified vertex.

Parameters
vertexvertex index to calculate bisector angle at
Returns
bisector angle, in radians clockwise from north
Note
added in QGIS 3.0
See also
interpolateAngle()

Definition at line 355 of file qgsgeometry.cpp.

§ area()

double QgsGeometry::area ( ) const

Returns the area of the geometry using GEOS.

Note
added in 1.5

Definition at line 1328 of file qgsgeometry.cpp.

§ asGeometryCollection()

QList< QgsGeometry > QgsGeometry::asGeometryCollection ( ) const

Return contents of the geometry as a list of geometries.

Note
added in version 1.1

Definition at line 1778 of file qgsgeometry.cpp.

§ asMultiPoint()

QgsMultiPoint QgsGeometry::asMultiPoint ( ) const

Return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list.

Definition at line 1212 of file qgsgeometry.cpp.

§ asMultiPolygon()

QgsMultiPolygon QgsGeometry::asMultiPolygon ( ) const

Return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list.

Definition at line 1285 of file qgsgeometry.cpp.

§ asMultiPolyline()

QgsMultiPolyline QgsGeometry::asMultiPolyline ( ) const

Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.

Definition at line 1236 of file qgsgeometry.cpp.

§ asPoint()

QgsPoint QgsGeometry::asPoint ( ) const

Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0,0].

Definition at line 1114 of file qgsgeometry.cpp.

§ asPolygon()

QgsPolygon QgsGeometry::asPolygon ( ) const

Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list.

Definition at line 1175 of file qgsgeometry.cpp.

§ asPolyline()

QgsPolyline QgsGeometry::asPolyline ( ) const

Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list.

Definition at line 1129 of file qgsgeometry.cpp.

§ asQPointF()

QPointF QgsGeometry::asQPointF ( ) const

Return contents of the geometry as a QPointF if wkbType is WKBPoint, otherwise returns a null QPointF.

Note
added in QGIS 2.7

Definition at line 1804 of file qgsgeometry.cpp.

§ asQPolygonF()

QPolygonF QgsGeometry::asQPolygonF ( ) const

Return contents of the geometry as a QPolygonF.

If geometry is a linestring, then the result will be an open QPolygonF. If the geometry is a polygon, then the result will be a closed QPolygonF of the geometry's exterior ring.

Note
added in QGIS 2.7

Definition at line 1810 of file qgsgeometry.cpp.

§ avoidIntersections()

int QgsGeometry::avoidIntersections ( const QHash< QgsVectorLayer *, QSet< QgsFeatureId > > &  ignoreFeatures = ( QHash<QgsVectorLayer*, QSet<QgsFeatureId> >() ))

Modifies geometry to avoid intersections with the layers specified in project properties.

Returns
0 in case of success, 1 if geometry is not of polygon type, 2 if avoid intersection would change the geometry type, 3 other error during intersection removal
Parameters
ignoreFeaturespossibility to give a list of features where intersections should be ignored (not available in python bindings)
Note
added in 1.5

Definition at line 1869 of file qgsgeometry.cpp.

§ boundingBox()

QgsRectangle QgsGeometry::boundingBox ( ) const

Returns the bounding box of the geometry.

See also
orientedMinimumBoundingBox()

Definition at line 856 of file qgsgeometry.cpp.

§ buffer() [1/2]

QgsGeometry QgsGeometry::buffer ( double  distance,
int  segments 
) const

Returns a buffer region around this geometry having the given width and with a specified number of segments used to approximate curves.

Definition at line 1371 of file qgsgeometry.cpp.

§ buffer() [2/2]

QgsGeometry QgsGeometry::buffer ( double  distance,
int  segments,
EndCapStyle  endCapStyle,
JoinStyle  joinStyle,
double  mitreLimit 
) const

Returns a buffer region around the geometry, with additional style options.

Parameters
distancebuffer distance
segmentsfor round joins, number of segments to approximate quarter-circle
endCapStyleend cap style
joinStylejoin style for corners in geometry
mitreLimitlimit on the mitre ratio used for very sharp corners (JoinStyleMitre only)
Note
added in 2.4

Definition at line 1387 of file qgsgeometry.cpp.

§ centroid()

QgsGeometry QgsGeometry::centroid ( ) const

Returns the center of mass of a geometry.

Note
for line based geometries, the center point of the line is returned, and for point based geometries, the point itself is returned
See also
pointOnSurface()
poleOfInaccessibility()

Definition at line 1537 of file qgsgeometry.cpp.

§ closestSegmentWithContext()

double QgsGeometry::closestSegmentWithContext ( const QgsPoint point,
QgsPoint minDistPoint,
int &  afterVertex,
double *  leftOf = nullptr,
double  epsilon = DEFAULT_SEGMENT_EPSILON 
) const

Searches for the closest segment of geometry to the given point.

Parameters
pointSpecifies the point for search
minDistPointReceives the nearest point on the segment
afterVertexReceives index of the vertex after the closest segment. The vertex before the closest segment is always afterVertex - 1
leftOfOut: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right )
epsilonepsilon for segment snapping (added in 1.8)
Returns
The squared cartesian distance is also returned in sqrDist, negative number on error

Definition at line 564 of file qgsgeometry.cpp.

§ closestVertex()

QgsPoint QgsGeometry::closestVertex ( const QgsPoint point,
int &  atVertex,
int &  beforeVertex,
int &  afterVertex,
double &  sqrDist 
) const

Returns the vertex closest to the given point, the corresponding vertex index, squared distance snap point / target point and the indices of the vertices before and after the closest vertex.

Parameters
pointpoint to search for
atVertexwill be set to the vertex index of the closest found vertex
beforeVertexwill be set to the vertex index of the previous vertex from the closest one. Will be set to -1 if not present.
afterVertexwill be set to the vertex index of the next vertex after the closest one. Will be set to -1 if not present.
sqrDistwill be set to the square distance between the closest vertex and the specified point
Returns
closest point in geometry. If not found (empty geometry), returns null point nad sqrDist is negative.

Definition at line 315 of file qgsgeometry.cpp.

§ closestVertexWithContext()

double QgsGeometry::closestVertexWithContext ( const QgsPoint point,
int &  atVertex 
) const

Searches for the closest vertex in this geometry to the given point.

Parameters
pointSpecifiest the point for search
atVertexReceives index of the closest vertex
Returns
The squared cartesian distance is also returned in sqrDist, negative number on error

Definition at line 548 of file qgsgeometry.cpp.

§ collectGeometry()

QgsGeometry QgsGeometry::collectGeometry ( const QList< QgsGeometry > &  geometries)
static

Creates a new multipart geometry from a list of QgsGeometry objects.

Definition at line 220 of file qgsgeometry.cpp.

§ combine()

QgsGeometry QgsGeometry::combine ( const QgsGeometry geometry) const

Returns a geometry representing all the points in this geometry and other (a union geometry operation).

Note
this operation is not called union since its a reserved word in C++.

Definition at line 1698 of file qgsgeometry.cpp.

§ compare() [1/3]

bool QgsGeometry::compare ( const QgsPolyline p1,
const QgsPolyline p2,
double  epsilon = 4 * std::numeric_limits<double>::epsilon() 
)
static

Compares two polylines for equality within a specified tolerance.

Parameters
p1first polyline
p2second polyline
epsilonmaximum difference for coordinates between the polylines
Returns
true if polylines have the same number of points and all points are equal within the specified tolerance
Note
added in QGIS 2.9

Definition at line 2172 of file qgsgeometry.cpp.

§ compare() [2/3]

bool QgsGeometry::compare ( const QgsPolygon p1,
const QgsPolygon p2,
double  epsilon = 4 * std::numeric_limits<double>::epsilon() 
)
static

Compares two polygons for equality within a specified tolerance.

Parameters
p1first polygon
p2second polygon
epsilonmaximum difference for coordinates between the polygons
Returns
true if polygons have the same number of rings, and each ring has the same number of points and all points are equal within the specified tolerance
Note
added in QGIS 2.9

Definition at line 2185 of file qgsgeometry.cpp.

§ compare() [3/3]

bool QgsGeometry::compare ( const QgsMultiPolygon p1,
const QgsMultiPolygon p2,
double  epsilon = 4 * std::numeric_limits<double>::epsilon() 
)
static

Compares two multipolygons for equality within a specified tolerance.

Parameters
p1first multipolygon
p2second multipolygon
epsilonmaximum difference for coordinates between the multipolygons
Returns
true if multipolygons have the same number of polygons, the polygons have the same number of rings, and each ring has the same number of points and all points are equal within the specified tolerance
Note
added in QGIS 2.9

Definition at line 2199 of file qgsgeometry.cpp.

§ contains() [1/2]

bool QgsGeometry::contains ( const QgsPoint p) const

Test for containment of a point (uses GEOS)

Definition at line 941 of file qgsgeometry.cpp.

§ contains() [2/2]

bool QgsGeometry::contains ( const QgsGeometry geometry) const

Test for if geometry is contained in another (uses GEOS)

Note
added in 1.5

Definition at line 953 of file qgsgeometry.cpp.

§ convertPointList() [1/2]

void QgsGeometry::convertPointList ( const QList< QgsPoint > &  input,
QgsPointSequence output 
)
static

Upgrades a point list from QgsPoint to QgsPointV2.

Parameters
inputlist of QgsPoint objects to be upgraded
outputdestination for list of points converted to QgsPointV2

Definition at line 2078 of file qgsgeometry.cpp.

§ convertPointList() [2/2]

void QgsGeometry::convertPointList ( const QgsPointSequence input,
QList< QgsPoint > &  output 
)
static

Downgrades a point list from QgsPointV2 to QgsPoint.

Parameters
inputlist of QgsPointV2 objects to be downgraded
outputdestination for list of points converted to QgsPoint

Definition at line 2088 of file qgsgeometry.cpp.

§ convertToMultiType()

bool QgsGeometry::convertToMultiType ( )

Converts single type geometry into multitype geometry e.g.

a polygon into a multipolygon geometry with one polygon If it is already a multipart geometry, it will return true and not change the geometry.

Returns
true in case of success and false else

Definition at line 1066 of file qgsgeometry.cpp.

§ convertToSingleType()

bool QgsGeometry::convertToSingleType ( )

Converts multi type geometry into single type geometry e.g.

a multipolygon into a polygon geometry. Only the first part of the multi geometry will be retained. If it is already a single part geometry, it will return true and not change the geometry.

Returns
true in case of success and false else

Definition at line 1091 of file qgsgeometry.cpp.

§ convertToStraightSegment()

void QgsGeometry::convertToStraightSegment ( )

Converts the geometry to straight line segments, if it is a curved geometry type.

Note
added in QGIS 2.10
See also
requiresConversionToStraightSegments

Definition at line 1941 of file qgsgeometry.cpp.

§ convertToType()

QgsGeometry QgsGeometry::convertToType ( QgsWkbTypes::GeometryType  destType,
bool  destMultipart = false 
) const

Try to convert the geometry to the requested type.

Parameters
destTypethe geometry type to be converted to
destMultipartdetermines if the output geometry will be multipart or not
Returns
the converted geometry or nullptr if the conversion fails.
Note
added in 2.2

Definition at line 1048 of file qgsgeometry.cpp.

§ convexHull()

QgsGeometry QgsGeometry::convexHull ( ) const

Returns the smallest convex polygon that contains all the points in the geometry.

Definition at line 1578 of file qgsgeometry.cpp.

§ createGeometryEngine()

QgsGeometryEngine * QgsGeometry::createGeometryEngine ( const QgsAbstractGeometry geometry)
static

Creates and returns a new geometry engine.

Definition at line 2703 of file qgsgeometry.cpp.

§ createPolygonFromQPolygonF()

QgsPolygon QgsGeometry::createPolygonFromQPolygonF ( const QPolygonF &  polygon)
static

Creates a QgsPolygon from a QPolygonF.

Parameters
polygonsource polygon
Returns
QgsPolygon
See also
createPolylineFromQPolygonF

Definition at line 2154 of file qgsgeometry.cpp.

§ createPolylineFromQPolygonF()

QgsPolyline QgsGeometry::createPolylineFromQPolygonF ( const QPolygonF &  polygon)
static

Creates a QgsPolyline from a QPolygonF.

Parameters
polygonsource polygon
Returns
QgsPolyline
See also
createPolygonFromQPolygonF

Definition at line 2161 of file qgsgeometry.cpp.

§ crosses()

bool QgsGeometry::crosses ( const QgsGeometry geometry) const

Test for if geometry crosses another (uses GEOS)

Note
added in 1.5

Definition at line 1019 of file qgsgeometry.cpp.

§ deletePart()

bool QgsGeometry::deletePart ( int  partNum)

Delete part identified by the part number.

Returns
true on success
Note
added in version 1.2

Definition at line 1851 of file qgsgeometry.cpp.

§ deleteRing()

bool QgsGeometry::deleteRing ( int  ringNum,
int  partNum = 0 
)

Delete a ring in polygon or multipolygon.

Ring 0 is outer ring and can't be deleted.

Returns
true on success
Note
added in version 1.2

Definition at line 1839 of file qgsgeometry.cpp.

§ deleteVertex()

bool QgsGeometry::deleteVertex ( int  atVertex)

Deletes the vertex at the given position number and item (first number is index 0) Returns false if atVertex does not correspond to a valid vertex on this geometry (including if this geometry is a Point), or if the number of remaining verticies in the linestring would be less than two.

It is up to the caller to distinguish between these error conditions. (Or maybe we add another method to this object to help make the distinction?)

Definition at line 452 of file qgsgeometry.cpp.

§ difference()

QgsGeometry QgsGeometry::difference ( const QgsGeometry geometry) const

Returns a geometry representing the points making up this geometry that do not make up other.

Definition at line 1732 of file qgsgeometry.cpp.

§ disjoint()

bool QgsGeometry::disjoint ( const QgsGeometry geometry) const

Test for if geometry is disjoint of another (uses GEOS)

Note
added in 1.5

Definition at line 964 of file qgsgeometry.cpp.

§ distance()

double QgsGeometry::distance ( const QgsGeometry geom) const

Returns the minimum distance between this geometry and another geometry, using GEOS.

Will return a negative value if a geometry is missing.

Parameters
geomgeometry to find minimum distance to

Definition at line 1360 of file qgsgeometry.cpp.

§ distanceToVertex()

double QgsGeometry::distanceToVertex ( int  vertex) const

Returns the distance along this geometry from its first vertex to the specified vertex.

Parameters
vertexvertex index to calculate distance to
Returns
distance to vertex (following geometry), or -1 for invalid vertex numbers
Note
added in QGIS 2.16

Definition at line 339 of file qgsgeometry.cpp.

§ draw()

void QgsGeometry::draw ( QPainter &  p) const

Draws the geometry onto a QPainter.

Parameters
pdestination QPainter
Note
added in QGIS 2.10

Definition at line 2009 of file qgsgeometry.cpp.

§ equals()

bool QgsGeometry::equals ( const QgsGeometry geometry) const

Test for if geometry equals another (uses GEOS)

Note
added in 1.5

Definition at line 975 of file qgsgeometry.cpp.

§ exportToGeoJSON()

QString QgsGeometry::exportToGeoJSON ( int  precision = 17) const

Exports the geometry to GeoJSON.

Returns
a QString representing the geometry as GeoJSON
Note
added in 1.8
python binding added in 1.9
precision parameter added in 2.4

Definition at line 1039 of file qgsgeometry.cpp.

§ exportToGeos()

GEOSGeometry * QgsGeometry::exportToGeos ( double  precision = 0) const

Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destroy_r)

Parameters
precisionThe precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
Note
added in 3.0
not available in python bindings

Definition at line 265 of file qgsgeometry.cpp.

§ exportToWkb()

QByteArray QgsGeometry::exportToWkb ( ) const

Export the geometry to WKB.

Note
added in 3.0

Definition at line 1773 of file qgsgeometry.cpp.

§ exportToWkt()

QString QgsGeometry::exportToWkt ( int  precision = 17) const

Exports the geometry to WKT.

Note
precision parameter added in 2.4
Returns
true in case of success and false else

Definition at line 1030 of file qgsgeometry.cpp.

§ extendLine()

QgsGeometry QgsGeometry::extendLine ( double  startDistance,
double  endDistance 
) const

Extends a (multi)line geometry by extrapolating out the start or end of the line by a specified distance.

Lines are extended using the bearing of the first or last segment in the line.

Note
added in QGIS 3.0

Definition at line 1482 of file qgsgeometry.cpp.

§ extrude()

QgsGeometry QgsGeometry::extrude ( double  x,
double  y 
)

Returns an extruded version of this geometry.

Definition at line 1766 of file qgsgeometry.cpp.

§ fromGeos()

void QgsGeometry::fromGeos ( GEOSGeometry *  geos)

Set the geometry, feeding in a geometry in GEOS format.

This class will take ownership of the buffer.

Note
not available in python bindings

Definition at line 307 of file qgsgeometry.cpp.

§ fromMultiPoint()

QgsGeometry QgsGeometry::fromMultiPoint ( const QgsMultiPoint multipoint)
static

Creates a new geometry from a QgsMultiPoint object.

Definition at line 175 of file qgsgeometry.cpp.

§ fromMultiPolygon()

QgsGeometry QgsGeometry::fromMultiPolygon ( const QgsMultiPolygon multipoly)
static

Creates a new geometry from a QgsMultiPolygon.

Definition at line 195 of file qgsgeometry.cpp.

§ fromMultiPolyline()

QgsGeometry QgsGeometry::fromMultiPolyline ( const QgsMultiPolyline multiline)
static

Creates a new geometry from a QgsMultiPolyline object.

Definition at line 185 of file qgsgeometry.cpp.

§ fromPoint()

QgsGeometry QgsGeometry::fromPoint ( const QgsPoint point)
static

Creates a new geometry from a QgsPoint object.

Definition at line 145 of file qgsgeometry.cpp.

§ fromPolygon()

QgsGeometry QgsGeometry::fromPolygon ( const QgsPolygon polygon)
static

Creates a new geometry from a QgsPolygon.

Definition at line 165 of file qgsgeometry.cpp.

§ fromPolyline()

QgsGeometry QgsGeometry::fromPolyline ( const QgsPolyline polyline)
static

Creates a new geometry from a QgsPolyline object.

Definition at line 155 of file qgsgeometry.cpp.

§ fromQPointF()

QgsGeometry QgsGeometry::fromQPointF ( QPointF  point)
static

Construct geometry from a QPointF.

Parameters
pointsource QPointF
Note
added in QGIS 2.7

Definition at line 2137 of file qgsgeometry.cpp.

§ fromQPolygonF()

QgsGeometry QgsGeometry::fromQPolygonF ( const QPolygonF &  polygon)
static

Construct geometry from a QPolygonF.

If the polygon is closed than the resultant geometry will be a polygon, if it is open than the geometry will be a polyline.

Parameters
polygonsource QPolygonF
Note
added in QGIS 2.7

Definition at line 2142 of file qgsgeometry.cpp.

§ fromRect()

QgsGeometry QgsGeometry::fromRect ( const QgsRectangle rect)
static

Creates a new geometry from a QgsRectangle.

Definition at line 205 of file qgsgeometry.cpp.

§ fromWkb() [1/2]

void QgsGeometry::fromWkb ( unsigned char *  wkb,
int  length 
)

Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.

This class will take ownership of the buffer.

Note
not available in python bindings

Definition at line 240 of file qgsgeometry.cpp.

§ fromWkb() [2/2]

void QgsGeometry::fromWkb ( const QByteArray &  wkb)

Set the geometry, feeding in the buffer containing OGC Well-Known Binary.

Note
added in 3.0

Definition at line 253 of file qgsgeometry.cpp.

§ fromWkt()

QgsGeometry QgsGeometry::fromWkt ( const QString &  wkt)
static

Creates a new geometry from a WKT string.

Definition at line 135 of file qgsgeometry.cpp.

§ geometry()

QgsAbstractGeometry * QgsGeometry::geometry ( ) const

Returns the underlying geometry store.

Note
added in QGIS 2.10
See also
setGeometry

Definition at line 108 of file qgsgeometry.cpp.

§ getGEOSHandler()

GEOSContextHandle_t QgsGeometry::getGEOSHandler ( )
static

Return GEOS context handle.

Note
added in 2.6
not available in Python

Definition at line 2132 of file qgsgeometry.cpp.

§ insertVertex()

bool QgsGeometry::insertVertex ( double  x,
double  y,
int  beforeVertex 
)

Insert a new vertex before the given vertex index, ring and item (first number is index 0) If the requested vertex number (beforeVertex.back()) is greater than the last actual vertex on the requested ring and item, it is assumed that the vertex is to be appended instead of inserted.

Returns false if atVertex does not correspond to a valid vertex on this geometry (including if this geometry is a Point). It is up to the caller to distinguish between these error conditions. (Or maybe we add another method to this object to help make the distinction?)

Definition at line 487 of file qgsgeometry.cpp.

§ interpolate()

QgsGeometry QgsGeometry::interpolate ( double  distance) const

Return interpolated point on line at distance.

Note
added in 1.9
See also
lineLocatePoint()

Definition at line 1593 of file qgsgeometry.cpp.

§ interpolateAngle()

double QgsGeometry::interpolateAngle ( double  distance) const

Returns the angle parallel to the linestring or polygon boundary at the specified distance along the geometry.

Angles are in radians, clockwise from north. If the distance coincides precisely at a node then the average angle from the segment either side of the node is returned.

Parameters
distancedistance along geometry
Note
added in QGIS 3.0
See also
angleAtVertex()

Definition at line 1631 of file qgsgeometry.cpp.

§ intersection()

QgsGeometry QgsGeometry::intersection ( const QgsGeometry geometry) const

Returns a geometry representing the points shared by this geometry and other.

Definition at line 1685 of file qgsgeometry.cpp.

§ intersects() [1/2]

bool QgsGeometry::intersects ( const QgsRectangle r) const

Test for intersection with a rectangle (uses GEOS)

Definition at line 924 of file qgsgeometry.cpp.

§ intersects() [2/2]

bool QgsGeometry::intersects ( const QgsGeometry geometry) const

Test for intersection with a geometry (uses GEOS)

Definition at line 930 of file qgsgeometry.cpp.

§ isEmpty()

bool QgsGeometry::isEmpty ( ) const

Returns true if the geometry is empty (ie, contains no underlying geometry accessible via geometry).

See also
geometry
Note
added in QGIS 2.10

Definition at line 130 of file qgsgeometry.cpp.

§ isGeosEmpty()

bool QgsGeometry::isGeosEmpty ( ) const

Check if the geometry is empty using GEOS.

Note
added in 1.5

Definition at line 1912 of file qgsgeometry.cpp.

§ isGeosEqual()

bool QgsGeometry::isGeosEqual ( const QgsGeometry g) const

Compares the geometry with another geometry using GEOS.

Note
added in 1.5

Definition at line 1901 of file qgsgeometry.cpp.

§ isGeosValid()

bool QgsGeometry::isGeosValid ( ) const

Checks validity of the geometry using GEOS.

Note
added in 1.5

Definition at line 1890 of file qgsgeometry.cpp.

§ isMultipart()

bool QgsGeometry::isMultipart ( ) const

Returns true if WKB of the geometry is of WKBMulti* type.

Definition at line 298 of file qgsgeometry.cpp.

§ length()

double QgsGeometry::length ( ) const

Returns the length of geometry using GEOS.

Note
added in 1.5

Definition at line 1350 of file qgsgeometry.cpp.

§ lineLocatePoint()

double QgsGeometry::lineLocatePoint ( const QgsGeometry point) const

Returns a distance representing the location along this linestring of the closest point on this linestring geometry to the specified point.

Ie, the returned value indicates how far along this linestring you need to traverse to get to the closest location where this linestring comes to the specified point.

Parameters
pointpoint to seek proximity to
Returns
distance along line, or -1 on error
Note
only valid for linestring geometries
See also
interpolate()
Note
added in QGIS 3.0

Definition at line 1613 of file qgsgeometry.cpp.

§ makeDifference() [1/2]

int QgsGeometry::makeDifference ( const QgsGeometry other)

Changes this geometry such that it does not intersect the other geometry.

Parameters
othergeometry that should not be intersect
Returns
0 in case of success

Definition at line 816 of file qgsgeometry.cpp.

§ makeDifference() [2/2]

QgsGeometry QgsGeometry::makeDifference ( const QgsGeometry other) const

Returns the geometry formed by modifying this geometry such that it does not intersect the other geometry.

Parameters
othergeometry that should not be intersect
Returns
difference geometry, or empty geometry if difference could not be calculated
Note
added in QGIS 3.0

Definition at line 838 of file qgsgeometry.cpp.

§ mapToPixel()

void QgsGeometry::mapToPixel ( const QgsMapToPixel mtp)

Transforms the geometry from map units to pixels in place.

Parameters
mtpmap to pixel transform
Note
added in QGIS 2.10

Definition at line 1988 of file qgsgeometry.cpp.

§ mergeLines()

QgsGeometry QgsGeometry::mergeLines ( ) const

Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line strings.

Returns
a LineString or MultiLineString geometry, with any connected lines joined. An empty geometry will be returned if the input geometry was not a MultiLineString geometry.
Note
added in QGIS 3.0

Definition at line 1715 of file qgsgeometry.cpp.

§ moveVertex() [1/2]

bool QgsGeometry::moveVertex ( double  x,
double  y,
int  atVertex 
)

Moves the vertex at the given position number and item (first number is index 0) to the given coordinates.

Returns false if atVertex does not correspond to a valid vertex on this geometry

Definition at line 416 of file qgsgeometry.cpp.

§ moveVertex() [2/2]

bool QgsGeometry::moveVertex ( const QgsPointV2 p,
int  atVertex 
)

Moves the vertex at the given position number and item (first number is index 0) to the given coordinates.

Returns false if atVertex does not correspond to a valid vertex on this geometry

Definition at line 434 of file qgsgeometry.cpp.

§ nearestPoint()

QgsGeometry QgsGeometry::nearestPoint ( const QgsGeometry other) const

Returns the nearest point on this geometry to another geometry.

Note
added in QGIS 2.14
See also
shortestLine()

Definition at line 536 of file qgsgeometry.cpp.

§ offsetCurve()

QgsGeometry QgsGeometry::offsetCurve ( double  distance,
int  segments,
JoinStyle  joinStyle,
double  mitreLimit 
) const

Returns an offset line at a given distance and side from an input line.

Parameters
distancebuffer distance
segmentsfor round joins, number of segments to approximate quarter-circle
joinStylejoin style for corners in geometry
mitreLimitlimit on the mitre ratio used for very sharp corners (JoinStyleMitre only)
Note
added in 2.4

Definition at line 1403 of file qgsgeometry.cpp.

§ operator bool()

QgsGeometry::operator bool ( ) const

Returns true if the geometry is non empty (ie, isEmpty() returns false), or false if it is an empty, uninitialised geometry (ie, ieEmpty() returns true).

Note
added in QGIS 3.0

Definition at line 2098 of file qgsgeometry.cpp.

§ operator QVariant()

QgsGeometry::operator QVariant ( ) const
inline

Allows direct construction of QVariants from geometry.

Definition at line 966 of file qgsgeometry.h.

§ operator=()

QgsGeometry & QgsGeometry::operator= ( QgsGeometry const &  rhs)

Assignments will prompt a deep copy of the object.

Note
not available in python bindings

Definition at line 79 of file qgsgeometry.cpp.

§ orientedMinimumBoundingBox()

QgsGeometry QgsGeometry::orientedMinimumBoundingBox ( double &  area,
double &  angle,
double &  width,
double &  height 
) const

Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated rectangle which fully encompasses the geometry.

The area, angle (clockwise in degrees from North), width and height of the rotated bounding box will also be returned.

Note
added in QGIS 3.0
See also
boundingBox()

Definition at line 865 of file qgsgeometry.cpp.

§ overlaps()

bool QgsGeometry::overlaps ( const QgsGeometry geometry) const

Test for if geometry overlaps another (uses GEOS)

Note
added in 1.5

Definition at line 997 of file qgsgeometry.cpp.

§ pointOnSurface()

QgsGeometry QgsGeometry::pointOnSurface ( ) const

Returns a point guaranteed to lie on the surface of a geometry.

While the centroid() of a geometry may be located outside of the geometry itself (eg for concave shapes), the point on surface will always be inside the geometry.

See also
centroid()
poleOfInaccessibility()

Definition at line 1554 of file qgsgeometry.cpp.

§ poleOfInaccessibility()

QgsGeometry QgsGeometry::poleOfInaccessibility ( double  precision,
double *  distanceToBoundary = nullptr 
) const

Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary of the surface.

This function uses the 'polylabel' algorithm (Vladimir Agafonkin, 2016), which is an iterative approach guaranteed to find the true pole of inaccessibility within a specified tolerance. More precise tolerances require more iterations and will take longer to calculate. Optionally, the distance to the polygon boundary from the pole can be stored.

See also
centroid()
pointOnSurface()
Note
added in QGIS 3.0

Definition at line 1571 of file qgsgeometry.cpp.

§ removeInteriorRings()

QgsGeometry QgsGeometry::removeInteriorRings ( double  minimumAllowedArea = -1) const

Removes the interior rings from a (multi)polygon geometry.

If the minimumAllowedArea parameter is specified then only rings smaller than this minimum area will be removed.

Note
added in QGIS 3.0

Definition at line 680 of file qgsgeometry.cpp.

§ requiresConversionToStraightSegments()

bool QgsGeometry::requiresConversionToStraightSegments ( ) const

Returns true if the geometry is a curved geometry type which requires conversion to display as straight line segments.

Note
added in QGIS 2.10
See also
convertToStraightSegment

Definition at line 1954 of file qgsgeometry.cpp.

§ reshapeGeometry()

int QgsGeometry::reshapeGeometry ( const QList< QgsPoint > &  reshapeWithLine)

Replaces a part of this geometry with another line.

Returns
0 in case of success
Note
: this function was added in version 1.3

Definition at line 791 of file qgsgeometry.cpp.

§ rotate()

int QgsGeometry::rotate ( double  rotation,
const QgsPoint center 
)

Rotate this geometry around the Z axis.

Note
added in 2.8
Parameters
rotationclockwise rotation in degrees
centerrotation center
Returns
0 in case of success

Definition at line 741 of file qgsgeometry.cpp.

§ setGeometry()

void QgsGeometry::setGeometry ( QgsAbstractGeometry geometry)

Sets the underlying geometry store.

Ownership of geometry is transferred.

Note
added in QGIS 2.10
See also
geometry

Definition at line 113 of file qgsgeometry.cpp.

§ shortestLine()

QgsGeometry QgsGeometry::shortestLine ( const QgsGeometry other) const

Returns the shortest line joining this geometry to another geometry.

Note
added in QGIS 2.14
See also
nearestPoint()

Definition at line 542 of file qgsgeometry.cpp.

§ simplify()

QgsGeometry QgsGeometry::simplify ( double  tolerance) const

Returns a simplified version of this geometry using a specified tolerance value.

Definition at line 1521 of file qgsgeometry.cpp.

§ singleSidedBuffer()

QgsGeometry QgsGeometry::singleSidedBuffer ( double  distance,
int  segments,
BufferSide  side,
JoinStyle  joinStyle = JoinStyleRound,
double  mitreLimit = 2.0 
) const

Returns a single sided buffer for a (multi)line geometry.

The buffer is only applied to one side of the line.

Parameters
distancebuffer distance
segmentsfor round joins, number of segments to approximate quarter-circle
sideside of geometry to buffer
joinStylejoin style for corners
mitreLimitlimit on the mitre ratio used for very sharp corners
Returns
buffered geometry, or an empty geometry if buffer could not be calculated
Note
added in QGIS 3.0

Definition at line 1442 of file qgsgeometry.cpp.

§ smooth()

QgsGeometry QgsGeometry::smooth ( const unsigned int  iterations = 1,
const double  offset = 0.25,
double  minimumDistance = -1.0,
double  maxAngle = 180.0 
) const

Smooths a geometry by rounding off corners using the Chaikin algorithm.

This operation roughly doubles the number of vertices in a geometry.

Parameters
iterationsnumber of smoothing iterations to run. More iterations results in a smoother geometry
offsetfraction of line to create new vertices along, between 0 and 1.0 eg the default value of 0.25 will create new vertices 25% and 75% along each line segment of the geometry for each iteration. Smaller values result in "tighter" smoothing.
minimumDistanceminimum segment length to apply smoothing to
maxAnglemaximum angle at node (0-180) at which smoothing will be applied
Note
added in 2.9

Definition at line 2212 of file qgsgeometry.cpp.

§ splitGeometry()

int QgsGeometry::splitGeometry ( const QList< QgsPoint > &  splitLine,
QList< QgsGeometry > &  newGeometries,
bool  topological,
QList< QgsPoint > &  topologyTestPoints 
)

Splits this geometry according to a given line.

Parameters
splitLinethe line that splits the geometry
[out]newGeometrieslist of new geometries that have been created with the split
topologicaltrue if topological editing is enabled
[out]topologyTestPointspoints that need to be tested for topological completeness in the dataset
Returns
0 in case of success, 1 if geometry has not been split, error else

Definition at line 757 of file qgsgeometry.cpp.

§ sqrDistToVertexAt()

double QgsGeometry::sqrDistToVertexAt ( QgsPoint point,
int  atVertex 
) const

Returns the squared cartesian distance between the given point to the given vertex index (vertex at the given position number, ring and item (first number is index 0))

Definition at line 530 of file qgsgeometry.cpp.

§ symDifference()

QgsGeometry QgsGeometry::symDifference ( const QgsGeometry geometry) const

Returns a geometry representing the points making up this geometry that do not make up other.

Definition at line 1749 of file qgsgeometry.cpp.

§ touches()

bool QgsGeometry::touches ( const QgsGeometry geometry) const

Test for if geometry touch another (uses GEOS)

Note
added in 1.5

Definition at line 986 of file qgsgeometry.cpp.

§ transform() [1/2]

int QgsGeometry::transform ( const QgsCoordinateTransform ct)

Transform this geometry as described by CoordinateTransform ct.

Returns
0 in case of success

Definition at line 1964 of file qgsgeometry.cpp.

§ transform() [2/2]

int QgsGeometry::transform ( const QTransform &  ct)

Transform this geometry as described by QTransform ct.

Note
added in 2.8
Returns
0 in case of success

Definition at line 1976 of file qgsgeometry.cpp.

§ translate()

int QgsGeometry::translate ( double  dx,
double  dy 
)

Translate this geometry by dx, dy.

Returns
0 in case of success

Definition at line 728 of file qgsgeometry.cpp.

§ type()

QgsWkbTypes::GeometryType QgsGeometry::type ( ) const

Returns type of the geometry as a QgsWkbTypes::GeometryType.

See also
wkbType

Definition at line 289 of file qgsgeometry.cpp.

§ unaryUnion()

QgsGeometry QgsGeometry::unaryUnion ( const QList< QgsGeometry > &  geometryList)
static

Compute the unary union on a list of geometries.

May be faster than an iterative union on a set of geometries.

Parameters
geometryLista list of QgsGeometry as input
Returns
the new computed QgsGeometry, or an empty QgsGeometry

Definition at line 1923 of file qgsgeometry.cpp.

§ validateGeometry()

void QgsGeometry::validateGeometry ( QList< Error > &  errors)

Validate geometry and produce a list of geometry errors.

Note
added in 1.5
python binding added in 1.6

Definition at line 1885 of file qgsgeometry.cpp.

§ vertexAt()

QgsPoint QgsGeometry::vertexAt ( int  atVertex) const

Returns coordinates of a vertex.

Parameters
atVertexindex of the vertex
Returns
Coordinates of the vertex or QgsPoint(0,0) on error

Definition at line 513 of file qgsgeometry.cpp.

§ vertexIdFromVertexNr()

bool QgsGeometry::vertexIdFromVertexNr ( int  nr,
QgsVertexId id 
) const

Calculates the vertex ID from a vertex number.

Parameters
nrvertex number
idreference to QgsVertexId for storing result
Returns
true if vertex was found
Note
added in QGIS 2.10
See also
vertexNrFromVertexId

Definition at line 2017 of file qgsgeometry.cpp.

§ vertexNrFromVertexId()

int QgsGeometry::vertexNrFromVertexId ( QgsVertexId  i) const

Returns the vertex number corresponding to a vertex idd.

Parameters
ivertex id
Returns
vertex number
Note
added in QGIS 2.10
See also
vertexIdFromVertexNr

Definition at line 2049 of file qgsgeometry.cpp.

§ within()

bool QgsGeometry::within ( const QgsGeometry geometry) const

Test for if geometry is within another (uses GEOS)

Note
added in 1.5

Definition at line 1008 of file qgsgeometry.cpp.

§ wkbType()

QgsWkbTypes::Type QgsGeometry::wkbType ( ) const

Returns type of the geometry as a WKB type (point / linestring / polygon etc.)

See also
type

Definition at line 276 of file qgsgeometry.cpp.


The documentation for this class was generated from the following files: