QGIS API Documentation  master-6227475
QgsGeometry Class Reference

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

#include <qgsgeometry.h>

List of all members.

Classes

class  Error

Public Member Functions

 QgsGeometry ()
 Constructor.
 QgsGeometry (const QgsGeometry &)
 copy constructor will prompt a deep copy of the object
 ~QgsGeometry ()
 Destructor.
int addPart (const QList< QgsPoint > &points)
 Adds a new island polygon to a multipolygon feature.
int addRing (const QList< QgsPoint > &ring)
 Adds a new ring to this geometry.
void adjacentVertices (int atVertex, int &beforeVertex, int &afterVertex)
 Returns the indexes of the vertices before and after the given vertex index.
double area ()
 get area of geometry using GEOS
QList< QgsGeometry * > asGeometryCollection ()
 return contents of the geometry as a list of geometries
GEOSGeometry * asGeos ()
 Returns a geos geomtry.
QgsMultiPoint asMultiPoint ()
 return contents of the geometry as a multi point if wkbType is WKBMultiPoint, otherwise an empty list
QgsMultiPolygon asMultiPolygon ()
 return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list
QgsMultiPolyline asMultiPolyline ()
 return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
QgsPoint asPoint ()
 return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0,0]
QgsPolygon asPolygon ()
 return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list
QgsPolyline asPolyline ()
 return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list
unsigned char * asWkb ()
 Returns the buffer containing this geometry in WKB format.
int avoidIntersections (QMap< QgsVectorLayer *, QSet< QgsFeatureId > > ignoreFeatures=(QMap< QgsVectorLayer *, QSet< QgsFeatureId > >()))
 Modifies geometry to avoid intersections with the layers specified in project properties.
QgsRectangle boundingBox ()
 Returns the bounding box of this feature.
QgsGeometrybuffer (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.
QgsGeometrycentroid ()
 Returns the center of mass of a geometry.
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.
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.
double closestVertexWithContext (const QgsPoint &point, int &atVertex)
 Searches for the closest vertex in this geometry to the given point.
QgsGeometrycombine (QgsGeometry *geometry)
 Returns a geometry representing all the points in this geometry and other (a union geometry operation).
bool contains (QgsPoint *p)
 Test for containment of a point (uses GEOS)
bool contains (QgsGeometry *geometry)
 Test for if geometry is contained in an other (uses GEOS)
bool convertToMultiType ()
 Converts single type geometry into multitype geometry e.g.
QgsGeometryconvexHull ()
 Returns the smallest convex polygon that contains all the points in the geometry.
bool crosses (QgsGeometry *geometry)
 Test for if geometry crosses an other (uses GEOS)
bool deletePart (int partNum)
 delete part identified by the part number
bool deleteRing (int ringNum, int partNum=0)
 delete a ring in polygon or multipolygon.
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.
QgsGeometrydifference (QgsGeometry *geometry)
 Returns a geometry representing the points making up this geometry that do not make up other.
bool disjoint (QgsGeometry *geometry)
 Test for if geometry is disjoint of an other (uses GEOS)
double distance (QgsGeometry &geom)
bool equals (QgsGeometry *geometry)
 Test for if geometry equals an other (uses GEOS)
QString exportToGeoJSON ()
 Exports the geometry to mGeoJSON.
QString exportToWkt ()
 Exports the geometry to mWkt.
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.
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.
QgsGeometryinterpolate (double distance)
QgsGeometryintersection (QgsGeometry *geometry)
 Returns a geometry representing the points shared by this geometry and other.
bool intersects (const QgsRectangle &r)
 Test for intersection with a rectangle (uses GEOS)
bool intersects (QgsGeometry *geometry)
 Test for intersection with a geometry (uses GEOS)
bool isGeosEmpty ()
 check if geometry is empty using GEOS
bool isGeosEqual (QgsGeometry &)
 compare geometries using GEOS
bool isGeosValid ()
 check validity using GEOS
bool isMultipart ()
 Returns true if wkb of the geometry is of WKBMulti* type.
double length ()
 get length of geometry using GEOS
int makeDifference (QgsGeometry *other)
 Changes this geometry such that it does not intersect the other geometry.
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.
QgsGeometryoperator= (QgsGeometry const &rhs)
 assignments will prompt a deep copy of the object
bool overlaps (QgsGeometry *geometry)
 Test for if geometry overlaps an other (uses GEOS)
int reshapeGeometry (const QList< QgsPoint > &reshapeWithLine)
 Replaces a part of this geometry with another line.
QgsGeometrysimplify (double tolerance)
 Returns a simplified version of this geometry using a specified tolerance value.
int splitGeometry (const QList< QgsPoint > &splitLine, QList< QgsGeometry * > &newGeometries, bool topological, QList< QgsPoint > &topologyTestPoints)
 Splits this geometry according to a given line.
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))
QgsGeometrysymDifference (QgsGeometry *geometry)
 Returns a Geometry representing the points making up this Geometry that do not make up other.
