Skip to content
Permalink
Browse files
Update python binding for QgsGeometry
  • Loading branch information
mhugent committed May 29, 2015
1 parent bb374f0 commit 82d18e7e61feacb33dafa1ce19773839bd8579e4
Showing with 89 additions and 27 deletions.
  1. +89 −27 python/core/geometry/qgsgeometry.sip
@@ -101,43 +101,43 @@ class QgsGeometry
QGis::WkbType wkbType() const;

/** Returns type of the vector */
QGis::GeometryType type();
QGis::GeometryType type() const;

/** Returns true if wkb of the geometry is of WKBMulti* type */
bool isMultipart();
bool isMultipart() const;

/** compare geometries using GEOS
@note added in 1.5
*/
bool isGeosEqual( QgsGeometry & );
bool isGeosEqual( const QgsGeometry& ) const;

/** check validity using GEOS
@note added in 1.5
*/
bool isGeosValid();
bool isGeosValid() const;

/** check if geometry is empty using GEOS
@note added in 1.5
*/
bool isGeosEmpty();
bool isGeosEmpty() const;

/** get area of geometry using GEOS
@note added in 1.5
*/
double area();
double area() const;

/** get length of geometry using GEOS
@note added in 1.5
*/
double length();
double length() const;

double distance( QgsGeometry& geom );
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
*/
QgsPoint closestVertex( const QgsPoint& point, int& atVertex /Out/, int& beforeVertex /Out/, int& afterVertex /Out/, double& sqrDist /Out/ );
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.
@@ -151,7 +151,7 @@ class QgsGeometry
account the first vertex is equal to the last vertex (and will
skip equal vertex positions).
*/
void adjacentVertices( int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/ );
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)
@@ -174,6 +174,14 @@ class QgsGeometry
*/
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.
// * 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
@@ -191,22 +199,22 @@ class QgsGeometry
* @param atVertex index of the vertex
* @return Coordinates of the vertex or QgsPoint(0,0) on error
*/
QgsPoint vertexAt( int atVertex );
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))
*/
double sqrDistToVertexAt( QgsPoint& point /In/, int atVertex );
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
*/
double closestVertexWithContext( const QgsPoint& point, int& atVertex /Out/ );
double closestVertexWithContext( const QgsPoint& point, int& atVertex /Out/ ) const;

/**
* Searches for the closest segment of geometry to the given point
@@ -218,7 +226,7 @@ class QgsGeometry
* @param epsilon epsilon for segment snapping (added in 1.8)
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
*/
double closestSegmentWithContext( const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& afterVertex /Out/ );
double closestSegmentWithContext( const QgsPoint& point, QgsPoint& minDistPoint /Out/, int& afterVertex /Out/ ) const;

/**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,
@@ -263,6 +271,18 @@ class QgsGeometry
@return 0 in case of success*/
int transform( const QgsCoordinateTransform& ct );

/**Transform this geometry as described by QTransform ct
@note added in 2.8
@return 0 in case of success*/
int transform( const QTransform& ct );

/**Rotate this geometry around the Z axis
@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 );

/**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.
@param splitLine the line that splits the geometry
@@ -286,7 +306,7 @@ class QgsGeometry
int makeDifference( QgsGeometry* other );

/**Returns the bounding box of this feature*/
QgsRectangle boundingBox();
QgsRectangle boundingBox() const;

/** Test for intersection with a rectangle (uses GEOS) */
bool intersects( const QgsRectangle& r ) const;
@@ -327,7 +347,7 @@ class QgsGeometry

/** 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 ) /Factory/;
QgsGeometry* buffer( double distance, int segments ) const /Factory/;

/** Returns a buffer region around the geometry, with additional style options.
* @param segments For round joins, number of segments to approximate quarter-circle
@@ -337,47 +357,47 @@ class QgsGeometry
* @note added in 2.4
* @note needs GEOS >= 3.3 - otherwise always returns 0
*/
QgsGeometry* buffer( double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit ) /Factory/;
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
*/
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) /Factory/;
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) const /Factory/;

/** Returns a simplified version of this geometry using a specified tolerance value */
QgsGeometry* simplify( double tolerance ) /Factory/;
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 */
QgsGeometry* centroid() /Factory/;
QgsGeometry* centroid() const /Factory/;

