Skip to content
Permalink
Browse files

Refine QgsFeature geometry getters/setters

All pointer based methods have been removed.

Now we have only:

  void setGeometry( const QgsGeometry& geom )

and

  QgsGeometry geometry() const

Benefits include avoiding a whole lot of tricky pointer lifetime
issues, potential memory leaks, and finally closing #777, which
has survived for over 9 years!...

Impacts on PyQGIS code:
- no more need for the messy
  g = QgsGeometry( feature.geometry() )
  workaround, just use g = feature.geometry() instead
- IMPORTANT: you can no longer test whether a feature has geometry
 using `if f.geometry():`, since QgsFeature::geometry() will
 *always* return an object. Instead, use
 `if not f.geometry().isEmpty():`, or preferably the new method
 `if not f.hasGeometry():`

Fix #777
  • Loading branch information
nyalldawson committed Aug 1, 2016
1 parent aceddae commit bd7d913379b68a8104608b1afab4d380e4edc26b
Showing with 1,377 additions and 1,313 deletions.
  1. +29 −0 doc/api_break.dox
  2. +2 −2 python/analysis/vector/qgsgeometryanalyzer.sip
  3. +8 −0 python/core/geometry/qgsgeometry.sip
  4. +22 −31 python/core/qgsfeature.sip
  5. +4 −4 python/core/qgspallabeling.sip
  6. +1 −1 python/core/qgsvectordataprovider.sip
  7. +1 −11 python/core/qgsvectorlayer.sip
  8. +1 −1 python/core/qgsvectorlayereditutils.sip
  9. +1 −1 python/gui/qgshighlight.sip
  10. +2 −2 python/plugins/db_manager/db_plugins/vlayers/data_model.py
  11. +4 −4 python/plugins/processing/algs/qgis/Buffer.py
  12. +1 −1 python/plugins/processing/algs/qgis/Centroids.py
  13. +2 −2 python/plugins/processing/algs/qgis/CheckValidity.py
  14. +5 −5 python/plugins/processing/algs/qgis/Clip.py
  15. +2 −2 python/plugins/processing/algs/qgis/ConvexHull.py
  16. +2 −2 python/plugins/processing/algs/qgis/Delaunay.py
  17. +1 −1 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
  18. +1 −1 python/plugins/processing/algs/qgis/DeleteHoles.py
  19. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometries.py
  20. +1 −1 python/plugins/processing/algs/qgis/DensifyGeometriesInterval.py
  21. +2 −2 python/plugins/processing/algs/qgis/Difference.py
  22. +5 −5 python/plugins/processing/algs/qgis/Dissolve.py
  23. +2 −2 python/plugins/processing/algs/qgis/Eliminate.py
  24. +1 −2 python/plugins/processing/algs/qgis/FieldsMapper.py
  25. +2 −2 python/plugins/processing/algs/qgis/Intersection.py
  26. +1 −1 python/plugins/processing/algs/qgis/LinesIntersection.py
  27. +1 −1 python/plugins/processing/algs/qgis/OrientedMinimumBoundingBox.py
  28. +1 −1 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  29. +1 −1 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  30. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsFixed.py
  31. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygonsVariable.py
  32. +6 −6 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsFixed.py
  33. +6 −6 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  34. +2 −2 python/plugins/processing/algs/qgis/ReverseLineDirection.py
  35. +2 −2 python/plugins/processing/algs/qgis/SelectByAttributeSum.py
  36. +1 −1 python/plugins/processing/algs/qgis/SimplifyGeometries.py
  37. +1 −1 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
  38. +1 −1 python/plugins/processing/algs/qgis/Smooth.py
  39. +2 −2 python/plugins/processing/algs/qgis/SplitLinesWithLines.py
  40. +2 −2 python/plugins/processing/algs/qgis/SumLines.py
  41. +4 −4 python/plugins/processing/algs/qgis/SymmetricalDifference.py
  42. +4 −4 python/plugins/processing/algs/qgis/Union.py
  43. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
  44. +1 −1 python/plugins/processing/tests/ToolsTest.py
  45. +2 −2 python/testing/__init__.py
  46. +5 −5 src/analysis/interpolation/qgsinterpolator.cpp
  47. +1 −1 src/analysis/interpolation/qgsinterpolator.h
  48. +4 −4 src/analysis/interpolation/qgstininterpolator.cpp
  49. +8 −8 src/analysis/network/qgslinevectorlayerdirector.cpp
  50. +28 −29 src/analysis/vector/qgsgeometryanalyzer.cpp
  51. +2 −2 src/analysis/vector/qgsgeometryanalyzer.h
  52. +7 −8 src/analysis/vector/qgsoverlayanalyzer.cpp
  53. +3 −3 src/analysis/vector/qgspointsample.cpp
  54. +30 −37 src/analysis/vector/qgstransectsample.cpp
  55. +3 −3 src/analysis/vector/qgstransectsample.h
  56. +10 −11 src/analysis/vector/qgszonalstatistics.cpp
  57. +2 −2 src/analysis/vector/qgszonalstatistics.h
  58. +1 −1 src/app/composer/qgscomposer.cpp
  59. +1 −1 src/app/gps/qgsgpsinformationwidget.cpp
  60. +6 −6 src/app/nodetool/qgsmaptoolnodetool.cpp
  61. +2 −2 src/app/nodetool/qgsselectedfeature.cpp
  62. +12 −12 src/app/qgisapp.cpp
  63. +4 −4 src/app/qgsclipboard.cpp
  64. +4 −4 src/app/qgsidentifyresultsdialog.cpp
  65. +4 −4 src/app/qgsmaptooladdfeature.cpp
  66. +10 −10 src/app/qgsmaptooldeletepart.cpp
  67. +14 −14 src/app/qgsmaptooldeletering.cpp
  68. +2 −2 src/app/qgsmaptooldeletering.h
  69. +4 −4 src/app/qgsmaptoollabel.cpp
  70. +4 −4 src/app/qgsmaptoolmovefeature.cpp
  71. +11 −13 src/app/qgsmaptooloffsetcurve.cpp
  72. +1 −1 src/app/qgsmaptooloffsetcurve.h
  73. +1 −1 src/app/qgsmaptoolreshape.cpp
  74. +8 −8 src/app/qgsmaptoolrotatefeature.cpp
  75. +2 −2 src/app/qgsmaptoolselectutils.cpp
  76. +13 −13 src/app/qgsmaptoolsimplify.cpp
  77. +1 −1 src/app/qgsmaptoolsimplify.h
  78. +1 −1 src/app/qgsmergeattributesdialog.cpp
  79. +4 −4 src/core/composer/qgsatlascomposition.cpp
  80. +3 −3 src/core/composer/qgscomposerattributetablev2.cpp
  81. +3 −2 src/core/dxf/qgsdxfexport.cpp
  82. +99 −0 src/core/geometry/qgsgeometry.cpp
  83. +34 −0 src/core/geometry/qgsgeometry.h
  84. +2 −2 src/core/geometry/qgsgeometryeditutils.cpp
  85. +27 −1 src/core/qgsdistancearea.cpp
  86. +33 −0 src/core/qgsdistancearea.h
  87. +30 −26 src/core/qgsexpression.cpp
  88. +1 −1 src/core/qgsexpressioncontext.cpp
  89. +12 −24 src/core/qgsfeature.cpp
  90. +21 −38 src/core/qgsfeature.h
  91. +5 −10 src/core/qgsfeature_p.h
  92. +1 −1 src/core/qgsfeaturerequest.cpp
  93. +6 −6 src/core/qgsgml.cpp
  94. +8 −15 src/core/qgsjsonutils.cpp
  95. +1 −1 src/core/qgsmaphittest.cpp
  96. +1 −1 src/core/qgsogrutils.cpp
  97. +52 −77 src/core/qgspallabeling.cpp
  98. +4 −4 src/core/qgspallabeling.h
  99. +8 −8 src/core/qgspointlocator.cpp
  100. +2 −2 src/core/qgsspatialindex.cpp
  101. +14 −15 src/core/qgstracer.cpp
  102. +3 −3 src/core/qgsvectordataprovider.cpp
  103. +1 −1 src/core/qgsvectordataprovider.h
  104. +8 −8 src/core/qgsvectorfilewriter.cpp
  105. +23 −67 src/core/qgsvectorlayer.cpp
  106. +2 −12 src/core/qgsvectorlayer.h
  107. +8 −8 src/core/qgsvectorlayerdiagramprovider.cpp
  108. +24 −24 src/core/qgsvectorlayereditutils.cpp
  109. +1 −1 src/core/qgsvectorlayereditutils.h
  110. +2 −2 src/core/qgsvectorlayerfeatureiterator.cpp
  111. +4 −4 src/core/qgsvectorlayerimport.cpp
  112. +5 −5 src/core/qgsvectorlayerlabelprovider.cpp
  113. +6 −6 src/core/qgsvectorlayerrenderer.cpp
  114. +7 −7 src/core/qgsvectorlayerundocommand.cpp
  115. +2 −2 src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
  116. +2 −2 src/core/symbology-ng/qgsfillsymbollayerv2.cpp
  117. +4 −8 src/core/symbology-ng/qgsheatmaprenderer.cpp
  118. +16 −21 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  119. +1 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.h
  120. +2 −2 src/core/symbology-ng/qgslinesymbollayerv2.cpp
  121. +3 −6 src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
  122. +4 −4 src/core/symbology-ng/qgsnullsymbolrenderer.cpp
  123. +5 −5 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  124. +30 −35 src/core/symbology-ng/qgssymbolv2.cpp
  125. +4 −4 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
  126. +8 −8 src/gui/qgshighlight.cpp
  127. +2 −2 src/gui/qgshighlight.h
  128. +1 −1 src/gui/qgsidentifymenu.cpp
  129. +4 −4 src/gui/qgsmapcanvas.cpp
  130. +2 −2 src/gui/qgsmaptoolcapture.cpp
  131. +14 −14 src/gui/qgsmaptoolidentify.cpp
  132. +2 −2 src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp
  133. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
  134. +5 −5 src/plugins/geometry_checker/checks/qgsgeometryareacheck.cpp
  135. +5 −5 src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
  136. +5 −5 src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp
  137. +2 −2 src/plugins/geometry_checker/checks/qgsgeometrydegeneratepolygoncheck.cpp
  138. +5 −5 src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp
  139. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp
  140. +4 −4 src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
  141. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryholecheck.cpp
  142. +2 −2 src/plugins/geometry_checker/checks/qgsgeometrymultipartcheck.cpp
  143. +8 −8 src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp
  144. +2 −2 src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp
  145. +2 −2 src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp
  146. +2 −2 src/plugins/geometry_checker/checks/qgsgeometrytypecheck.cpp
  147. +1 −1 src/plugins/geometry_checker/qgsgeometrychecker.cpp
  148. +1 −1 src/plugins/geometry_checker/utils/qgsfeaturepool.cpp
  149. +6 −6 src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
  150. +4 −4 src/plugins/heatmap/heatmap.cpp
  151. +2 −2 src/plugins/spatialquery/qgsrubberselectid.cpp
  152. +9 −9 src/plugins/spatialquery/qgsspatialquery.cpp
  153. +4 −4 src/plugins/spatialquery/qgsspatialquerydialog.cpp
  154. +11 −11 src/plugins/topology/checkDock.cpp
  155. +10 −9 src/plugins/topology/topolError.cpp
  156. +60 −60 src/plugins/topology/topolTest.cpp
  157. +2 −2 src/providers/arcgisrest/qgsafsprovider.cpp
  158. +2 −2 src/providers/db2/qgsdb2featureiterator.cpp
  159. +2 −2 src/providers/db2/qgsdb2provider.cpp
  160. +3 −3 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  161. +2 −2 src/providers/gpx/qgsgpxprovider.cpp
  162. +13 −13 src/providers/grass/qgis.v.in.cpp
  163. +2 −2 src/providers/grass/qgsgrassimport.cpp
  164. +5 −10 src/providers/grass/qgsgrassprovider.cpp
  165. +3 −3 src/providers/memory/qgsmemoryfeatureiterator.cpp
  166. +2 −2 src/providers/memory/qgsmemoryprovider.cpp
  167. +2 −2 src/providers/mssql/qgsmssqlfeatureiterator.cpp
  168. +4 −4 src/providers/mssql/qgsmssqlprovider.cpp
  169. +5 −5 src/providers/ogr/qgsogrfeatureiterator.cpp
  170. +3 −3 src/providers/ogr/qgsogrprovider.cpp
  171. +5 −5 src/providers/oracle/qgsoraclefeatureiterator.cpp
  172. +8 −12 src/providers/oracle/qgsoracleprovider.cpp
  173. +1 −1 src/providers/oracle/qgsoracleprovider.h
  174. +1 −1 src/providers/postgres/qgspostgresfeatureiterator.cpp
  175. +7 −7 src/providers/postgres/qgspostgresprovider.cpp
  176. +1 −1 src/providers/postgres/qgspostgresprovider.h
  177. +3 −3 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  178. +3 −3 src/providers/spatialite/qgsspatialiteprovider.cpp
  179. +1 −1 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
  180. +3 −3 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  181. +14 −14 src/providers/wfs/qgswfsfeatureiterator.cpp
  182. +6 −6 src/providers/wfs/qgswfsprovider.cpp
  183. +10 −10 src/providers/wfs/qgswfsshareddata.cpp
  184. +4 −4 src/providers/wfs/qgswfsutils.cpp
  185. +4 −4 src/providers/wms/qgswmsprovider.cpp
  186. +14 −14 src/server/qgswfsserver.cpp
  187. +4 −4 src/server/qgswmsserver.cpp
  188. +11 −9 tests/src/app/testqgisappclipboard.cpp
  189. +3 −3 tests/src/app/testqgsmaptoolidentifyaction.cpp
  190. +4 −2 tests/src/core/testqgsconnectionpool.cpp
  191. +13 −13 tests/src/core/testqgsfeature.cpp
  192. +75 −75 tests/src/core/testqgsgml.cpp
  193. +19 −16 tests/src/core/testqgsogrutils.cpp
  194. +1 −1 tests/src/core/testqgspointlocator.cpp
  195. +5 −5 tests/src/core/testqgsvectordataprovider.cpp
  196. +6 −5 tests/src/providers/grass/testqgsgrassprovider.cpp
  197. +3 −3 tests/src/python/providertestbase.py
  198. +5 −5 tests/src/python/test_provider_ogr.py
  199. +1 −1 tests/src/python/test_provider_shapefile.py
  200. +1 −1 tests/src/python/test_provider_virtual.py
  201. +2 −2 tests/src/python/test_qgsdelimitedtextprovider.py
  202. +9 −9 tests/src/python/test_qgsjsonutils.py