bool touches (QgsGeometry *geometry)
 Test for if geometry touch an other (uses GEOS)
int transform (const QgsCoordinateTransform &ct)
 Transform this geometry as described by CoordinateTranasform ct.
int translate (double dx, double dy)
 Translate this geometry by dx, dy.
QGis::GeometryType type ()
 Returns type of the vector.
void validateGeometry (QList< Error > &errors)
 Validate geometry and produce a list of geometry errors.
QgsPoint vertexAt (int atVertex)
 Returns coordinates of a vertex.
bool within (QgsGeometry *geometry)
 Test for if geometry is within an other (uses GEOS)
size_t wkbSize ()
 Returns the size of the WKB in asWkb().
QGis::WkbType wkbType ()
 Returns type of wkb (point / linestring / polygon etc.)

Static Public Member Functions

static QgsGeometryfromMultiPoint (const QgsMultiPoint &multipoint)
 construct geometry from a multipoint
static QgsGeometryfromMultiPolygon (const QgsMultiPolygon &multipoly)
 construct geometry from a multipolygon
static QgsGeometryfromMultiPolyline (const QgsMultiPolyline &multiline)
 construct geometry from a multipolyline
static QgsGeometryfromPoint (const QgsPoint &point)
 construct geometry from a point
static QgsGeometryfromPolygon (const QgsPolygon &polygon)
 construct geometry from a polygon
static QgsGeometryfromPolyline (const QgsPolyline &polyline)
 construct geometry from a polyline
static QgsGeometryfromRect (const QgsRectangle &rect)
 construct geometry from a rectangle
static QgsGeometryfromWkt (QString wkt)
 static method that creates geometry from Wkt

Private Member Functions

QgsPoint asPoint (unsigned char *&ptr, bool hasZValue)
 return point from wkb
QgsPolygon asPolygon (unsigned char *&ptr, bool hasZValue)
 return polygon from wkb
QgsPolyline asPolyline (unsigned char *&ptr, bool hasZValue)
 return polyline from wkb
bool exportGeosToWkb ()
 Converts from the GEOS geometry to the WKB geometry.
bool exportWkbToGeos ()
 Converts from the WKB geometry to the GEOS geometry.
bool insertVertex (double x, double y, int beforeVertex, const GEOSCoordSequence *old_sequence, GEOSCoordSequence **new_sequence)
 Insert a new vertex before the given vertex index (first number is index 0) in the given GEOS Coordinate Sequence.
double leftOf (double x, double y, double &x1, double &y1, double &x2, double &y2)
 Returns < 0 if point(x/y) is left of the line x1,y1 -> x1,y2.
int mergeGeometriesMultiTypeSplit (QVector< GEOSGeometry * > &splitResult)
int numberOfGeometries (GEOSGeometry *g) const
 Returns number of single geometry in a geos geometry.
int splitLinearGeometry (GEOSGeometry *splitLine, QList< QgsGeometry * > &newGeometries)
 Splits line/multiline geometries.
int splitPolygonGeometry (GEOSGeometry *splitLine, QList< QgsGeometry * > &newGeometries)
 Splits polygon/multipolygon geometries.
