Open nyalldawson opened 7 years ago
+1, clearer indeed.
I like the const/returning better, but I understand the use of modifying geometries inplace, in this case, shouldn't the function return a ref to this, such that one can write:
feature.geometry().buffer(500, 8).transform(QgsCoordinateTransform(source_crs, dest_crs )).simplify(5)
I guess it'll be easier to detect missing /Out/ annotations, so a big +1 from me!
Le mer. 21 juin 2017 à 09:34, Vincent Mora notifications@github.com a écrit :
+1, clearer indeed.
I like the const/returning better, but I understand the use of modifying geometries inplace, in this case, shouldn't the function return a ref to this, such that one can write:
feature.geometry().buffer(500, 8).transform(QgsCoordinateTransform(source_crs, dest_crs )).simplify(5)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/qgis/QGIS-Enhancement-Proposals/issues/96#issuecomment-309988880, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHxGwyQ0xffoG6Ddi5dvTDExnJLuIOpks5sGMehgaJpZM4OAfZH .
On Wed, Jun 21, 2017 at 12:34:57AM -0700, Vincent Mora wrote:
shouldn't the function return a ref to this, such that one can write:
This was my thought as well...
QGIS Enhancement: Rename QgsGeometry methods for clarity
Date 2017/06/21
Author Nyall Dawson @nyalldawson
Contact nyall dot dawson at gmail dot com
Version QGIS 3.0
Summary
The QgsGeometry class has many methods which perform operations on the geometries, including operations like buffers, reprojecting, transformation, etc.
Currently, there's a confusing mix of methods which alter geometries in place vs those which are const and return a new geometry object. This lack of consistency makes use of the QGIS API difficult. E.g. while
works as expected,
doesn't, because rotate is non-const and performed in place, and the rotate method instead returns an int value.
This can lead to extreme confusion when writing PyQGIS scripts - it's difficult to tell where the error in code like
is without resorting to studying the api docs (transform returns an int and modifies in place)
Proposed Solution
This could be remedied by renaming all const methods which return a new geometry to use past tense names, e.g.
QgsGeometry::buffer -> QgsGeometry::buffered QgsGeometry::simplify -> QgsGeometry::simplified
The command tense ("transform"/"rotate"/etc) will be reserved for use solely when the operation is performed in place on a geometry.
Affected Files
qgsgeometry.h/.cpp and all files which use the affected methods
Backwards Compatibility
N/A
Votes
(required)