@@ -218,15 +218,34 @@ attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
<li>geometryAndOwnership() has been removed. Use geometry() instead.</li>
<li>setGeometryAndOwnership() has been removed. Use setGeometry() instead.</li>
<li>The setGeometry( QgsGeometry* ) method has been removed, use setGeometry( const QgsGeometry& ) instead.</li>
<li>The geometry() method now returns a copy of the geometry, not a pointer. Since QgsGeometry objects are
implicitly shared this is a low-cost copy, and avoids ownership and dangling pointer issues. <b>Very important: Testing that
a feature has a geometry is now done using the new hasGeometry() method. QgsFeature::geometry() will ALWAYS return
true, as the method will return an empty geometry if the feature has no geometry.</b></li>
<li>The temporary constGeometry() method has been removed. Use geometry() instead.</li>
<li>setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGeometryAnalyzer QgsGeometryAnalyzer

<ul>
<li>locateBetweenMeasures() and locateAlongMeasure() now take geometry references, not pointers</li>
</ul>

\subsection qgis_api_break_3_0_QgsGroupWMSDataDialog QgsGroupWMSDataDialog

<ul>
<li>QgsGroupWMSDataDialo has been renamed to QgsGroupWmsDataDialog</li>
</ul>

\subsection qgis_api_break_3_0_QgsHighlight QgsHighlight