int topologicalTestPointsSplit (const GEOSGeometry *splitLine, QList< QgsPoint > &testPoints) const
 Finds out the points that need to be tested for topological correctnes if this geometry will be split.
void transformVertex (int &wkbPosition, const QgsCoordinateTransform &ct, bool hasZValue)
 Transforms a single vertex by ct.
void translateVertex (int &wkbPosition, double dx, double dy, bool hasZValue)
 Translates a single vertex by dx and dy.

Static Private Member Functions

static bool geomInDegrees (const GEOSGeometry *geom)
 Tests if geom bounding rect is within -180 <= x <= 180, -90 <= y <= 90.
static bool geosRelOp (char(*op)(const GEOSGeometry *, const GEOSGeometry *), QgsGeometry *a, QgsGeometry *b)
static int lineContainedInLine (const GEOSGeometry *line1, const GEOSGeometry *line2)
 Tests if line1 is completely contained in line2.
static GEOSGeometry * nodeGeometries (const GEOSGeometry *splitLine, const GEOSGeometry *poly)
 Nodes together a split line and a (multi-) polygon geometry in a multilinestring.
static int pointContainedInLine (const GEOSGeometry *point, const GEOSGeometry *line)
 Tests if a point is on a line.
static GEOSGeometry * reshapeLine (const GEOSGeometry *origLine, const GEOSGeometry *reshapeLineGeos)
 Creates a new line from an original line and a reshape line.
static GEOSGeometry * reshapePolygon (const GEOSGeometry *polygon, const GEOSGeometry *reshapeLineGeos)
 Creates a new polygon replacing the part from the first to the second intersection with the reshape line.

Private Attributes

bool mDirtyGeos
 If the geometry has been set since the last conversion to GEOS.
bool mDirtyWkb
 If the geometry has been set since the last conversion to WKB.
unsigned char * mGeometry
 pointer to geometry in binary WKB format This is the class' native implementation
size_t mGeometrySize
 size of geometry
GEOSGeometry * mGeos
 cached GEOS version of this geometry

Detailed Description

A geometry is the spatial representation of a feature.

Represents a geometry with input and output in formats specified by (at least) the Open Geospatial Consortium (WKB / Wkt), and containing various functions for geoprocessing of the geometry.

The geometry is represented internally by the OGC WKB format or as GEOS geometry. Some functions use WKB for their work, others use GEOS.

TODO: migrate completely to GEOS and only support WKB/Wkt import/export.

Author:
Brendan Morley

Definition at line 72 of file qgsgeometry.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 191 of file qgsgeometry.cpp.

Referenced by asGeometryCollection(), and combine().

copy constructor will prompt a deep copy of the object

Definition at line 200 of file qgsgeometry.cpp.

References mGeometry, mGeometrySize, and mGeos.

Destructor.

Definition at line 224 of file qgsgeometry.cpp.

References mGeometry, and mGeos.


Member Function Documentation

int QgsGeometry::addPart ( const QList< QgsPoint > &  points)

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

Definition at line 2876 of file qgsgeometry.cpp.

References convertToMultiType(), createGeosCollection(), createGeosLinearRing(), createGeosLineString(), createGeosPoint(), createGeosPolygon(), exportWkbToGeos(), isMultipart(), QGis::Line, QgsMessageLog::logMessage(), mDirtyGeos, mDirtyWkb, mGeos, QGis::Point, QGis::Polygon, QgsDebugMsg, tr, type(), and GEOSException::what().

Referenced by QgsVectorLayerEditUtils::addPart().

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

References createGeosCollection(), createGeosLinearRing(), createGeosPolygon(), exportWkbToGeos(), QgsMessageLog::logMessage(), mDirtyGeos, mDirtyWkb, mGeos, QGis::Polygon, throwGEOSException(), tr, type(), GEOSException::what(), QGis::WKBMultiPolygon, QGis::WKBPolygon, and wkbType().

Referenced by QgsVectorLayerEditUtils::addRing().

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:

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

