QGIS API Documentation  2.14.0-Essen
Classes | 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 Member Functions

 QgsGeometry ()
 Constructor. More...
 
 QgsGeometry (const QgsGeometry &)
 Copy constructor will prompt a deep copy of the object. More...
 
 QgsGeometry (QgsAbstractGeometryV2 *geom)
 Creates a geometry from an abstract geometry object. More...
 
 ~QgsGeometry ()
 Destructor. More...
 
int addPart (const QList< QgsPoint > &points, QGis::GeometryType geomType=QGis::UnknownGeometry)
 Adds a new part to a the geometry. More...
 
int addPart (const QgsPointSequenceV2 &points, QGis::GeometryType geomType=QGis::UnknownGeometry)
 Adds a new part to a the geometry. More...
 
int addPart (QgsAbstractGeometryV2 *part, QGis::GeometryType geomType=QGis::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 (QgsCurveV2 *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 area () const
 Returns the area of the geometry using GEOS. More...
 
QList< QgsGeometry * > asGeometryCollection () const
 Return contents of the geometry as a list of geometries. More...
 
const GEOSGeometry * asGeos (double precision=0) const
 Returns a geos geometry. 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...
 
const unsigned char * asWkb () const
 Returns the buffer containing this geometry in WKB format. More...
 
int avoidIntersections (const QMap< QgsVectorLayer *, QSet< QgsFeatureId > > &ignoreFeatures=(QMap< QgsVectorLayer *, QSet< QgsFeatureId > >()))
 Modifies geometry to avoid intersections with the layers specified in project properties. More...
 
QgsRectangle boundingBox () const
 Returns the bounding box of this feature. More...
 
QgsGeometrybuffer (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...
 
QgsGeometrybuffer (double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit) const
 Returns a buffer region around the geometry, with additional style options. More...
 
QgsGeometrycentroid () 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/after. More...
 
double closestVertexWithContext (const QgsPoint &point, int &atVertex) const
 Searches for the closest vertex in this geometry to the given point. More...
 
QgsGeometrycombine (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...
 
QgsGeometryconvertToType (QGis::GeometryType destType, bool destMultipart=false) const
 Try to convert the geometry to the requested type. More...
 
QgsGeometryconvexHull () 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...
 
QgsGeometrydifference (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...
 
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...
 
QString exportToWkt (int precision=17) const
 Exports the geometry to WKT. 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...
 
QgsAbstractGeometryV2geometry () 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...
 
QgsGeometryinterpolate (double distance) const
 Return interpolated point on line at distance. More...
 
QgsGeometryintersection (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...
 
int makeDifference (const QgsGeometry *other)
 Changes 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...
 
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...
 
QgsGeometryoffsetCurve (double distance, int segments, int joinStyle, double mitreLimit) const
 Returns an offset line at a given distance and side from an input line. More...
 
QgsGeometryoperator= (QgsGeometry const &rhs)
 Assignments will prompt a deep copy of the object. More...
 
bool overlaps (const QgsGeometry *geometry) const
 Test for if geometry overlaps another (uses GEOS) More...
 
QgsGeometrypointOnSurface () const
 Returns a point within a 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 (QgsAbstractGeometryV2 *geometry)
 Sets the underlying geometry store. More...
 
QgsGeometry shortestLine (const QgsGeometry &other) const
 Returns the shortest line joining this geometry to another geometry. More...
 
QgsGeometrysimplify (double tolerance) const
 Returns a simplified version of this geometry using a specified tolerance value. More...
 
QgsGeometrysmooth (const unsigned int iterations=1, const double offset=0.25) const
 Smooths a geometry by rounding off corners using the Chaikin algorithm. More...
 
QgsPolyline smoothLine (const QgsPolyline &polyline, const unsigned int iterations=1, const double offset=0.25) const
 Smooths a polyline using the Chaikin algorithm. More...
 
QgsPolygon smoothPolygon (const QgsPolygon &polygon, const unsigned int iterations=1, const double offset=0.25) const
 Smooths a polygon 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...
 
QgsGeometrysymDifference (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...
 
QGis::GeometryType type () const
 Returns type of the geometry as a QGis::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...
 
int wkbSize () const
 Returns the size of the WKB in asWkb(). More...
 
QGis::WkbType wkbType () const
 Returns type of the geometry as a WKB type (point / linestring / polygon etc.) More...
 

Static Public Member Functions

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, QgsPointSequenceV2 &output)
 Upgrades a point list from QgsPoint to QgsPointV2. More...
 
static void convertPointList (const QgsPointSequenceV2 &input, QList< QgsPoint > &output)
 Downgrades a point list from QgsPointV2 to QgsPoint. More...
 
static QgsGeometryEnginecreateGeometryEngine (const QgsAbstractGeometryV2 *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 QgsGeometryfromMultiPoint (const QgsMultiPoint &multipoint)
 Creates a new geometry from a QgsMultiPoint object. More...
 
static QgsGeometryfromMultiPolygon (const QgsMultiPolygon &multipoly)
 Creates a new geometry from a QgsMultiPolygon. More...
 
static QgsGeometryfromMultiPolyline (const QgsMultiPolyline &multiline)
 Creates a new geometry from a QgsMultiPolyline object. More...
 
static QgsGeometryfromPoint (const QgsPoint &point)
 Creates a new geometry from a QgsPoint object. More...
 
static QgsGeometryfromPolygon (const QgsPolygon &polygon)
 Creates a new geometry from a QgsPolygon. More...
 
static QgsGeometryfromPolyline (const QgsPolyline &polyline)
 Creates a new geometry from a QgsPolyline object. More...
 
static QgsGeometryfromQPointF (QPointF point)
 Construct geometry from a QPointF. More...
 
static QgsGeometryfromQPolygonF (const QPolygonF &polygon)
 Construct geometry from a QPolygonF. More...
 
static QgsGeometryfromRect (const QgsRectangle &rect)
 Creates a new geometry from a QgsRectangle. More...
 
static QgsGeometryfromWkt (const QString &wkt)
 Creates a new geometry from a WKT string. More...
 
static GEOSContextHandle_t getGEOSHandler ()
 Return GEOS context handle. More...
 
static QgsGeometryunaryUnion (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 QgsAbstractGeometryV2 within the container, and can be accessed via the geometry method or set using the setGeometry method.

Definition at line 76 of file qgsgeometry.h.

Constructor & Destructor Documentation

QgsGeometry::QgsGeometry ( )

Constructor.

Definition at line 65 of file qgsgeometry.cpp.

QgsGeometry::QgsGeometry ( const QgsGeometry other)

Copy constructor will prompt a deep copy of the object.

Definition at line 81 of file qgsgeometry.cpp.

QgsGeometry::QgsGeometry ( QgsAbstractGeometryV2 geom)
explicit

Creates a geometry from an abstract geometry object.

Ownership of geom is transferred.

Note
added in QGIS 2.10

Definition at line 75 of file qgsgeometry.cpp.

QgsGeometry::~QgsGeometry ( )

Destructor.

Definition at line 69 of file qgsgeometry.cpp.

Member Function Documentation

int QgsGeometry::addPart ( const QList< QgsPoint > &  points,
QGis::GeometryType  geomType = QGis::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 593 of file qgsgeometry.cpp.

int QgsGeometry::addPart ( const QgsPointSequenceV2 points,
QGis::GeometryType  geomType = QGis::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 600 of file qgsgeometry.cpp.

int QgsGeometry::addPart ( QgsAbstractGeometryV2 part,
QGis::GeometryType  geomType = QGis::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 616 of file qgsgeometry.cpp.

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 656 of file qgsgeometry.cpp.

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 646 of file qgsgeometry.cpp.

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 567 of file qgsgeometry.cpp.

int QgsGeometry::addRing ( QgsCurveV2 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 579 of file qgsgeometry.cpp.

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 364 of file qgsgeometry.cpp.

double QgsGeometry::area ( ) const

Returns the area of the geometry using GEOS.

Note
added in 1.5

Definition at line 1201 of file qgsgeometry.cpp.

QList< QgsGeometry * > QgsGeometry::asGeometryCollection ( ) const

Return contents of the geometry as a list of geometries.

Note
added in version 1.1

Definition at line 1443 of file qgsgeometry.cpp.

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

Returns a geos geometry.

QgsGeometry retains ownership of the geometry, so the returned object should not be deleted.

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

Definition at line 287 of file qgsgeometry.cpp.

QgsMultiPoint QgsGeometry::asMultiPoint ( ) const

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

Definition at line 1085 of file qgsgeometry.cpp.

QgsMultiPolygon QgsGeometry::asMultiPolygon ( ) const

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

Definition at line 1158 of file qgsgeometry.cpp.

QgsMultiPolyline QgsGeometry::asMultiPolyline ( ) const

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

Definition at line 1109 of file qgsgeometry.cpp.

QgsPoint QgsGeometry::asPoint ( ) const

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

Definition at line 988 of file qgsgeometry.cpp.

QgsPolygon QgsGeometry::asPolygon ( ) const

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

Definition at line 1048 of file qgsgeometry.cpp.

QgsPolyline QgsGeometry::asPolyline ( ) const

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

Definition at line 1003 of file qgsgeometry.cpp.

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 1469 of file qgsgeometry.cpp.

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 1475 of file qgsgeometry.cpp.

const unsigned char * QgsGeometry::asWkb ( ) const

Returns the buffer containing this geometry in WKB format.

You may wish to use in conjunction with wkbSize().

See also
wkbSize

Definition at line 259 of file qgsgeometry.cpp.

int QgsGeometry::avoidIntersections ( const QMap< QgsVectorLayer *, QSet< QgsFeatureId > > &  ignoreFeatures = QMap<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 1535 of file qgsgeometry.cpp.

QgsRectangle QgsGeometry::boundingBox ( ) const

Returns the bounding box of this feature.

Definition at line 785 of file qgsgeometry.cpp.

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 1244 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::buffer ( double  distance,
int  segments,
int  endCapStyle,
int  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
endCapStyleRound (1) / Flat (2) / Square (3) end cap style
joinStyleRound (1) / Mitre (2) / Bevel (3) join style
mitreLimitLimit on the mitre ratio used for very sharp corners
Note
added in 2.4
needs GEOS >= 3.3 - otherwise always returns 0

Definition at line 1260 of file qgsgeometry.cpp.

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

Definition at line 1308 of file qgsgeometry.cpp.

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 539 of file qgsgeometry.cpp.

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/after.

The vertices before/after are -1 if not present

Definition at line 341 of file qgsgeometry.cpp.

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 525 of file qgsgeometry.cpp.

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 1385 of file qgsgeometry.cpp.

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 1837 of file qgsgeometry.cpp.

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 1850 of file qgsgeometry.cpp.

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 1864 of file qgsgeometry.cpp.

bool QgsGeometry::contains ( const QgsPoint p) const

Test for containment of a point (uses GEOS)

Definition at line 813 of file qgsgeometry.cpp.

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 825 of file qgsgeometry.cpp.

void QgsGeometry::convertPointList ( const QList< QgsPoint > &  input,
QgsPointSequenceV2 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 1748 of file qgsgeometry.cpp.

void QgsGeometry::convertPointList ( const QgsPointSequenceV2 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 1758 of file qgsgeometry.cpp.

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 938 of file qgsgeometry.cpp.

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 964 of file qgsgeometry.cpp.

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 1608 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::convertToType ( QGis::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 920 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::convexHull ( ) const

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

Definition at line 1342 of file qgsgeometry.cpp.

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

Creates and returns a new geometry engine.

Definition at line 2305 of file qgsgeometry.cpp.

QgsPolygon QgsGeometry::createPolygonFromQPolygonF ( const QPolygonF polygon)
static

Creates a QgsPolygon from a QPolygonF.

Parameters
polygonsource polygon
Returns
QgsPolygon
See also
createPolylineFromQPolygonF

Definition at line 1819 of file qgsgeometry.cpp.

QgsPolyline QgsGeometry::createPolylineFromQPolygonF ( const QPolygonF polygon)
static

Creates a QgsPolyline from a QPolygonF.

Parameters
polygonsource polygon
Returns
QgsPolyline
See also
createPolygonFromQPolygonF

Definition at line 1826 of file qgsgeometry.cpp.

bool QgsGeometry::crosses ( const QgsGeometry geometry) const

Test for if geometry crosses another (uses GEOS)

Note
added in 1.5

Definition at line 891 of file qgsgeometry.cpp.

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 1516 of file qgsgeometry.cpp.

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 1504 of file qgsgeometry.cpp.

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 423 of file qgsgeometry.cpp.

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 1402 of file qgsgeometry.cpp.

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 836 of file qgsgeometry.cpp.

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 1233 of file qgsgeometry.cpp.

void QgsGeometry::draw ( QPainter p) const

Draws the geometry onto a QPainter.

Parameters
pdestination QPainter
Note
added in QGIS 2.10

Definition at line 1679 of file qgsgeometry.cpp.

bool QgsGeometry::equals ( const QgsGeometry geometry) const

Test for if geometry equals another (uses GEOS)

Note
added in 1.5

Definition at line 847 of file qgsgeometry.cpp.

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 911 of file qgsgeometry.cpp.

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 902 of file qgsgeometry.cpp.

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

Returns an extruded version of this geometry.

Definition at line 1436 of file qgsgeometry.cpp.

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 333 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromMultiPoint ( const QgsMultiPoint multipoint)
static

Creates a new geometry from a QgsMultiPoint object.

Definition at line 191 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromMultiPolygon ( const QgsMultiPolygon multipoly)
static

Creates a new geometry from a QgsMultiPolygon.

Definition at line 211 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromMultiPolyline ( const QgsMultiPolyline multiline)
static

Creates a new geometry from a QgsMultiPolyline object.

Definition at line 201 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromPoint ( const QgsPoint point)
static

Creates a new geometry from a QgsPoint object.

Definition at line 161 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromPolygon ( const QgsPolygon polygon)
static

Creates a new geometry from a QgsPolygon.

Definition at line 181 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromPolyline ( const QgsPolyline polyline)
static

Creates a new geometry from a QgsPolyline object.

Definition at line 171 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromQPointF ( QPointF  point)
static

Construct geometry from a QPointF.

Parameters
pointsource QPointF
Note
added in QGIS 2.7

Definition at line 1802 of file qgsgeometry.cpp.

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 1807 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::fromRect ( const QgsRectangle rect)
static

Creates a new geometry from a QgsRectangle.

Definition at line 221 of file qgsgeometry.cpp.

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.

Definition at line 236 of file qgsgeometry.cpp.

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

Creates a new geometry from a WKT string.

Definition at line 151 of file qgsgeometry.cpp.

QgsAbstractGeometryV2 * QgsGeometry::geometry ( ) const

Returns the underlying geometry store.

Note
added in QGIS 2.10
See also
setGeometry

Definition at line 128 of file qgsgeometry.cpp.

GEOSContextHandle_t QgsGeometry::getGEOSHandler ( )
static

Return GEOS context handle.

Note
added in 2.6
not available in Python

Definition at line 1797 of file qgsgeometry.cpp.

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 461 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::interpolate ( double  distance) const

Return interpolated point on line at distance.

Note
added in 1.9

Definition at line 1357 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::intersection ( const QgsGeometry geometry) const

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

Definition at line 1372 of file qgsgeometry.cpp.

bool QgsGeometry::intersects ( const QgsRectangle r) const

Test for intersection with a rectangle (uses GEOS)

Definition at line 794 of file qgsgeometry.cpp.

bool QgsGeometry::intersects ( const QgsGeometry geometry) const

Test for intersection with a geometry (uses GEOS)

Definition at line 802 of file qgsgeometry.cpp.

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 146 of file qgsgeometry.cpp.

bool QgsGeometry::isGeosEmpty ( ) const

Check if the geometry is empty using GEOS.

Note
added in 1.5

Definition at line 1579 of file qgsgeometry.cpp.

bool QgsGeometry::isGeosEqual ( const QgsGeometry g) const

Compares the geometry with another geometry using GEOS.

Note
added in 1.5

Definition at line 1568 of file qgsgeometry.cpp.

bool QgsGeometry::isGeosValid ( ) const

Checks validity of the geometry using GEOS.

Note
added in 1.5

Definition at line 1557 of file qgsgeometry.cpp.

bool QgsGeometry::isMultipart ( ) const

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

Definition at line 324 of file qgsgeometry.cpp.

double QgsGeometry::length ( ) const

Returns the length of geometry using GEOS.

Note
added in 1.5

Definition at line 1223 of file qgsgeometry.cpp.

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 762 of file qgsgeometry.cpp.

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 1658 of file qgsgeometry.cpp.

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 385 of file qgsgeometry.cpp.

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 404 of file qgsgeometry.cpp.

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 513 of file qgsgeometry.cpp.

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

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

See buffer() method for details on parameters.

Note
added in 2.4
needs GEOS >= 3.3 - otherwise always returns 0

Definition at line 1276 of file qgsgeometry.cpp.

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

Assignments will prompt a deep copy of the object.

Note
not available in python bindings

Definition at line 87 of file qgsgeometry.cpp.

bool QgsGeometry::overlaps ( const QgsGeometry geometry) const

Test for if geometry overlaps another (uses GEOS)

Note
added in 1.5

Definition at line 869 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::pointOnSurface ( ) const

Returns a point within a geometry.

Definition at line 1325 of file qgsgeometry.cpp.

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 1622 of file qgsgeometry.cpp.

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 736 of file qgsgeometry.cpp.

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 684 of file qgsgeometry.cpp.

void QgsGeometry::setGeometry ( QgsAbstractGeometryV2 geometry)

Sets the underlying geometry store.

Ownership of geometry is transferred.

Note
added in QGIS 2.10
See also
geometry

Definition at line 133 of file qgsgeometry.cpp.

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 519 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::simplify ( double  tolerance) const

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

Definition at line 1292 of file qgsgeometry.cpp.

QgsGeometry * QgsGeometry::smooth ( const unsigned int  iterations = 1,
const double  offset = 0.25 
) 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.
Note
added in 2.9

Definition at line 1877 of file qgsgeometry.cpp.

QgsPolyline QgsGeometry::smoothLine ( const QgsPolyline polyline,
const unsigned int  iterations = 1,
const double  offset = 0.25 
) const

Smooths a polyline using the Chaikin algorithm.

Definition at line 1941 of file qgsgeometry.cpp.

QgsPolygon QgsGeometry::smoothPolygon ( const QgsPolygon polygon,
const unsigned int  iterations = 1,
const double  offset = 0.25 
) const

Smooths a polygon using the Chaikin algorithm.

Definition at line 1960 of file qgsgeometry.cpp.

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 701 of file qgsgeometry.cpp.

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 507 of file qgsgeometry.cpp.

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 1419 of file qgsgeometry.cpp.

bool QgsGeometry::touches ( const QgsGeometry geometry) const

Test for if geometry touch another (uses GEOS)

Note
added in 1.5

Definition at line 858 of file qgsgeometry.cpp.

int QgsGeometry::transform ( const QgsCoordinateTransform ct)

Transform this geometry as described by CoordinateTransform ct.

Returns
0 in case of success

Definition at line 1632 of file qgsgeometry.cpp.

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 1645 of file qgsgeometry.cpp.

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

Translate this geometry by dx, dy.

Returns
0 in case of success

Definition at line 670 of file qgsgeometry.cpp.

QGis::GeometryType QgsGeometry::type ( ) const

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

See also
wkbType

Definition at line 315 of file qgsgeometry.cpp.

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 null

Definition at line 1590 of file qgsgeometry.cpp.

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 1552 of file qgsgeometry.cpp.

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 490 of file qgsgeometry.cpp.

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 1687 of file qgsgeometry.cpp.

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 1719 of file qgsgeometry.cpp.

bool QgsGeometry::within ( const QgsGeometry geometry) const

Test for if geometry is within another (uses GEOS)

Note
added in 1.5

Definition at line 880 of file qgsgeometry.cpp.

int QgsGeometry::wkbSize ( ) const

Returns the size of the WKB in asWkb().

See also
asWkb

Definition at line 273 of file qgsgeometry.cpp.

QGis::WkbType QgsGeometry::wkbType ( ) const

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

See also
type

Definition at line 302 of file qgsgeometry.cpp.


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