<ul>
<li>The QgsHighlight constructor now takes a geometry reference, not a pointer.</li>
</ul>



\subsection qgis_api_break_3_0_QgsVectorDataProvider QgsVectorDataProvider

<ul>
@@ -236,6 +255,7 @@ only affects third party c++ providers, and does not affect PyQGIS scripts.</li>
<li>The SaveAsShapefile, SelectGeometryAtId, RandomSelectGeometryAtId and SequentialSelectGeometryAtId
capabilities have been removed, as they were unused and had no effect.</li>
<li>capabilities() now returns a typesafe QgsVectorDataProvider::Capabilities object, not an integer.</li>
<li>convertToProviderType() now takes a geometry reference, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsLabelingEngineInterface QgsLabelingEngineInterface
@@ -331,6 +351,7 @@ be returned instead of a null pointer if no transformation is required.</li>

<ul>
<li>init(QgsMapRenderer*) has been removed. Use init(const QgsMapSettings&) instead.</li>
<li>prepareGeometry and geometryRequiresPreparation now take geometry references, not pointers.</li>
</ul>

\subsection qgis_api_break_3_0_QgsOSMElement QgsOSMElement
@@ -435,6 +456,8 @@ setExcludeAttributesWms()</li>
setExcludeAttributesWfs()</li>
<li>changeGeometry() now accepts a geometry reference, not a pointer.</li>
<li>The geometryChanged() signal now uses a const QgsGeometry reference.</li>
<li>The deprecated removePolygonIntersections has been removed.</li>
<li>addTopologicalPoints() now takes a geometry reference, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer
@@ -444,6 +467,12 @@ setExcludeAttributesWfs()</li>
<li>The geometryChanged() signal now uses a const QgsGeometry reference.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerEditUtils QgsVectorLayerEditUtils