References exportGeosToWkb(), mDirtyWkb, mGeometry, QgsDebugMsg, QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPolygon, QGis::WKBPolygon25D, and wkbType().

double QgsGeometry::area ( )

get area of geometry using GEOS

Note:
added in 1.5

Definition at line 6334 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), mDirtyGeos, and mGeos.

Referenced by QgsPalLayerSettings::checkMinimumSizeMM(), and QgsZonalStatistics::statisticsFromPreciseIntersection().

return contents of the geometry as a list of geometries

Note:
added in version 1.1

Definition at line 6621 of file qgsgeometry.cpp.

References exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, mGeos, QgsDebugMsg, and QgsGeometry().

Referenced by QgsGeometryAnalyzer::addEventLayerFeature(), and QgsGeometryAnalyzer::createOffsetGeometry().

GEOSGeometry * QgsGeometry::asGeos ( )

Returns a geos geomtry.

QgsGeometry keeps ownership, don't delete the returned object!

Note:
this method was added in version 1.1
not available in python bindings

Definition at line 612 of file qgsgeometry.cpp.

References exportWkbToGeos(), mDirtyGeos, and mGeos.

Referenced by QgsPALGeometry::getGeosGeometry(), isGeosEmpty(), isGeosValid(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), QgsGeometryValidator::run(), and QgsZonalStatistics::statisticsFromMiddlePointTest().

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

Definition at line 6269 of file qgsgeometry.cpp.

References asPoint(), mGeometry, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, and wkbType().

Referenced by QgsRubberBand::addGeometry(), deletePart(), and QgsHighlight::paint().

QgsPoint QgsGeometry::asPoint ( unsigned char *&  ptr,
bool  hasZValue 
) [private]

return point from wkb

Definition at line 6156 of file qgsgeometry.cpp.

QgsPolygon QgsGeometry::asPolygon ( unsigned char *&  ptr,
bool  hasZValue 
) [private]

return polygon from wkb

Definition at line 6197 of file qgsgeometry.cpp.

QgsPolyline QgsGeometry::asPolyline ( unsigned char *&  ptr,
bool  hasZValue 
) [private]

return polyline from wkb

Definition at line 6170 of file qgsgeometry.cpp.

int QgsGeometry::avoidIntersections ( 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 6774 of file qgsgeometry.cpp.

References QgsMapLayerRegistry::instance(), QgsProject::instance(), QgsMapLayerRegistry::mapLayer(), QGis::Polygon, QgsProject::readListEntry(), QgsVectorLayer::removePolygonIntersections(), type(), and wkbType().

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.

Definition at line 6405 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by QgsGeometryAnalyzer::bufferFeature(), and fcnBuffer().

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

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by QgsGeometryAnalyzer::centroidFeature(), and fcnCentroid().

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.

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

References exportGeosToWkb(), leftOf(), MathUtils::max(), mDirtyWkb, mGeometry, QgsDebugMsg, QgsPoint::sqrDistToSegment(), QgsPoint::toString(), QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, wkbType(), QGis::WKBUnknown, QgsPoint::x(), and QgsPoint::y().

Referenced by QgsGeometryAnalyzer::createPointOffset(), and QgsVectorLayer::snapToGeometry().

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

Definition at line 716 of file qgsgeometry.cpp.

References exportGeosToWkb(), MathUtils::max(), mDirtyWkb, mGeometry, QgsDebugMsg, QgsPoint::sqrDist(), QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, and wkbType().

Referenced by QgsVectorLayer::snapToGeometry().

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

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

References exportWkbToGeos(), QgsMessageLog::logMessage(), MathUtils::max(), mDirtyGeos, mGeos, QgsPoint::sqrDist(), tr, and GEOSException::what().

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

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), QGis::Line, mDirtyGeos, mGeos, QgsGeometry(), and type().

Referenced by QgsGeometryAnalyzer::bufferFeature(), QgsGeometryAnalyzer::convexFeature(), QgsGeometryAnalyzer::dissolveFeature(), and fcnCombine().

Test for containment of a point (uses GEOS)

