QGIS/python/core/geometry/qgsgeometry.sip

715 lines
30 KiB
Plaintext
Raw Normal View History

2015-07-29 11:52:14 +02:00
/** Polyline is represented as a vector of points */
typedef QVector<QgsPoint> QgsPolyline;
2015-07-29 11:52:14 +02:00
/** Polygon: first item of the list is outer ring, inner rings (if any) start from second item */
typedef QVector< QVector<QgsPoint> > QgsPolygon;
2015-07-29 11:52:14 +02:00
/** A collection of QgsPoints that share a common collection of attributes */
typedef QVector<QgsPoint> QgsMultiPoint;
2015-07-29 11:52:14 +02:00
/** A collection of QgsPolylines that share a common collection of attributes */
typedef QVector< QVector<QgsPoint> > QgsMultiPolyline;
2015-07-29 11:52:14 +02:00
/** A collection of QgsPolygons that share a common collection of attributes */
typedef QVector< QVector< QVector<QgsPoint> > > QgsMultiPolygon;
/** \ingroup core
* 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 @link QgsAbstractGeometryV2 @endlink within the container, and
* can be accessed via the @link geometry @endlink method or set using the @link setGeometry @endlink method.
*/
class QgsGeometry
{
%TypeHeaderCode
#include <qgsgeometry.h>
%End
public:
//! Constructor
QgsGeometry();
2015-07-29 11:52:14 +02:00
/** Copy constructor will prompt a deep copy of the object */
QgsGeometry( const QgsGeometry & );
/** Creates a geometry from an abstract geometry object. Ownership of
* geom is transferred.
2015-06-01 15:17:56 +02:00
* @note added in QGIS 2.10
*/
2015-09-01 16:07:10 +10:00
explicit QgsGeometry( QgsAbstractGeometryV2* geom /Transfer/ );
//! Destructor
~QgsGeometry();
2015-06-01 15:17:56 +02:00
/** Returns the underlying geometry store.
* @note added in QGIS 2.10
* @see setGeometry
2015-06-01 15:17:56 +02:00
*/
QgsAbstractGeometryV2* geometry() const;
2015-05-15 15:41:56 +02:00
/** Sets the underlying geometry store. Ownership of geometry is transferred.
* @note added in QGIS 2.10
* @see geometry
*/
void setGeometry( QgsAbstractGeometryV2* geometry /Transfer/ );
/** Returns true if the geometry is empty (ie, contains no underlying geometry
* accessible via @link geometry @endlink).
* @see geometry
* @note added in QGIS 2.10
*/
bool isEmpty() const;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a WKT string */
static QgsGeometry* fromWkt( const QString& wkt ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsPoint object*/
static QgsGeometry* fromPoint( const QgsPoint& point ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsMultiPoint object */
static QgsGeometry* fromMultiPoint( const QgsMultiPoint& multipoint ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsPolyline object */
static QgsGeometry* fromPolyline( const QgsPolyline& polyline ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsMultiPolyline object*/
static QgsGeometry* fromMultiPolyline( const QgsMultiPolyline& multiline ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsPolygon */
static QgsGeometry* fromPolygon( const QgsPolygon& polygon ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsMultiPolygon */
static QgsGeometry* fromMultiPolygon( const QgsMultiPolygon& multipoly ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a new geometry from a QgsRectangle */
static QgsGeometry* fromRect( const QgsRectangle& rect ) /Factory/;
2015-06-01 15:17:56 +02:00
2014-01-26 18:35:21 +01:00
/**
Set the geometry, feeding in a geometry in GEOS format.
This class will take ownership of the buffer.
@note not available in python bindings
*/
// void fromGeos( GEOSGeometry* geos );
/**
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.
*/
void fromWkb( unsigned char * wkb /Array/, int length /ArraySize/ );
%MethodCode
// create copy of Python's string and pass it to fromWkb()
unsigned char * copy = new unsigned char[a1];
memcpy(copy, a0, a1);
sipCpp->fromWkb(copy, a1);
%End
/**
Returns the buffer containing this geometry in WKB format.
You may wish to use in conjunction with wkbSize().
2015-06-01 15:17:56 +02:00
@see wkbSize
*/
SIP_PYOBJECT asWkb();
%MethodCode
sipRes = PyBytes_FromStringAndSize((const char *)sipCpp->asWkb(), sipCpp->wkbSize());
%End
/**
* Returns the size of the WKB in asWkb().
2015-06-01 15:17:56 +02:00
* @see asWkb
*/
int wkbSize() const;
2015-06-01 15:17:56 +02:00
/** Returns a geos geometry. QgsGeometry retains ownership of the geometry, so the returned object should not be deleted.
2015-10-08 11:28:32 +02:00
@param precision The precision of the grid to which to snap the geometry vertices. If 0, no snapping is performed.
2015-05-15 15:41:56 +02:00
@note this method was added in version 1.1
2014-01-18 23:05:32 +01:00
@note not available in python bindings
*/
2015-10-08 11:28:32 +02:00
// const GEOSGeometry* asGeos( double precision = 0 ) const;
2014-01-18 23:05:32 +01:00
2015-06-01 15:17:56 +02:00
/** Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
* @see type
*/
2013-06-25 16:03:46 +02:00
QGis::WkbType wkbType() const;
2015-06-01 15:17:56 +02:00
/** Returns type of the geometry as a QGis::GeometryType
* @see wkbType
*/
2015-05-29 11:35:13 +02:00
QGis::GeometryType type() const;
2015-06-01 15:17:56 +02:00
/** Returns true if WKB of the geometry is of WKBMulti* type */
2015-05-29 11:35:13 +02:00
bool isMultipart() const;
2015-06-01 15:17:56 +02:00
/** Compares the geometry with another geometry using GEOS
2015-05-15 15:41:56 +02:00
@note added in 1.5
*/
2015-05-29 11:35:13 +02:00
bool isGeosEqual( const QgsGeometry& ) const;
2015-06-01 15:17:56 +02:00
/** Checks validity of the geometry using GEOS
2015-05-15 15:41:56 +02:00
@note added in 1.5
*/
2015-05-29 11:35:13 +02:00
bool isGeosValid() const;
2015-06-01 15:17:56 +02:00
/** Check if the geometry is empty using GEOS
2015-05-15 15:41:56 +02:00
@note added in 1.5
*/
2015-05-29 11:35:13 +02:00
bool isGeosEmpty() const;
2015-06-01 15:17:56 +02:00
/** Returns the area of the geometry using GEOS
2015-05-15 15:41:56 +02:00
@note added in 1.5
*/
2015-05-29 11:35:13 +02:00
double area() const;
2015-06-01 15:17:56 +02:00
/** Returns the length of geometry using GEOS
2015-05-15 15:41:56 +02:00
@note added in 1.5
*/
2015-05-29 11:35:13 +02:00
double length() const;
2016-01-15 08:34:42 +11:00
/** Returns the minimum distance between this geometry and another geometry, using GEOS
2015-06-01 15:17:56 +02:00
* @param geom geometry to find minimum distance to
*/
2015-05-29 11:35:13 +02:00
double distance( const QgsGeometry& geom ) 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
*/
2015-05-29 11:35:13 +02:00
QgsPoint closestVertex( const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/ ) 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).
*/
2015-05-29 11:35:13 +02:00
void adjacentVertices( int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/ ) const;
/** 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?)
*/
bool insertVertex( double x, double y, int beforeVertex );
/** 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
*/
bool moveVertex( double x, double y, int atVertex );
2015-05-29 11:35:13 +02:00
/** 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
*/
bool moveVertex( const QgsPointV2& p, 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?)
*/
bool deleteVertex( int atVertex );
/**
* Returns coordinates of a vertex.
* @param atVertex index of the vertex
* @return Coordinates of the vertex or QgsPoint(0,0) on error
*/
2015-05-29 11:35:13 +02:00
QgsPoint vertexAt( 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))
*/
2015-05-29 11:35:13 +02:00
double sqrDistToVertexAt( QgsPoint& point /In/, int atVertex ) const;
/**
* Searches for the closest vertex in this geometry to the given point.
* @param point Specifiest the point for search
* @param atVertex Receives index of the closest vertex
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
*/
2015-05-29 11:35:13 +02:00
double closestVertexWithContext( const QgsPoint& point, int& atVertex /Out/ ) const;
/**
* Searches for the closest segment of geometry to the given point
* @param point Specifies the point for search
* @param minDistPoint Receives the nearest point on the segment
* @param afterVertex Receives index of the vertex after the closest segment. The vertex
* before the closest segment is always afterVertex - 1
* @param leftOf Out: Returns if the point lies on the left of right side of the segment ( < 0 means left, > 0 means right )
2015-05-15 15:41:56 +02:00
* @param epsilon epsilon for segment snapping (added in 1.8)
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
*/
2015-05-29 11:35:13 +02:00
double closestSegmentWithContext( const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& afterVertex /Out/ ) const;
2015-07-29 11:52:14 +02:00
/** Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
@return 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*/
int addRing( const QList<QgsPoint>& ring );
2015-07-29 11:52:14 +02:00
/** Adds a new ring to this geometry. This makes only sense for polygon and multipolygons.
2015-05-15 15:41:56 +02:00
@return 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*/
int addRing( QgsCurveV2* ring );
/** Adds a new part to a the geometry.
* @param points points describing part to add
* @param geomType default 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
*/
2014-01-18 23:05:32 +01:00
int addPart( const QList<QgsPoint> &points, QGis::GeometryType geomType = QGis::UnknownGeometry );
/** Adds a new part to this geometry.
* @param part part to add (ownership is transferred)
* @param geomType default 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
*/
int addPart( QgsAbstractGeometryV2* part /Transfer/, QGis::GeometryType geomType = QGis::UnknownGeometry );
2015-06-01 15:17:56 +02:00
2015-07-29 11:52:14 +02:00
/** Adds a new island polygon to a multipolygon feature
2014-01-26 18:35:21 +01:00
@return 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
*/
// int addPart( GEOSGeometry *newPart );
2015-07-29 11:52:14 +02:00
/** Adds a new island polygon to a multipolygon feature
2014-01-26 18:35:21 +01:00
@return 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
2015-06-01 15:17:56 +02:00
@note available in python bindings as addPartGeometry (added in 2.2)
2014-01-26 18:35:21 +01:00
*/
2015-05-15 15:41:56 +02:00
int addPart( const QgsGeometry *newPart /Transfer/ ) /PyName=addPartGeometry/;
2014-01-26 18:35:21 +01:00
2015-07-29 11:52:14 +02:00
/** Translate this geometry by dx, dy
@return 0 in case of success*/
int translate( double dx, double dy );
2015-07-29 11:52:14 +02:00
/** Transform this geometry as described by CoordinateTransform ct
@return 0 in case of success*/
int transform( const QgsCoordinateTransform& ct );
2015-07-29 11:52:14 +02:00
/** Transform this geometry as described by QTransform ct
2015-05-29 11:35:13 +02:00
@note added in 2.8
@return 0 in case of success*/
int transform( const QTransform& ct );
2015-07-29 11:52:14 +02:00
/** Rotate this geometry around the Z axis
2015-05-29 11:35:13 +02:00
@note added in 2.8
@param rotation clockwise rotation in degrees
@param center rotation center
@return 0 in case of success*/
int rotate( double rotation, const QgsPoint& center );
2015-07-29 11:52:14 +02:00
/** Splits this geometry according to a given line.
@param splitLine the line that splits the geometry
@param[out] newGeometries list of new geometries that have been created with the split
@param topological true if topological editing is enabled
@param[out] topologyTestPoints points that need to be tested for topological completeness in the dataset
@return 0 in case of success, 1 if geometry has not been split, error else*/
int splitGeometry( const QList<QgsPoint>& splitLine,
QList<QgsGeometry*>&newGeometries /Out/,
bool topological,
QList<QgsPoint> &topologyTestPoints /Out/);
2015-07-29 11:52:14 +02:00
/** Replaces a part of this geometry with another line
2015-05-15 15:41:56 +02:00
@return 0 in case of success
@note: this function was added in version 1.3*/
int reshapeGeometry( const QList<QgsPoint>& reshapeWithLine );
2015-07-29 11:52:14 +02:00
/** Changes this geometry such that it does not intersect the other geometry
@param other geometry that should not be intersect
@return 0 in case of success*/
2015-06-01 15:17:56 +02:00
int makeDifference( const QgsGeometry* other );
2015-07-29 11:52:14 +02:00
/** Returns the bounding box of this feature*/
2015-05-29 11:35:13 +02:00
QgsRectangle boundingBox() const;
/** Test for intersection with a rectangle (uses GEOS) */
2013-06-25 16:03:46 +02:00
bool intersects( const QgsRectangle& r ) const;
/** Test for intersection with a geometry (uses GEOS) */
2013-06-25 16:03:46 +02:00
bool intersects( const QgsGeometry* geometry ) const;
/** Test for containment of a point (uses GEOS) */
2013-06-25 16:03:46 +02:00
bool contains( const QgsPoint* p ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry is contained in another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool contains( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry is disjoint of another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool disjoint( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry equals another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool equals( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry touch another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool touches( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry overlaps another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool overlaps( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry is within another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool within( const QgsGeometry* geometry ) const;
2015-05-15 15:41:56 +02:00
/** Test for if geometry crosses another (uses GEOS)
* @note added in 1.5 */
2013-06-25 16:03:46 +02:00
bool crosses( const QgsGeometry* geometry ) const;
/** Returns a buffer region around this geometry having the given width and with a specified number
of segments used to approximate curves */
2015-05-29 11:35:13 +02:00
QgsGeometry* buffer( double distance, int segments ) const /Factory/;
/** Returns a buffer region around the geometry, with additional style options.
2015-06-01 15:17:56 +02:00
* @param distance buffer distance
* @param segments For round joins, number of segments to approximate quarter-circle
* @param endCapStyle Round (1) / Flat (2) / Square (3) end cap style
* @param joinStyle Round (1) / Mitre (2) / Bevel (3) join style
* @param mitreLimit Limit on the mitre ratio used for very sharp corners
* @note added in 2.4
* @note needs GEOS >= 3.3 - otherwise always returns 0
*/
2015-05-29 11:35:13 +02:00
QgsGeometry* buffer( double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit ) const /Factory/;
/** 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
* @note needs GEOS >= 3.3 - otherwise always returns 0
*/
2015-05-29 11:35:13 +02:00
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) const /Factory/;
/** Returns a simplified version of this geometry using a specified tolerance value */
2015-05-29 11:35:13 +02:00
QgsGeometry* simplify( double tolerance ) const /Factory/;
/** 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 */
2015-05-29 11:35:13 +02:00
QgsGeometry* centroid() const /Factory/;
/** Returns a point within a geometry */
2015-05-29 11:35:13 +02:00
QgsGeometry* pointOnSurface() const /Factory/;
/** Returns the smallest convex polygon that contains all the points in the geometry. */
2015-05-29 11:35:13 +02:00
QgsGeometry* convexHull() const /Factory/;
2012-07-29 22:32:17 +10:00
2015-05-15 15:41:56 +02:00
/* Return interpolated point on line at distance
* @note added in 1.9
*/
QgsGeometry* interpolate( double distance ) /Factory/;
/** Returns a geometry representing the points shared by this geometry and other. */
2015-06-01 15:17:56 +02:00
QgsGeometry* intersection( const QgsGeometry* geometry ) const /Factory/;
/** 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++.*/
2015-06-01 15:17:56 +02:00
QgsGeometry* combine( const QgsGeometry* geometry ) const /Factory/;
/** Returns a geometry representing the points making up this geometry that do not make up other. */
2015-06-01 15:17:56 +02:00
QgsGeometry* difference( const QgsGeometry* geometry ) const /Factory/;
2015-12-21 20:58:57 +01:00
/** Returns a Geometry representing the points making up this geometry that do not make up other. */
2015-06-01 15:17:56 +02:00
QgsGeometry* symDifference( const QgsGeometry* geometry ) const /Factory/;
2015-12-21 20:58:57 +01:00
/** Returns an extruded version of this geometry. */
QgsGeometry extrude( double x, double y );
/** Exports the geometry to WKT
* @note precision parameter added in 2.4
* @return true in case of success and false else
*/
QString exportToWkt( const int &precision = 17 ) const;
/** Exports the geometry to GeoJSON
* @return a QString representing the geometry as GeoJSON
2015-05-15 15:41:56 +02:00
* @note added in 1.8
* @note python binding added in 1.9
* @note precision parameter added in 2.4
*/
QString exportToGeoJSON( const int &precision = 17 ) const;
2015-07-29 11:52:14 +02:00
/** Try to convert the geometry to the requested type
2014-01-22 08:58:57 +01:00
* @param destType the geometry type to be converted to
* @param destMultipart determines if the output geometry will be multipart or not
* @return the converted geometry or NULL pointer if the conversion fails.
* @note added in 2.2
*/
2015-05-29 11:35:13 +02:00
QgsGeometry* convertToType( QGis::GeometryType destType, bool destMultipart = false ) const /Factory/;
2014-01-22 08:58:57 +01:00
/* Accessor functions for getting geometry data */
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a point
if wkbType is WKBPoint, otherwise returns [0,0] */
2013-06-25 16:03:46 +02:00
QgsPoint asPoint() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a polyline
if wkbType is WKBLineString, otherwise an empty list */
2013-06-25 16:03:46 +02:00
QgsPolyline asPolyline() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a polygon
if wkbType is WKBPolygon, otherwise an empty list */
2013-06-25 16:03:46 +02:00
QgsPolygon asPolygon() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a multi point
if wkbType is WKBMultiPoint, otherwise an empty list */
2013-06-25 16:03:46 +02:00
QgsMultiPoint asMultiPoint() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a multi linestring
if wkbType is WKBMultiLineString, otherwise an empty list */
2013-06-25 16:03:46 +02:00
QgsMultiPolyline asMultiPolyline() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a multi polygon
if wkbType is WKBMultiPolygon, otherwise an empty list */
2013-06-25 16:03:46 +02:00
QgsMultiPolygon asMultiPolygon() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a list of geometries
2015-05-15 15:41:56 +02:00
@note added in version 1.1 */
2013-06-25 16:03:46 +02:00
QList<QgsGeometry*> asGeometryCollection() const /Factory/;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a QPointF if wkbType is WKBPoint,
2015-05-29 11:35:13 +02:00
* otherwise returns a null QPointF.
* @note added in QGIS 2.7
*/
QPointF asQPointF() const;
2015-07-29 11:52:14 +02:00
/** Return contents of the geometry as a QPolygonF. If geometry is a linestring,
2015-05-29 11:35:13 +02:00
* 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
*/
QPolygonF asQPolygonF() const;
2015-06-01 15:17:56 +02:00
/** Delete a ring in polygon or multipolygon.
Ring 0 is outer ring and can't be deleted.
2015-05-15 15:41:56 +02:00
@return true on success
@note added in version 1.2 */
bool deleteRing( int ringNum, int partNum = 0 );
2015-06-01 15:17:56 +02:00
/** Delete part identified by the part number
2015-05-15 15:41:56 +02:00
@return true on success
@note added in version 1.2 */
bool deletePart( int partNum );
2015-07-29 11:52:14 +02:00
/** Converts single type geometry into multitype geometry
e.g. a polygon into a multipolygon geometry with one polygon
@return true in case of success and false else*/
bool convertToMultiType();
/**
* 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.
*
* @return true in case of success and false else
*/
bool convertToSingleType();
/** Modifies geometry to avoid intersections with the layers specified in project properties
* @return 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
* @param ignoreFeatures possibility to give a list of features where intersections should be ignored (not available in python bindings)
2015-05-15 15:41:56 +02:00
* @note added in 1.5
*/
int avoidIntersections();
class Error
{
public:
Error();
Error( const QString& m );
Error( const QString& m, const QgsPoint& p );
QString what();
QgsPoint where();
bool hasWhere();
};
2015-05-15 15:41:56 +02:00
/** Validate geometry and produce a list of geometry errors
* @note added in 1.5
* @note python binding added in 1.6
**/
void validateGeometry( QList<QgsGeometry::Error> &errors /Out/ );
2014-06-13 16:40:41 +02:00
2015-07-29 11:52:14 +02:00
/** Compute the unary union on a list of geometries. May be faster than an iterative union on a set of geometries.
2014-06-13 16:40:41 +02:00
@param geometryList a list of QgsGeometry* as input
@returns the new computed QgsGeometry, or null
*/
static QgsGeometry *unaryUnion( const QList<QgsGeometry*>& geometryList ) /Factory/;
2015-05-26 11:42:27 +02:00
2015-06-01 15:17:56 +02:00
/** Converts the geometry to straight line segments, if it is a curved geometry type.
* @note added in QGIS 2.10
* @see requiresConversionToStraightSegments
*/
void convertToStraightSegment();
/** 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 convertToStraightSegment
*/
bool requiresConversionToStraightSegments() const;
2015-06-01 15:17:56 +02:00
/** Transforms the geometry from map units to pixels in place.
* @param mtp map to pixel transform
* @note added in QGIS 2.10
*/
2015-05-29 11:35:13 +02:00
void mapToPixel( const QgsMapToPixel& mtp );
2015-06-01 15:17:56 +02:00
// not implemented for 2.10
/** Clips the geometry using the specified rectangle
* @param rect clip rectangle
* @note added in QGIS 2.10
*/
// void clip( const QgsRectangle& rect );
/** Draws the geometry onto a QPainter
* @param p destination QPainter
* @note added in QGIS 2.10
*/
2015-05-29 11:35:13 +02:00
void draw( QPainter& p ) const;
2015-06-01 15:17:56 +02:00
/** Calculates the vertex ID from a vertex number
* @param nr vertex number
* @param id reference to QgsVertexId for storing result
* @returns true if vertex was found
* @note added in QGIS 2.10
* @see vertexNrFromVertexId
*/
2015-05-29 11:35:13 +02:00
bool vertexIdFromVertexNr( int nr, QgsVertexId& id ) const;
2015-06-01 15:17:56 +02:00
/** Returns the vertex number corresponding to a vertex idd
* @param i vertex id
* @returns vertex number
* @note added in QGIS 2.10
* @see vertexIdFromVertexNr
*/
2015-05-29 11:35:13 +02:00
int vertexNrFromVertexId( const QgsVertexId& i ) const;
2015-07-29 11:52:14 +02:00
/** Return GEOS context handle
2015-06-01 15:17:56 +02:00
* @note added in 2.6
* @note not available in Python
*/
// static GEOSContextHandle_t getGEOSHandler();
2015-07-29 11:52:14 +02:00
/** Construct geometry from a QPointF
2015-05-29 11:35:13 +02:00
* @param point source QPointF
* @note added in QGIS 2.7
*/
static QgsGeometry* fromQPointF( const QPointF& point ) /Factory/;
2015-07-29 11:52:14 +02:00
/** Construct geometry from a QPolygonF. If the polygon is closed than
2015-05-29 11:35:13 +02:00
* the resultant geometry will be a polygon, if it is open than the
* geometry will be a polyline.
* @param polygon source QPolygonF
* @note added in QGIS 2.7
*/
static QgsGeometry* fromQPolygonF( const QPolygonF& polygon ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a QgsPolyline from a QPolygonF.
* @param polygon source polygon
* @returns QgsPolyline
* @see createPolygonFromQPolygonF
*/
2015-05-29 11:35:13 +02:00
static QgsPolyline createPolylineFromQPolygonF( const QPolygonF &polygon ) /Factory/;
2015-06-01 15:17:56 +02:00
/** Creates a QgsPolygon from a QPolygonF.
* @param polygon source polygon
* @returns QgsPolygon
* @see createPolylineFromQPolygonF
*/
static QgsPolygon createPolygonFromQPolygonF( const QPolygonF &polygon ) /Factory/;
2015-05-29 11:35:13 +02:00
2015-05-26 11:42:27 +02:00
/** Compares two polylines for equality within a specified tolerance.
* @param p1 first polyline
* @param p2 second polyline
* @param epsilon maximum 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
*/
static bool compare( const QgsPolyline& p1, const QgsPolyline& p2, double epsilon = 4 * DBL_EPSILON );
/** Compares two polygons for equality within a specified tolerance.
* @param p1 first polygon
* @param p2 second polygon
* @param epsilon maximum 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
*/
static bool compare( const QgsPolygon& p1, const QgsPolygon& p2, double epsilon = 4 * DBL_EPSILON );
/** Compares two multipolygons for equality within a specified tolerance.
* @param p1 first multipolygon
* @param p2 second multipolygon
* @param epsilon maximum 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
*/
static bool compare( const QgsMultiPolygon& p1, const QgsMultiPolygon& p2, double epsilon = 4 * DBL_EPSILON );
2015-07-29 11:52:14 +02:00
/** Smooths a geometry by rounding off corners using the Chaikin algorithm. This operation
2015-05-26 11:42:27 +02:00
* roughly doubles the number of vertices in a geometry.
* @param iterations number of smoothing iterations to run. More iterations results
* in a smoother geometry
* @param offset fraction 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
*/
2015-06-01 15:17:56 +02:00
QgsGeometry* smooth( const unsigned int iterations, const double offset ) const;
2015-05-29 11:35:13 +02:00
2015-07-29 11:52:14 +02:00
/** Smooths a polygon using the Chaikin algorithm*/
2015-05-29 11:35:13 +02:00
QgsPolygon smoothPolygon( const QgsPolygon &polygon, const unsigned int iterations = 1, const double offset = 0.25 ) const;
2015-07-29 11:52:14 +02:00
/** Smooths a polyline using the Chaikin algorithm*/
2015-05-29 11:35:13 +02:00
QgsPolyline smoothLine( const QgsPolyline &polyline, const unsigned int iterations = 1, const double offset = 0.25 ) const;
/** Creates and returns a new geometry engine*/
2015-06-25 11:34:36 +02:00
static QgsGeometryEngine* createGeometryEngine( const QgsAbstractGeometryV2* geometry ) /Factory/;
2015-10-22 21:56:54 +02:00
/** Upgrades a point list from QgsPoint to QgsPointV2
* @param input list of QgsPoint objects to be upgraded
* @param output destination for list of points converted to QgsPointV2
*/
static void convertPointList( const QList<QgsPoint>& input, QList<QgsPointV2>& output );
/** Downgrades a point list from QgsPointV2 to QgsPoint
* @param input list of QgsPointV2 objects to be downgraded
* @param output destination for list of points converted to QgsPoint
*/
2015-10-22 21:56:54 +02:00
static void convertPointList( const QList<QgsPointV2>& input, QList<QgsPoint>& output );
}; // class QgsGeometry