<ul>
<li>addTopologicalPoints() now accepts a geometry reference, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerImport QgsVectorLayerImport

<ul>
@@ -95,10 +95,10 @@ class QgsGeometryAnalyzer
bool forceSingleGeometry = false, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );

/** Returns linear reference geometry as a multiline (or 0 if no match). Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)*/
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry* lineGeom );
QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry& lineGeom );
/** Returns linear reference geometry. Unlike the PostGIS function, this method always returns multipoint or 0 if no match (not geometry collection).
* Currently, the z-coordinates are considered to be the measures (no support for m-values in QGIS)
*/
QgsGeometry* locateAlongMeasure( double measure, const QgsGeometry* lineGeom );
QgsGeometry* locateAlongMeasure( double measure, const QgsGeometry& lineGeom );

};
@@ -393,6 +393,14 @@ class QgsGeometry
*/
int makeDifference( const QgsGeometry* other );

/** Returns the geometry formed by modifying this geometry such that it does not
* intersect the other geometry.
* @param other geometry that should not be intersect
* @return difference geometry, or empty geometry if difference could not be calculated
* @note added in QGIS 3.0
*/
QgsGeometry makeDifference( const QgsGeometry& other ) const;

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

@@ -322,41 +322,32 @@ class QgsFeature
*/
void setValid( bool validity );

