1 /*************************************************************************** 2 qgsgeometryeditutils.h 3 ------------------------------------------------------------------- 4 Date : 21 Jan 2015 5 Copyright : (C) 2015 by Marco Hugentobler 6 email : marco.hugentobler at sourcepole dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 #ifndef QGSGEOMETRYEDITUTILS_H 17 #define QGSGEOMETRYEDITUTILS_H 18 19 class QgsAbstractGeometry; 20 class QgsCurve; 21 class QgsGeometryEngine; 22 class QgsVectorLayer; 23 24 #define SIP_NO_FILE 25 26 #include "qgsfeatureid.h" 27 #include "qgis.h" 28 #include <QMap> 29 #include <memory> 30 31 /** 32 * \ingroup core 33 * \class QgsGeometryEditUtils 34 * \brief Convenience functions for geometry editing 35 * \note not available in Python bindings 36 * \since QGIS 2.10 37 */ 38 class QgsGeometryEditUtils 39 { 40 public: 41 42 /** 43 * Add an interior \a ring to a \a geometry. 44 * Ownership of the \a ring is transferred. 45 * \returns 0 in case of success (ring added), 1 problem with geometry type, 2 ring not closed, 46 * 3 ring is not valid geometry, 4 ring not disjoint with existing rings, 5 no polygon found which contained the ring 47 */ 48 static Qgis::GeometryOperationResult addRing( QgsAbstractGeometry *geometry, std::unique_ptr< QgsCurve > ring ); 49 50 /** 51 * Add a \a part to multi type \a geometry. 52 * Ownership of the \a part is transferred. 53 * \returns 0 in case of success, 1 if not a multigeometry, 2 if part is not a valid geometry, 3 if new polygon ring 54 * not disjoint with existing polygons of the feature 55 */ 56 static Qgis::GeometryOperationResult addPart( QgsAbstractGeometry *geometry, std::unique_ptr< QgsAbstractGeometry > part ); 57 58 /** 59 * Deletes a ring from a geometry. 60 * \returns TRUE if delete was successful 61 */ 62 static bool deleteRing( QgsAbstractGeometry *geom, int ringNum, int partNum = 0 ); 63 64 /** 65 * Deletes a part from a geometry. 66 * \returns TRUE if delete was successful 67 */ 68 static bool deletePart( QgsAbstractGeometry *geom, int partNum ); 69 70 /** 71 * Alters a geometry so that it avoids intersections with features from all open vector layers. 72 * \param geom geometry to alter 73 * \param avoidIntersectionsLayers list of layers to check for intersections 74 * \param haveInvalidGeometry returns true if at least one geometry intersected is invalid. In this case, the algorithm may not work and return the same geometry as the input. You must fix your intersecting geometries. 75 * \param ignoreFeatures map of layer to feature id of features to ignore 76 */ 77 static std::unique_ptr< QgsAbstractGeometry > avoidIntersections( const QgsAbstractGeometry &geom, 78 const QList<QgsVectorLayer *> &avoidIntersectionsLayers, 79 bool &haveInvalidGeometry, 80 const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) ); 81 }; 82 83 #endif // QGSGEOMETRYEDITUTILS_H 84