Skip to content
Permalink
Browse files

Return enum instead of int from QgsGeometry operations

  • Loading branch information
3nids authored and m-kuhn committed Aug 13, 2017
1 parent 8d61554 commit 86e8da74cb0bbdef40fc8aae9da55d70304f0429
@@ -44,6 +44,23 @@ class QgsGeometry
#include "qgsgeometry.h"
%End
public:

enum OperationResult
{
Success,
NothingHappened,
InvalidBaseGeometry,
InvalidInput,
GeometryEngineError,
AddPartSelectedGeometryNotFound,
AddPartNotMultiGeometry,
AddRingNotClosed,
AddRingNotValid,
AddRingCrossesExistingRings,
AddRingNotInExistingFeature,
SplitCannotSplitPoint,
};

QgsGeometry();
%Docstring
Constructor
@@ -380,63 +397,58 @@ Returns true if WKB of the geometry is of WKBMulti* type
:rtype: float
%End

int addRing( const QList<QgsPointXY> &ring );
OperationResult addRing( const QList<QgsPointXY> &ring );
%Docstring
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*
:rtype: int
\param ring The ring to be added
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int addRing( QgsCurve *ring /Transfer/ );
OperationResult addRing( QgsCurve *ring /Transfer/ );
%Docstring
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*
:rtype: int
\param ring The ring to be added
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPoints/;
OperationResult addPart( const QList<QgsPointXY> &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPoints/;
%Docstring
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
: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
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPointsV2/;
OperationResult addPart( const QgsPointSequence &points, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry ) /PyName=addPointsV2/;
%Docstring
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
: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
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int addPart( QgsAbstractGeometry *part /Transfer/, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
OperationResult addPart( QgsAbstractGeometry *part /Transfer/, QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
%Docstring
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
: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
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End


int addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/;
OperationResult addPart( const QgsGeometry &newPart ) /PyName=addPartGeometry/;
%Docstring
Adds a new island polygon to a multipolygon feature
: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
:return: OperationResult a result code: success or reason of failure
.. note::

available in Python bindings as addPartGeometry
.. versionadded:: 2.2
:rtype: int
available in python bindings as addPartGeometry
:rtype: OperationResult
%End

QgsGeometry removeInteriorRings( double minimumAllowedArea = -1 ) const;
@@ -448,52 +460,52 @@ not disjoint with existing polygons of the feature
:rtype: QgsGeometry
%End

int translate( double dx, double dy );
OperationResult translate( double dx, double dy );
%Docstring
Translate this geometry by dx, dy
:return: 0 in case of success*
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int transform( const QgsCoordinateTransform &ct );
OperationResult transform( const QgsCoordinateTransform &ct );
%Docstring
Transform this geometry as described by CoordinateTransform ct
:return: 0 in case of success*
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int transform( const QTransform &ct );
OperationResult transform( const QTransform &ct );
%Docstring
Transform this geometry as described by QTransform ct
.. versionadded:: 2.8
:return: 0 in case of success*
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int rotate( double rotation, const QgsPointXY &center );
OperationResult rotate( double rotation, const QgsPointXY &center );
%Docstring
Rotate this geometry around the Z axis
.. versionadded:: 2.8
\param rotation clockwise rotation in degrees
\param center rotation center
:return: 0 in case of success*
:rtype: int
\param rotation clockwise rotation in degrees
\param center rotation center
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int splitGeometry( const QList<QgsPointXY> &splitLine,
QList<QgsGeometry> &newGeometries /Out/,
bool topological,
QList<QgsPointXY> &topologyTestPoints /Out/ );
OperationResult splitGeometry( const QList<QgsPointXY> &splitLine, QList<QgsGeometry> &newGeometries, bool topological, QList<QgsPointXY> &topologyTestPoints );
%Docstring
:rtype: int
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: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End

int reshapeGeometry( const QgsLineString &reshapeLineString );
OperationResult reshapeGeometry( const QgsLineString &reshapeLineString );
%Docstring
Replaces a part of this geometry with another line
:return: 0 in case of success
.. versionadded:: 1.3
:rtype: int
:return: OperationResult a result code: success or reason of failure
:rtype: OperationResult
%End


@@ -21,6 +21,19 @@ class QgsGeometryEngine
#include "qgsgeometryengine.h"
%End
public:

enum EngineOperationResult
{
Success,
NothingHappened,
MethodNotImplemented,
EngineError,
NodedGeometryError,
InvalidBaseGeometry,
InvalidInput,
SplitCannotSplitPoint,
};

virtual ~QgsGeometryEngine();

virtual void geometryChanged() = 0;
@@ -230,12 +243,12 @@ class QgsGeometryEngine
:rtype: bool
%End

virtual int splitGeometry( const QgsLineString &splitLine,
QList<QgsAbstractGeometry *> &newGeometries,
bool topological,
QgsPointSequence &topologyTestPoints, QString *errorMsg = 0 ) const;
virtual QgsGeometryEngine::EngineOperationResult splitGeometry( const QgsLineString &splitLine,
QList<QgsAbstractGeometry *> &newGeometries,
bool topological,
QgsPointSequence &topologyTestPoints, QString *errorMsg = 0 ) const;
%Docstring
:rtype: int
:rtype: QgsGeometryEngine.EngineOperationResult
%End

virtual QgsAbstractGeometry *offsetCurve( double distance, int segments, int joinStyle, double miterLimit, QString *errorMsg = 0 ) const = 0 /Factory/;
@@ -63,29 +63,51 @@ class QgsVectorLayerEditUtils
:rtype: QgsVectorLayer.EditResult
%End

int addRing( const QList<QgsPointXY> &ring, const QgsFeatureIds &targetFeatureIds = QgsFeatureIds(), QgsFeatureId *modifiedFeatureId = 0 );
QgsGeometry::OperationResult addRing( const QList<QgsPointXY> &ring, const QgsFeatureIds &targetFeatureIds = QgsFeatureIds(), QgsFeatureId *modifiedFeatureId = 0 );
%Docstring
:rtype: int
Adds a ring to polygon/multipolygon features
@param ring ring to add
@param targetFeatureIds if specified, only these features will be the candidates for adding a ring. Otherwise
all intersecting features are tested and the ring is added to the first valid feature.
@param modifiedFeatureId if specified, feature ID for feature that ring was added to will be stored in this parameter
@return OperationResult result code: success or reason of failure
:rtype: QgsGeometry.OperationResult
%End

int addRing( QgsCurve *ring, const QgsFeatureIds &targetFeatureIds = QgsFeatureIds(), QgsFeatureId *modifiedFeatureId = 0 ) /PyName=addCurvedRing/;
QgsGeometry::OperationResult addRing( QgsCurve *ring, const QgsFeatureIds &targetFeatureIds = QgsFeatureIds(), QgsFeatureId *modifiedFeatureId = 0 ) /PyName=addCurvedRing/;
%Docstring
:rtype: int
Adds a ring to polygon/multipolygon features
@param ring ring to add
@param targetFeatureIds if specified, only these features will be the candidates for adding a ring. Otherwise
all intersecting features are tested and the ring is added to the first valid feature.
@param modifiedFeatureId if specified, feature ID for feature that ring was added to will be stored in this parameter
@return OperationResult result code: success or reason of failure
.. note::

available in python bindings as addCurvedRing
:rtype: QgsGeometry.OperationResult
%End

int addPart( const QList<QgsPointXY> &ring, QgsFeatureId featureId );
QgsGeometry::OperationResult addPart( const QList<QgsPointXY> &ring, QgsFeatureId featureId );
%Docstring
:rtype: int
Adds a new part polygon to a multipart feature
@returns QgsGeometry.OperationResult a result code: success or reason of failure
:rtype: QgsGeometry.OperationResult
%End

int addPart( const QgsPointSequence &ring, QgsFeatureId featureId );
QgsGeometry::OperationResult addPart( const QgsPointSequence &ring, QgsFeatureId featureId );
%Docstring
:rtype: int
Adds a new part polygon to a multipart feature
@returns QgsGeometry.OperationResult a result code: success or reason of failure
.. note::

available in python bindings as addPartV2
:rtype: QgsGeometry.OperationResult
%End

int addPart( QgsCurve *ring, QgsFeatureId featureId ) /PyName=addCurvedPart/;
QgsGeometry::OperationResult addPart( QgsCurve *ring, QgsFeatureId featureId ) /PyName=addCurvedPart/;
%Docstring
:rtype: int
:rtype: QgsGeometry.OperationResult
%End

int translateFeature( QgsFeatureId featureId, double dx, double dy );
@@ -98,14 +120,14 @@ class QgsVectorLayerEditUtils
:rtype: int
%End

int splitParts( const QList<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitParts( const QList<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
:rtype: QgsGeometry.OperationResult
%End

int splitFeatures( const QList<QgsPointXY> &splitLine, bool topologicalEditing = false );
QgsGeometry::OperationResult splitFeatures( const QList<QgsPointXY> &splitLine, bool topologicalEditing = false );
%Docstring
:rtype: int
:rtype: QgsGeometry.OperationResult
%End

int addTopologicalPoints( const QgsGeometry &geom );
@@ -130,15 +152,6 @@ class QgsVectorLayerEditUtils
:rtype: int
%End

protected:

int boundingBoxFromPointList( const QList<QgsPointXY> &list, double &xmin, double &ymin, double &xmax, double &ymax ) const;
%Docstring
Little helper function that gives bounding box from a list of points.
:return: 0 in case of success *
:rtype: int
%End

};

/************************************************************************

0 comments on commit 86e8da7

Please sign in to comment.
You can’t perform that action at this time.