/** Get the geometry object associated with this feature. If the geometry
* is not going to be modified than calling the const @link constGeometry @endlink
* method is preferable as it avoids a potentially expensive detach operation.
*
* It is possible to modify the geometry in place but this will
* be removed in 3.0 and therefore @link setGeometry @endlink should be called explicitly.
*
* @note will be modified to return by value in QGIS 3.0: `QgsGeometry geometry() const;`
*
* @returns pointer to feature's geometry
* @see constGeometry
* @see setGeometry
/** Returns true if the feature has an associated geometry.
* @see geometry()
* @note added in QGIS 3.0.
*/
QgsGeometry* geometry();

/** Gets a const pointer to the geometry object associated with this feature. If the geometry
* is not going to be modified than this method is preferable to the non-const
* @link geometry @endlink method.
* @note this is a temporary method for 2.x release cycle. Will be removed in QGIS 3.0.
* @returns const pointer to feature's geometry
* @see geometry
* @see geometryAndOwnership
* @see setGeometry
* @note added in QGIS 2.9
* @note will be removed in QGIS 3.0
bool hasGeometry() const;

/** Returns the geometry associated with this feature. If the feature has no geometry,
* an empty QgsGeometry object will be returned.
* @see hasGeometry()
* @see setGeometry()
*/
QgsGeometry geometry() const;