Definition at line 3872 of file qgsgeometry.cpp.

References createGeosPoint(), exportWkbToGeos(), QgsMessageLog::logMessage(), mGeos, QgsDebugMsg, tr, and GEOSException::what().

Referenced by fcnContains(), and QgsPalLayerSettings::registerFeature().

bool QgsGeometry::contains ( QgsGeometry geometry)

Test for if geometry is contained in an other (uses GEOS)

Note:
added in 1.5

Definition at line 3924 of file qgsgeometry.cpp.

References geosRelOp().

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

Definition at line 6457 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by QgsGeometryAnalyzer::convexFeature(), QgsGeometryAnalyzer::convexHull(), and fcnConvexHull().

bool QgsGeometry::crosses ( QgsGeometry geometry)

Test for if geometry crosses an other (uses GEOS)

Note:
added in 1.5

Definition at line 3954 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by fcnCrosses().

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

References asMultiPolygon(), asPolygon(), fromMultiPolygon(), fromPolygon(), QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPolygon, QGis::WKBPolygon25D, and wkbType().

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

References exportGeosToWkb(), mDirtyGeos, mDirtyWkb, mGeometry, mGeometrySize, QgsDebugMsg, QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBNoGeometry, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, wkbType(), and QGis::WKBUnknown.

Referenced by QgsVectorLayerEditUtils::deleteVertex().

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

Definition at line 6565 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by fcnDifference().

bool QgsGeometry::disjoint ( QgsGeometry geometry)

Test for if geometry is disjoint of an other (uses GEOS)

Note:
added in 1.5

Definition at line 3929 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by fcnDisjoint().

double QgsGeometry::distance ( QgsGeometry geom)

Definition at line 6379 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), mDirtyGeos, and mGeos.

Referenced by fcnDistance().

bool QgsGeometry::equals ( QgsGeometry geometry)

Test for if geometry equals an other (uses GEOS)

Note:
added in 1.5

Definition at line 3934 of file qgsgeometry.cpp.

References geosRelOp().

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

References mDirtyGeos, mDirtyWkb, mGeometry, and mGeos.

Referenced by QgsGeometryAnalyzer::createOffsetGeometry(), and fromGeosGeom().

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

construct geometry from a multipolygon

Definition at line 496 of file qgsgeometry.cpp.

References createGeosCollection(), createGeosPolygon(), fromGeosGeom(), QgsMessageLog::logMessage(), tr, and GEOSException::what().

Referenced by deletePart(), and deleteRing().

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

construct geometry from a point

Definition at line 435 of file qgsgeometry.cpp.

References createGeosPoint(), and fromGeosGeom().

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

construct geometry from a polygon

Definition at line 445 of file qgsgeometry.cpp.

References createGeosPolygon(), and fromGeosGeom().

Referenced by QgsRubberBand::asGeometry(), deleteRing(), and fromRect().

QgsGeometry * QgsGeometry::fromPolyline ( const QgsPolyline polyline) [static]
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.

Definition at line 570 of file qgsgeometry.cpp.

References length(), mDirtyGeos, mDirtyWkb, mGeometry, mGeometrySize, and mGeos.

Referenced by QgsOgcUtils::geometryFromGMLLineString(), QgsOgcUtils::geometryFromGMLMultiLineString(), QgsOgcUtils::geometryFromGMLMultiPoint(), QgsOgcUtils::geometryFromGMLMultiPolygon(), QgsOgcUtils::geometryFromGMLPoint(), QgsOgcUtils::geometryFromGMLPolygon(), and QgsFeature::setGeometryAndOwnership().

QgsGeometry * QgsGeometry::fromWkt ( QString  wkt) [static]

static method that creates geometry from Wkt

Definition at line 415 of file qgsgeometry.cpp.

References fromGeosGeom(), QgsMessageLog::logMessage(), tr, and GEOSException::what().

Referenced by QgsOfflineEditing::applyGeometryChanges(), QgsOgcUtils::expressionFunctionToOgcFilter(), and fcnGeomFromWKT().