/** Returns a point within a geometry */
QgsGeometry* pointOnSurface() /Factory/;
QgsGeometry* pointOnSurface() const /Factory/;

/** Returns the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull() /Factory/;
QgsGeometry* convexHull() const /Factory/;

/* 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. */
QgsGeometry* intersection( QgsGeometry* geometry ) /Factory/;
QgsGeometry* intersection( 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++.*/
QgsGeometry* combine( QgsGeometry* geometry ) /Factory/;
QgsGeometry* combine( QgsGeometry* geometry ) const /Factory/;

/** Returns a geometry representing the points making up this geometry that do not make up other. */
QgsGeometry* difference( QgsGeometry* geometry ) /Factory/;
QgsGeometry* difference( QgsGeometry* geometry ) const /Factory/;

/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
QgsGeometry* symDifference( QgsGeometry* geometry ) /Factory/;
QgsGeometry* symDifference( QgsGeometry* geometry ) const /Factory/;

/** Exports the geometry to WKT
* @note precision parameter added in 2.4
@@ -399,7 +419,7 @@ class QgsGeometry
* @return the converted geometry or NULL pointer if the conversion fails.
* @note added in 2.2
*/
QgsGeometry* convertToType( QGis::GeometryType destType, bool destMultipart = false ) /Factory/;
QgsGeometry* convertToType( QGis::GeometryType destType, bool destMultipart = false ) const /Factory/;

/* Accessor functions for getting geometry data */

@@ -431,6 +451,19 @@ class QgsGeometry
@note added in version 1.1 */
QList<QgsGeometry*> asGeometryCollection() const /Factory/;

/**Return contents of the geometry as a QPointF if wkbType is WKBPoint,
* otherwise returns a null QPointF.
* @note added in QGIS 2.7
*/
QPointF asQPointF() const;

/**Return contents of the geometry as a QPolygonF. If geometry is a linestring,
* then the result will be an open QPolygonF. If the geometry is a polygon,
* then the result will be a closed QPolygonF of the geometry's exterior ring.
* @note added in QGIS 2.7
*/
QPolygonF asQPolygonF() const;

/** delete a ring in polygon or multipolygon.
Ring 0 is outer ring and can't be deleted.
@return true on success
@@ -488,6 +521,30 @@ class QgsGeometry
*/
bool requiresConversionToStraightSegments() const;

void mapToPixel( const QgsMapToPixel& mtp );
void clip( const QgsRectangle& rect );
void draw( QPainter& p ) const;

bool vertexIdFromVertexNr( int nr, QgsVertexId& id ) const;
int vertexNrFromVertexId( const QgsVertexId& i ) const;

/**Construct geometry from a QPointF
* @param point source QPointF
* @note added in QGIS 2.7
*/
static QgsGeometry* fromQPointF( const QPointF& point ) /Factory/;

/**Construct geometry from a QPolygonF. If the polygon is closed than
* the resultant geometry will be a polygon, if it is open than the
* geometry will be a polyline.
* @param polygon source QPolygonF
* @note added in QGIS 2.7
*/
static QgsGeometry* fromQPolygonF( const QPolygonF& polygon ) /Factory/;
static QgsPolyline createPolylineFromQPolygonF( const QPolygonF &polygon ) /Factory/;
static QgsPolygon createPolygonFromQPolygonF( const QPolygonF &polygon ) /Factory/;


/** Compares two polylines for equality within a specified tolerance.
* @param p1 first polyline
* @param p2 second polyline
@@ -529,5 +586,10 @@ class QgsGeometry
* @note added in 2.9
*/
QgsGeometry* smooth( const unsigned int iterations, const double offset ) const;

/**Smooths a polygon using the Chaikin algorithm*/
QgsPolygon smoothPolygon( const QgsPolygon &polygon, const unsigned int iterations = 1, const double offset = 0.25 ) const;
/**Smooths a polyline using the Chaikin algorithm*/
QgsPolyline smoothLine( const QgsPolyline &polyline, const unsigned int iterations = 1, const double offset = 0.25 ) const;
}; // class QgsGeometry

1 comment on commit 82d18e7

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson commented on 82d18e7 May 29, 2015

@mhugent thanks!

Please sign in to comment.