/** Set the feature's geometry.
* @param geometry new feature geometry
* @see geometry()
* @see clearGeometry()
*/
const QgsGeometry* constGeometry() const;
void setGeometry( const QgsGeometry& geometry );

/** Set this feature's geometry from another QgsGeometry object. This method performs a deep copy
* of the geometry.
* @param geom new feature geometry
* @see geometry
* @see constGeometry
/** Removes any geometry associated with the feature.
* @see setGeometry()
* @see hasGeometry()
* @note added in QGIS 3.0
*/
void setGeometry( const QgsGeometry& geom );
void clearGeometry();

/** Assign a field map with the feature to allow attribute access by attribute name.
* @param fields The attribute fields which this feature holds
@@ -991,10 +991,10 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @param context render context
* @param ct coordinate transform, or invalid transform if no transformation required
* @param clipGeometry geometry to clip features to, if applicable
* @returns prepared geometry, the caller takes ownership
* @returns prepared geometry
* @note added in QGIS 2.9
*/
static QgsGeometry* prepareGeometry( const QgsGeometry *geometry, QgsRenderContext &context, const QgsCoordinateTransform& ct, QgsGeometry *clipGeometry = 0 ) /Factory/;
static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform& ct, QgsGeometry *clipGeometry = 0 ) /Factory/;

/** Checks whether a geometry requires preparation before registration with PAL
* @param geometry geometry to prepare
@@ -1004,7 +1004,7 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @returns true if geometry requires preparation
* @note added in QGIS 2.9
*/
static bool geometryRequiresPreparation( const QgsGeometry *geometry, QgsRenderContext &context, const QgsCoordinateTransform& ct, QgsGeometry *clipGeometry = 0 );
static bool geometryRequiresPreparation( const QgsGeometry& geometry, QgsRenderContext &context, const QgsCoordinateTransform& ct, QgsGeometry *clipGeometry = 0 );

/** Splits a text string to a list of separate lines, using a specified wrap character.
* The text string will be split on either newline characters or the wrap character.
@@ -1054,5 +1054,5 @@ class QgsPalLabeling : QgsLabelingEngineInterface
* @returns true if geometry exceeds minimum size
* @note added in QGIS 2.9
*/
static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize );
static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry* geom, double minSize );
};
@@ -385,7 +385,7 @@ class QgsVectorDataProvider : QgsDataProvider