bool QgsGeometry::geomInDegrees ( const GEOSGeometry *  geom) [static, private]

Tests if geom bounding rect is within -180 <= x <= 180, -90 <= y <= 90.

Other methods may use more accurate tolerances if this is true

Definition at line 6010 of file qgsgeometry.cpp.

Referenced by lineContainedInLine(), and pointContainedInLine().

bool QgsGeometry::geosRelOp ( char(*)(const GEOSGeometry *, const GEOSGeometry *)  op,
QgsGeometry a,
QgsGeometry b 
) [static, private]
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 1853 of file qgsgeometry.cpp.

References exportGeosToWkb(), mDirtyGeos, mDirtyWkb, mGeometry, mGeometrySize, QgsDebugMsg, QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBNoGeometry, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, wkbType(), and QGis::WKBUnknown.

Referenced by QgsVectorLayerEditUtils::insertVertex().

bool QgsGeometry::insertVertex ( double  x,
double  y,
int  beforeVertex,
const GEOSCoordSequence *  old_sequence,
GEOSCoordSequence **  new_sequence 
) [private]

Insert a new vertex before the given vertex index (first number is index 0) in the given GEOS Coordinate Sequence.

If the requested vertex number is greater than the last actual vertex, it is assumed that the vertex is to be appended instead of inserted.

Parameters:
xx coordinate
yy coordinate
beforeVertexinsert before vertex with this index
old_sequenceThe sequence to update (The caller remains the owner).
new_sequenceThe updated sequence (The caller becomes the owner if the function returns true). Returns false if beforeVertex does not correspond to a valid vertex number on the Coordinate Sequence.

Definition at line 1223 of file qgsgeometry.cpp.

Test for intersection with a rectangle (uses GEOS)

Definition at line 3844 of file qgsgeometry.cpp.

References fromRect().

Referenced by fcnBbox(), fcnIntersects(), and QgsOverlayAnalyzer::intersectFeature().

bool QgsGeometry::intersects ( QgsGeometry geometry)

Test for intersection with a geometry (uses GEOS)

Definition at line 3852 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), mGeos, and QgsDebugMsg.

check if geometry is empty using GEOS

Note:
added in 1.5

Definition at line 6853 of file qgsgeometry.cpp.

References asGeos(), QgsMessageLog::logMessage(), tr, and GEOSException::what().

compare geometries using GEOS

Note:
added in 1.5

Definition at line 6848 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by QgsVectorLayer::updateFeature().

check validity using GEOS

Note:
added in 1.5

Definition at line 6830 of file qgsgeometry.cpp.

References asGeos(), QgsMessageLog::logMessage(), tr, and GEOSException::what().

double QgsGeometry::leftOf ( double  x,
double  y,
double &  x1,
double &  y1,
double &  x2,
double &  y2 
) [private]

Returns < 0 if point(x/y) is left of the line x1,y1 -> x1,y2.

Definition at line 6871 of file qgsgeometry.cpp.

Referenced by closestSegmentWithContext().

double QgsGeometry::length ( )

get length of geometry using GEOS

Note:
added in 1.5

Definition at line 6357 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), mDirtyGeos, and mGeos.

Referenced by QgsPalLayerSettings::checkMinimumSizeMM(), and fromWkb().

int QgsGeometry::lineContainedInLine ( const GEOSGeometry *  line1,
const GEOSGeometry *  line2 
) [static, private]

Tests if line1 is completely contained in line2.

This method works with a very small buffer around line2 and therefore is less prone to numerical errors as the corresponding geos method

Definition at line 5943 of file qgsgeometry.cpp.

References DEFAULT_QUADRANT_SEGMENTS, and geomInDegrees().

Referenced by reshapeLine().

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

References CATCH_GEOS, convertToMultiType(), exportWkbToGeos(), isMultipart(), mDirtyGeos, mDirtyWkb, and mGeos.

Referenced by QgsVectorLayer::removePolygonIntersections().

int QgsGeometry::mergeGeometriesMultiTypeSplit ( QVector< GEOSGeometry * > &  splitResult) [private]
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 1275 of file qgsgeometry.cpp.

