QGIS API Documentation
2.6.0-Brighton
|
#include <qgsgeometry.h>
Classes | |
class | Error |
Public Member Functions | |
QgsGeometry () | |
Constructor. | |
QgsGeometry (const QgsGeometry &) | |
copy constructor will prompt a deep copy of the object | |
QgsGeometry & | operator= (QgsGeometry const &rhs) |
assignments will prompt a deep copy of the object | |
~QgsGeometry () | |
Destructor. | |
void | fromGeos (GEOSGeometry *geos) |
Set the geometry, feeding in a geometry in GEOS format. | |
void | fromWkb (unsigned char *wkb, size_t length) |
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length. | |
const unsigned char * | asWkb () const |
Returns the buffer containing this geometry in WKB format. | |
size_t | wkbSize () const |
Returns the size of the WKB in asWkb(). | |
const GEOSGeometry * | asGeos () const |
Returns a geos geomtry. | |
QGis::WkbType | wkbType () const |
Returns type of wkb (point / linestring / polygon etc.) | |
QGis::GeometryType | type () |
Returns type of the vector. | |
bool | isMultipart () |
Returns true if wkb of the geometry is of WKBMulti* type. | |
bool | isGeosEqual (QgsGeometry &) |
compare geometries using GEOS | |
bool | isGeosValid () |
check validity using GEOS | |
bool | isGeosEmpty () |
check if geometry is empty using GEOS | |
double | area () |
get area of geometry using GEOS | |
double | length () |
get length of geometry using GEOS | |
double | distance (QgsGeometry &geom) |
QgsPoint | closestVertex (const QgsPoint &point, int &atVertex, int &beforeVertex, int &afterVertex, double &sqrDist) |
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. | |
void | adjacentVertices (int atVertex, int &beforeVertex, int &afterVertex) |
Returns the indexes of the vertices before and after the given vertex index. | |
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. | |
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. | |
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. | |
QgsPoint | vertexAt (int atVertex) |
Returns coordinates of a vertex. | |
double | sqrDistToVertexAt (QgsPoint &point, int atVertex) |
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)) | |
double | closestVertexWithContext (const QgsPoint &point, int &atVertex) |
Searches for the closest vertex in this geometry to the given point. | |
double | closestSegmentWithContext (const QgsPoint &point, QgsPoint &minDistPoint, int &afterVertex, double *leftOf=0, double epsilon=DEFAULT_SEGMENT_EPSILON) |
Searches for the closest segment of geometry to the given point. | |
int | addRing (const QList< QgsPoint > &ring) |
Adds a new ring to this geometry. | |
int | addPart (const QList< QgsPoint > &points, QGis::GeometryType geomType=QGis::UnknownGeometry) |
Adds a new island polygon to a multipolygon feature. | |
int | addPart (GEOSGeometry *newPart) |
Adds a new island polygon to a multipolygon feature. | |
int | addPart (QgsGeometry *newPart) |
Adds a new island polygon to a multipolygon feature. | |
int | translate (double dx, double dy) |
Translate this geometry by dx, dy. | |
int | transform (const QgsCoordinateTransform &ct) |
Transform this geometry as described by CoordinateTranasform ct. | |
int | splitGeometry (const QList< QgsPoint > &splitLine, QList< QgsGeometry * > &newGeometries, bool topological, QList< QgsPoint > &topologyTestPoints) |
Splits this geometry according to a given line. | |
int | reshapeGeometry (const QList< QgsPoint > &reshapeWithLine) |
Replaces a part of this geometry with another line. | |
int | makeDifference (QgsGeometry *other) |
Changes this geometry such that it does not intersect the other geometry. | |
QgsRectangle | boundingBox () |
Returns the bounding box of this feature. | |
bool | intersects (const QgsRectangle &r) const |
Test for intersection with a rectangle (uses GEOS) | |
bool | intersects (const QgsGeometry *geometry) const |
Test for intersection with a geometry (uses GEOS) | |
bool | contains (const QgsPoint *p) const |
Test for containment of a point (uses GEOS) | |
bool | contains (const QgsGeometry *geometry) const |
Test for if geometry is contained in another (uses GEOS) | |
bool | disjoint (const QgsGeometry *geometry) const |
Test for if geometry is disjoint of another (uses GEOS) | |
bool | equals (const QgsGeometry *geometry) const |
Test for if geometry equals another (uses GEOS) | |
bool | touches (const QgsGeometry *geometry) const |
Test for if geometry touch another (uses GEOS) | |
bool | overlaps (const QgsGeometry *geometry) const |
Test for if geometry overlaps another (uses GEOS) | |
bool | within (const QgsGeometry *geometry) const |
Test for if geometry is within another (uses GEOS) | |
bool | crosses (const QgsGeometry *geometry) const |
Test for if geometry crosses another (uses GEOS) | |
QgsGeometry * | buffer (double distance, int segments) |
Returns a buffer region around this geometry having the given width and with a specified number of segments used to approximate curves. | |
QgsGeometry * | buffer (double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit) |
Returns a buffer region around the geometry, with additional style options. | |
QgsGeometry * | offsetCurve (double distance, int segments, int joinStyle, double mitreLimit) |
Returns an offset line at a given distance and side from an input line. | |
QgsGeometry * | simplify (double tolerance) |
Returns a simplified version of this geometry using a specified tolerance value. | |
QgsGeometry * | centroid () |
Returns the center of mass of a geometry. | |
QgsGeometry * | pointOnSurface () |
Returns a point within a geometry. | |
QgsGeometry * | convexHull () |
Returns the smallest convex polygon that contains all the points in the geometry. | |
QgsGeometry * | interpolate (double distance) |
QgsGeometry * | intersection (QgsGeometry *geometry) |
Returns a geometry representing the points shared by this geometry and other. | |
QgsGeometry * | combine (QgsGeometry *geometry) |
Returns a geometry representing all the points in this geometry and other (a union geometry operation). | |
QgsGeometry * | difference (QgsGeometry *geometry) |
Returns a geometry representing the points making up this geometry that do not make up other. | |
QgsGeometry * | symDifference (QgsGeometry *geometry) |
Returns a Geometry representing the points making up this Geometry that do not make up other. | |
QString | exportToWkt (const int &precision=17) const |
Exports the geometry to WKT. | |
QString | exportToGeoJSON (const int &precision=17) const |
Exports the geometry to GeoJSON. | |
QgsGeometry * | convertToType (QGis::GeometryType destType, bool destMultipart=false) |
try to convert the geometry to the requested type | |
QgsPoint | asPoint () const |
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0,0] | |
QgsPolyline | asPolyline () const |
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list | |
QgsPolygon | asPolygon () const |
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list | |
QgsMultiPoint | asMultiPoint () const |
return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list | |
QgsMultiPolyline | asMultiPolyline () const |
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list | |
QgsMultiPolygon | asMultiPolygon () const |
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list | |
QList< QgsGeometry * > | asGeometryCollection () const |
return contents of the geometry as a list of geometries | |
bool | deleteRing (int ringNum, int partNum=0) |
delete a ring in polygon or multipolygon. | |
bool | deletePart (int partNum) |
delete part identified by the part number | |
bool | convertToMultiType () |
Converts single type geometry into multitype geometry e.g. | |
int | avoidIntersections (QMap< QgsVectorLayer *, QSet< QgsFeatureId > > ignoreFeatures=(QMap< QgsVectorLayer *, QSet< QgsFeatureId > >())) |
Modifies geometry to avoid intersections with the layers specified in project properties. | |
void | validateGeometry (QList< Error > &errors) |
Validate geometry and produce a list of geometry errors. |
Static Public Member Functions | |
static GEOSContextHandle_t | getGEOSHandler () |
return GEOS context handle | |
static QgsGeometry * | fromWkt (QString wkt) |
static method that creates geometry from Wkt | |
static QgsGeometry * | fromPoint (const QgsPoint &point) |
construct geometry from a point | |
static QgsGeometry * | fromMultiPoint (const QgsMultiPoint &multipoint) |
construct geometry from a multipoint | |
static QgsGeometry * | fromPolyline (const QgsPolyline &polyline) |
construct geometry from a polyline | |
static QgsGeometry * | fromMultiPolyline (const QgsMultiPolyline &multiline) |
construct geometry from a multipolyline | |
static QgsGeometry * | fromPolygon (const QgsPolygon &polygon) |
construct geometry from a polygon | |
static QgsGeometry * | fromMultiPolygon (const QgsMultiPolygon &multipoly) |
construct geometry from a multipolygon | |
static QgsGeometry * | fromRect (const QgsRectangle &rect) |
construct geometry from a rectangle | |
static QgsGeometry * | unaryUnion (const QList< QgsGeometry * > &geometryList) |
compute the unary union on a list of geometries. |
QgsGeometry::QgsGeometry | ( | ) |
Constructor.
QgsGeometry::QgsGeometry | ( | const QgsGeometry & | rhs | ) |
copy constructor will prompt a deep copy of the object
QgsGeometry::~QgsGeometry | ( | ) |
Destructor.
int QgsGeometry::addPart | ( | const QList< QgsPoint > & | points, |
QGis::GeometryType | geomType = QGis::UnknownGeometry |
||
) |
Adds a new island polygon to a multipolygon feature.
int QgsGeometry::addPart | ( | GEOSGeometry * | newPart | ) |
Adds a new island polygon to a multipolygon feature.
int QgsGeometry::addPart | ( | QgsGeometry * | newPart | ) |
Adds a new island polygon to a multipolygon feature.
int QgsGeometry::addRing | ( | const QList< QgsPoint > & | ring | ) |
Adds a new ring to this geometry.
This makes only sense for polygon and multipolygons.
void QgsGeometry::adjacentVertices | ( | int | atVertex, |
int & | beforeVertex, | ||
int & | afterVertex | ||
) |
Returns the indexes of the vertices before and after the given vertex index.
This function takes into account the following factors:
double QgsGeometry::area | ( | ) |
get area of geometry using GEOS
QList< QgsGeometry * > QgsGeometry::asGeometryCollection | ( | ) | const |
return contents of the geometry as a list of geometries
const GEOSGeometry * QgsGeometry::asGeos | ( | ) | const |
Returns a geos geomtry.
QgsGeometry keeps ownership, don't delete the returned object!
QgsMultiPoint QgsGeometry::asMultiPoint | ( | ) | const |
return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list
QgsMultiPolygon QgsGeometry::asMultiPolygon | ( | ) | const |
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list
QgsMultiPolyline QgsGeometry::asMultiPolyline | ( | ) | const |
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
QgsPoint QgsGeometry::asPoint | ( | ) | const |
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0,0]
QgsPolygon QgsGeometry::asPolygon | ( | ) | const |
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list
QgsPolyline QgsGeometry::asPolyline | ( | ) | const |
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list
const unsigned char * QgsGeometry::asWkb | ( | ) | const |
Returns the buffer containing this geometry in WKB format.
You may wish to use in conjunction with wkbSize().
int QgsGeometry::avoidIntersections | ( | QMap< QgsVectorLayer *, QSet< QgsFeatureId > > | ignoreFeatures = ( QMap<QgsVectorLayer*, QSet<QgsFeatureId> >() ) | ) |
Modifies geometry to avoid intersections with the layers specified in project properties.
ignoreFeatures | possibility to give a list of features where intersections should be ignored (not available in python bindings) |
QgsRectangle QgsGeometry::boundingBox | ( | ) |
Returns the bounding box of this feature.
QgsGeometry * QgsGeometry::buffer | ( | double | distance, |
int | segments | ||
) |
Returns a buffer region around this geometry having the given width and with a specified number of segments used to approximate curves.
QgsGeometry * QgsGeometry::buffer | ( | double | distance, |
int | segments, | ||
int | endCapStyle, | ||
int | joinStyle, | ||
double | mitreLimit | ||
) |
Returns a buffer region around the geometry, with additional style options.
distance | buffer distance |
segments | For round joins, number of segments to approximate quarter-circle |
endCapStyle | Round (1) / Flat (2) / Square (3) end cap style |
joinStyle | Round (1) / Mitre (2) / Bevel (3) join style |
mitreLimit | Limit on the mitre ratio used for very sharp corners |
QgsGeometry * QgsGeometry::centroid | ( | ) |
Returns the center of mass of a geometry.
double QgsGeometry::closestSegmentWithContext | ( | const QgsPoint & | point, |
QgsPoint & | minDistPoint, | ||
int & | afterVertex, | ||
double * | leftOf = 0 , |
||
double | epsilon = DEFAULT_SEGMENT_EPSILON |
||
) |
Searches for the closest segment of geometry to the given point.
point | Specifies the point for search |
minDistPoint | Receives the nearest point on the segment |
afterVertex | Receives index of the vertex after the closest segment. The vertex before the closest segment is always afterVertex - 1 |
leftOf | Out: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right ) |
epsilon | epsilon for segment snapping |
QgsPoint QgsGeometry::closestVertex | ( | const QgsPoint & | point, |
int & | atVertex, | ||
int & | beforeVertex, | ||
int & | afterVertex, | ||
double & | sqrDist | ||
) |
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
double QgsGeometry::closestVertexWithContext | ( | const QgsPoint & | point, |
int & | atVertex | ||
) |
Searches for the closest vertex in this geometry to the given point.
point | Specifiest the point for search |
atVertex | Receives index of the closest vertex |
QgsGeometry * QgsGeometry::combine | ( | QgsGeometry * | geometry | ) |
Returns a geometry representing all the points in this geometry and other (a union geometry operation).
bool QgsGeometry::contains | ( | const QgsPoint * | p | ) | const |
Test for containment of a point (uses GEOS)
bool QgsGeometry::contains | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry is contained in another (uses GEOS)
bool QgsGeometry::convertToMultiType | ( | ) |
Converts single type geometry into multitype geometry e.g.
a polygon into a multipolygon geometry with one polygon
QgsGeometry * QgsGeometry::convertToType | ( | QGis::GeometryType | destType, |
bool | destMultipart = false |
||
) |
try to convert the geometry to the requested type
destType | the geometry type to be converted to |
destMultipart | determines if the output geometry will be multipart or not |
QgsGeometry * QgsGeometry::convexHull | ( | ) |
Returns the smallest convex polygon that contains all the points in the geometry.
bool QgsGeometry::crosses | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry crosses another (uses GEOS)
bool QgsGeometry::deletePart | ( | int | partNum | ) |
delete part identified by the part number
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.
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?)
QgsGeometry * QgsGeometry::difference | ( | QgsGeometry * | geometry | ) |
Returns a geometry representing the points making up this geometry that do not make up other.
bool QgsGeometry::disjoint | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry is disjoint of another (uses GEOS)
double QgsGeometry::distance | ( | QgsGeometry & | geom | ) |
bool QgsGeometry::equals | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry equals another (uses GEOS)
QString QgsGeometry::exportToGeoJSON | ( | const int & | precision = 17 | ) | const |
Exports the geometry to GeoJSON.
QString QgsGeometry::exportToWkt | ( | const int & | precision = 17 | ) | const |
Exports the geometry to WKT.
void QgsGeometry::fromGeos | ( | GEOSGeometry * | geos | ) |
Set the geometry, feeding in a geometry in GEOS format.
This class will take ownership of the buffer.
|
static |
construct geometry from a multipoint
|
static |
construct geometry from a multipolygon
|
static |
construct geometry from a multipolyline
|
static |
construct geometry from a point
|
static |
construct geometry from a polygon
|
static |
construct geometry from a polyline
|
static |
construct geometry from a rectangle
void QgsGeometry::fromWkb | ( | unsigned char * | wkb, |
size_t | 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.
|
static |
static method that creates geometry from Wkt
|
static |
return GEOS context handle
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?)
QgsGeometry * QgsGeometry::interpolate | ( | double | distance | ) |
QgsGeometry * QgsGeometry::intersection | ( | QgsGeometry * | geometry | ) |
Returns a geometry representing the points shared by this geometry and other.
bool QgsGeometry::intersects | ( | const QgsRectangle & | r | ) | const |
Test for intersection with a rectangle (uses GEOS)
bool QgsGeometry::intersects | ( | const QgsGeometry * | geometry | ) | const |
Test for intersection with a geometry (uses GEOS)
bool QgsGeometry::isGeosEmpty | ( | ) |
check if geometry is empty using GEOS
bool QgsGeometry::isGeosEqual | ( | QgsGeometry & | g | ) |
compare geometries using GEOS
bool QgsGeometry::isGeosValid | ( | ) |
check validity using GEOS
bool QgsGeometry::isMultipart | ( | ) |
Returns true if wkb of the geometry is of WKBMulti* type.
double QgsGeometry::length | ( | ) |
get length of geometry using GEOS
int QgsGeometry::makeDifference | ( | QgsGeometry * | other | ) |
Changes this geometry such that it does not intersect the other geometry.
other | geometry that should not be intersect |
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
QgsGeometry * QgsGeometry::offsetCurve | ( | double | distance, |
int | segments, | ||
int | joinStyle, | ||
double | mitreLimit | ||
) |
Returns an offset line at a given distance and side from an input line.
See buffer() method for details on parameters.
QgsGeometry & QgsGeometry::operator= | ( | QgsGeometry const & | rhs | ) |
assignments will prompt a deep copy of the object
bool QgsGeometry::overlaps | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry overlaps another (uses GEOS)
QgsGeometry * QgsGeometry::pointOnSurface | ( | ) |
Returns a point within a geometry.
int QgsGeometry::reshapeGeometry | ( | const QList< QgsPoint > & | reshapeWithLine | ) |
Replaces a part of this geometry with another line.
QgsGeometry * QgsGeometry::simplify | ( | double | tolerance | ) |
Returns a simplified version of this geometry using a specified tolerance value.
int QgsGeometry::splitGeometry | ( | const QList< QgsPoint > & | splitLine, |
QList< QgsGeometry * > & | newGeometries, | ||
bool | topological, | ||
QList< QgsPoint > & | topologyTestPoints | ||
) |
Splits this geometry according to a given line.
Note that the geometry is only split once. If there are several intersections between geometry and splitLine, only the first one is considered.
splitLine | the line that splits the geometry | |
[out] | newGeometries | list of new geometries that have been created with the split |
topological | true if topological editing is enabled | |
[out] | topologyTestPoints | points that need to be tested for topological completeness in the dataset |
double QgsGeometry::sqrDistToVertexAt | ( | QgsPoint & | point, |
int | atVertex | ||
) |
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))
QgsGeometry * QgsGeometry::symDifference | ( | QgsGeometry * | geometry | ) |
Returns a Geometry representing the points making up this Geometry that do not make up other.
bool QgsGeometry::touches | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry touch another (uses GEOS)
int QgsGeometry::transform | ( | const QgsCoordinateTransform & | ct | ) |
Transform this geometry as described by CoordinateTranasform ct.
int QgsGeometry::translate | ( | double | dx, |
double | dy | ||
) |
Translate this geometry by dx, dy.
QGis::GeometryType QgsGeometry::type | ( | ) |
Returns type of the vector.
|
static |
compute the unary union on a list of geometries.
May be faster than an iterative union on a set of geometries.
geometryList | a list of QgsGeometry* as input |
void QgsGeometry::validateGeometry | ( | QList< Error > & | errors | ) |
Validate geometry and produce a list of geometry errors.
QgsPoint QgsGeometry::vertexAt | ( | int | atVertex | ) |
Returns coordinates of a vertex.
atVertex | index of the vertex |
bool QgsGeometry::within | ( | const QgsGeometry * | geometry | ) | const |
Test for if geometry is within another (uses GEOS)
size_t QgsGeometry::wkbSize | ( | ) | const |
Returns the size of the WKB in asWkb().
QGis::WkbType QgsGeometry::wkbType | ( | ) | const |
Returns type of wkb (point / linestring / polygon etc.)