/** Converts the geometry to the provider type if possible / necessary
@return the converted geometry or nullptr if no conversion was necessary or possible*/
QgsGeometry* convertToProviderType( const QgsGeometry* geom ) const /Factory/;
QgsGeometry* convertToProviderType( const QgsGeometry& geom ) const /Factory/;
};

QFlags<QgsVectorDataProvider::Capability> operator|(QgsVectorDataProvider::Capability f1, QFlags<QgsVectorDataProvider::Capability> f2);
@@ -763,22 +763,12 @@ class QgsVectorLayer : QgsMapLayer
*/
int splitFeatures( const QList<QgsPoint>& splitLine, bool topologicalEditing = false );

/** Changes the specified geometry such that it has no intersections with other
* polygon (or multipolygon) geometries in this vector layer
* @param geom geometry to modify
* @param ignoreFeatures list of feature ids where intersections should be ignored
* @return 0 in case of success
*
* @deprecated since 2.2 - not being used for "avoid intersections" functionality anymore
*/
int removePolygonIntersections( QgsGeometry* geom, const QgsFeatureIds& ignoreFeatures = QgsFeatureIds() ) /Deprecated/;

/** Adds topological points for every vertex of the geometry.
* @param geom the geometry where each vertex is added to segments of other features
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( const QgsGeometry* geom );
int addTopologicalPoints( const QgsGeometry& geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
@@ -138,7 +138,7 @@ class QgsVectorLayerEditUtils
* @note geom is not going to be modified by the function
* @return 0 in case of success
*/
int addTopologicalPoints( const QgsGeometry *geom );
int addTopologicalPoints( const QgsGeometry& geom );