References exportGeosToWkb(), mDirtyGeos, mDirtyWkb, mGeometry, QgsDebugMsg, QGis::WKBLineString, QGis::WKBLineString25D, QGis::WKBMultiLineString, QGis::WKBMultiLineString25D, QGis::WKBMultiPoint, QGis::WKBMultiPoint25D, QGis::WKBMultiPolygon, QGis::WKBMultiPolygon25D, QGis::WKBPoint, QGis::WKBPoint25D, QGis::WKBPolygon, QGis::WKBPolygon25D, and wkbType().

Referenced by QgsVectorLayerEditUtils::moveVertex().

GEOSGeometry * QgsGeometry::nodeGeometries ( const GEOSGeometry *  splitLine,
const GEOSGeometry *  poly 
) [static, private]

Nodes together a split line and a (multi-) polygon geometry in a multilinestring.

Returns:
the noded multiline geometry or 0 in case of error. The calling function takes ownership of the node geometry

Definition at line 5918 of file qgsgeometry.cpp.

Referenced by reshapeLine(), and splitPolygonGeometry().

int QgsGeometry::numberOfGeometries ( GEOSGeometry *  g) const [private]

Returns number of single geometry in a geos geometry.

Is save for geos 2 and 3

Definition at line 6054 of file qgsgeometry.cpp.

Referenced by splitPolygonGeometry().

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

assignments will prompt a deep copy of the object

Note:
not available in python bindings

Definition at line 537 of file qgsgeometry.cpp.

References mDirtyGeos, mDirtyWkb, mGeometry, mGeometrySize, and mGeos.

bool QgsGeometry::overlaps ( QgsGeometry geometry)

Test for if geometry overlaps an other (uses GEOS)

Note:
added in 1.5

Definition at line 3944 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by fcnOverlaps().

int QgsGeometry::pointContainedInLine ( const GEOSGeometry *  point,
const GEOSGeometry *  line 
) [static, private]

Tests if a point is on a line.

This method works with a very small buffer and is thus less prone to numerical problems as the direct geos functions.

Parameters:
pointthe point to test
lineline to test
Returns:
0 not contained, 1 if contained, <0 in case of error

Definition at line 5982 of file qgsgeometry.cpp.

References geomInDegrees().

Referenced by reshapeLine().

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

References createGeosLineString(), exportWkbToGeos(), QGis::Line, mDirtyGeos, mDirtyWkb, mGeos, QGis::Point, reshapeLine(), reshapePolygon(), and type().

GEOSGeometry * QgsGeometry::reshapeLine ( const GEOSGeometry *  origLine,
const GEOSGeometry *  reshapeLineGeos 
) [static, private]

Creates a new line from an original line and a reshape line.

The part of the input line from the first to the last intersection with the reshape line will be replaced. The calling function takes ownership of the result.

Parameters:
origLinethe original line
reshapeLineGeosthe reshape line
Returns:
the reshaped line or 0 in case of error

Definition at line 5614 of file qgsgeometry.cpp.

References createGeosPoint(), lineContainedInLine(), QgsMessageLog::logMessage(), nodeGeometries(), pointContainedInLine(), tr, and GEOSException::what().

Referenced by reshapeGeometry(), and reshapePolygon().

GEOSGeometry * QgsGeometry::reshapePolygon ( const GEOSGeometry *  polygon,
const GEOSGeometry *  reshapeLineGeos 
) [static, private]

Creates a new polygon replacing the part from the first to the second intersection with the reshape line.

As a polygon ring is always closed, the method keeps the longer part of the existing boundary

Parameters:
polygongeometry to reshape
reshapeLineGeosthe reshape line
Returns:
the reshaped polygon or 0 in case of error

Definition at line 5481 of file qgsgeometry.cpp.

References QgsMessageLog::logMessage(), reshapeLine(), tr, and GEOSException::what().

Referenced by reshapeGeometry().

QgsGeometry * QgsGeometry::simplify ( double  tolerance)

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