/** Adds a vertex to segments which intersect point p but don't
* already have a vertex there. If a feature already has a vertex at position p,
@@ -4,7 +4,7 @@ class QgsHighlight : QgsMapCanvasItem
#include <qgshighlight.h>
%End
public:
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry *geom, QgsVectorLayer *layer );
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry& geom, QgsVectorLayer *layer );
~QgsHighlight();

/** Set line/outline to color, polygon fill to color with alpha = 63.
@@ -48,7 +48,7 @@ def __init__(self, table, parent=None):
for f in self.layer.getFeatures():
a = f.attributes()
# add the geometry type
if f.geometry():
if f.hasGeometry():
a.append(QgsWKBTypes.displayString(Qgis.fromOldWkbType(f.geometry().wkbType())))
else:
a.append('None')
@@ -97,7 +97,7 @@ def __init__(self, db, sql, parent=None):
for f in p.getFeatures():
a = f.attributes()
if has_geometry:
if f.geometry():
if f.hasGeometry():
a += [f.geometry().exportToWkt()]
else:
a += [None]
@@ -56,8 +56,8 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve,
else:
value = distance

inGeom = QgsGeometry(inFeat.geometry())
if inGeom.isGeosEmpty():
inGeom = inFeat.geometry()
if inGeom.isEmpty() or inGeom.isGeosEmpty():
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, 'Feature {} has empty geometry. Skipping...'.format(inFeat.id()))
continue
if not inGeom.isGeosValid():
@@ -84,8 +84,8 @@ def buffering(progress, writer, distance, field, useField, layer, dissolve,
value = attrs[field]
else:
value = distance
inGeom = QgsGeometry(inFeat.geometry())
if inGeom.isGeosEmpty():
inGeom = inFeat.geometry()
if inGeom.isEmpty() or inGeom.isGeosEmpty():
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING, 'Feature {} has empty geometry. Skipping...'.format(inFeat.id()))
continue
if not inGeom.isGeosValid():
@@ -75,7 +75,7 @@ def processAlgorithm(self, progress):
inGeom = feat.geometry()
attrs = feat.attributes()

if not inGeom:
if inGeom.isEmpty():
outGeom = QgsGeometry(None)
else:
outGeom = QgsGeometry(inGeom.centroid())
@@ -135,11 +135,11 @@ def doCheck(self, progress):
features = vector.features(layer)
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
geom = QgsGeometry(inFeat.geometry())
geom = inFeat.geometry()
attrs = inFeat.attributes()

valid = True
if not geom.isGeosEmpty():
if not geom.isEmpty() and not geom.isGeosEmpty():
errors = list(geom.validateGeometry())
if errors:
# QGIS method return a summary at the end
@@ -81,7 +81,7 @@ def processAlgorithm(self, progress):
total = 100.0 / len(selectionA)

for current, inFeatA in enumerate(selectionA):
geom = QgsGeometry(inFeatA.geometry())
geom = inFeatA.geometry()
attrs = inFeatA.attributes()
intersects = index.intersects(geom.boundingBox())
first = True
@@ -91,16 +91,16 @@ def processAlgorithm(self, progress):
layerB.getFeatures(
QgsFeatureRequest().setFilterFid(i)).nextFeature(
inFeatB)
tmpGeom = QgsGeometry(inFeatB.geometry())
tmpGeom = inFeatB.geometry()
if tmpGeom.intersects(geom):
found = True
if first:
outFeat.setGeometry(QgsGeometry(tmpGeom))
first = False
else:
cur_geom = QgsGeometry(outFeat.geometry())
cur_geom = outFeat.geometry()
new_geom = QgsGeometry(cur_geom.combine(tmpGeom))
if new_geom.isGeosEmpty() or not new_geom.isGeosValid():
if new_geom.isEmpty() or new_geom.isGeosEmpty() or not new_geom.isGeosValid():
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('GEOS geoprocessing error: One or '
'more input features have invalid '
@@ -109,7 +109,7 @@ def processAlgorithm(self, progress):

outFeat.setGeometry(QgsGeometry(new_geom))
if found:
cur_geom = QgsGeometry(outFeat.geometry())
cur_geom = outFeat.geometry()
new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == Qgis.WKBUnknown or QgsWKBTypes.flatType(new_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom))
@@ -121,7 +121,7 @@ def processAlgorithm(self, progress):
val = idVar
first = False

inGeom = QgsGeometry(f.geometry())
inGeom = f.geometry()
points = vector.extractPoints(inGeom)
hull.extend(points)
current += 1
@@ -144,7 +144,7 @@ def processAlgorithm(self, progress):
total = 100.0 / layer.featureCount()
features = vector.features(layer)
for current, f in enumerate(features):
inGeom = QgsGeometry(f.geometry())
inGeom = f.geometry()
points = vector.extractPoints(inGeom)
hull.extend(points)
progress.setPercentage(int(current * total))
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
features = vector.features(layer)
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
geom = QgsGeometry(inFeat.geometry())
geom = inFeat.geometry()
point = geom.asPoint()
x = point.x()
y = point.y()
@@ -110,7 +110,7 @@ def processAlgorithm(self, progress):
for index in indicies:
request = QgsFeatureRequest().setFilterFid(ptDict[ids[index]])
inFeat = layer.getFeatures(request).next()
geom = QgsGeometry(inFeat.geometry())
geom = inFeat.geometry()
point = QgsPoint(geom.asPoint())
polygon.append(point)
if step <= 3:
@@ -59,7 +59,7 @@ def processAlgorithm(self, progress):
total = 100.0 / len(features)
geoms = dict()
for current, f in enumerate(features):
geoms[f.id()] = QgsGeometry(f.geometry())
geoms[f.id()] = f.geometry()
progress.setPercentage(int(current * total))

cleaned = dict(geoms)
@@ -59,7 +59,7 @@ def processAlgorithm(self, progress):
feat = QgsFeature()
for current, f in enumerate(features):
geometry = f.geometry()
if geometry:
if not geometry.isEmpty():
if geometry.isMultipart():
multi_polygon = geometry.asMultiPolygon()
for polygon in multi_polygon:

0 comments on commit bd7d913

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