Definition at line 6423 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by QgsGeometryAnalyzer::simplifyFeature().

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.

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

References CATCH_GEOS, createGeosLineString(), exportGeosToWkb(), exportWkbToGeos(), QGis::Line, mDirtyGeos, mDirtyWkb, mGeos, QGis::Point, QGis::Polygon, splitLinearGeometry(), splitPolygonGeometry(), topologicalTestPointsSplit(), and type().

Referenced by QgsVectorLayerEditUtils::splitFeatures().

int QgsGeometry::splitLinearGeometry ( GEOSGeometry *  splitLine,
QList< QgsGeometry * > &  newGeometries 
) [private]

Splits line/multiline geometries.

Parameters:
splitLinethe line that splits the feature
newGeometriesnew geometries if splitting was successful
Returns:
0 in case of success, 1 if geometry has not been split, error else

Definition at line 5292 of file qgsgeometry.cpp.

References exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, mDirtyWkb, mergeGeometriesMultiTypeSplit(), and mGeos.

Referenced by splitGeometry().

int QgsGeometry::splitPolygonGeometry ( GEOSGeometry *  splitLine,
QList< QgsGeometry * > &  newGeometries 
) [private]

Splits polygon/multipolygon geometries.

Returns:
0 in case of success, 1 if geometry has not been split, error else

Definition at line 5357 of file qgsgeometry.cpp.

References exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, mDirtyWkb, mergeGeometriesMultiTypeSplit(), mGeos, nodeGeometries(), numberOfGeometries(), and QgsDebugMsg.

Referenced by splitGeometry().

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))

Definition at line 2361 of file qgsgeometry.cpp.

References MathUtils::max(), QgsDebugMsg, QgsPoint::sqrDist(), QgsPoint::toString(), and vertexAt().

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

Definition at line 6593 of file qgsgeometry.cpp.

References CATCH_GEOS, exportWkbToGeos(), fromGeosGeom(), mDirtyGeos, and mGeos.

Referenced by fcnSymDifference().

int QgsGeometry::topologicalTestPointsSplit ( const GEOSGeometry *  splitLine,
QList< QgsPoint > &  testPoints 
) const [private]

Finds out the points that need to be tested for topological correctnes if this geometry will be split.

Returns:
0 in case of success

Definition at line 5860 of file qgsgeometry.cpp.

References mGeos.

Referenced by splitGeometry().

bool QgsGeometry::touches ( QgsGeometry geometry)

Test for if geometry touch an other (uses GEOS)

Note:
added in 1.5

Definition at line 3939 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by fcnTouches().

void QgsGeometry::transformVertex ( int &  wkbPosition,
const QgsCoordinateTransform ct,
bool  hasZValue 
) [private]

Transforms a single vertex by ct.

Parameters:
wkbPositionposition in wkb array. Is increased automatically by the function
ctthe QgsCoordinateTransform
hasZValue25D type?

Definition at line 5267 of file qgsgeometry.cpp.

References mGeometry, and QgsCoordinateTransform::transformInPlace().

Referenced by transform().

void QgsGeometry::translateVertex ( int &  wkbPosition,
double  dx,
double  dy,
bool  hasZValue 
) [private]

Translates a single vertex by dx and dy.

Parameters:
wkbPositionposition in wkb array. Is increased automatically by the function
dxtranslation of x-coordinate
dytranslation of y-coordinate
hasZValue25D type?

Definition at line 5245 of file qgsgeometry.cpp.

References mGeometry.

Referenced by translate().

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

bool QgsGeometry::within ( QgsGeometry geometry)

Test for if geometry is within an other (uses GEOS)

Note:
added in 1.5

Definition at line 3949 of file qgsgeometry.cpp.

References geosRelOp().

Referenced by fcnWithin().


Member Data Documentation

size_t QgsGeometry::mGeometrySize [private]

size of geometry

Definition at line 477 of file qgsgeometry.h.

Referenced by convertToMultiType(), deleteVertex(), exportGeosToWkb(), fromWkb(), insertVertex(), operator=(), QgsGeometry(), and wkbSize().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines