On 2/19/2022 6:03 PM, Asim al-sofi
wrote:
Hi everyoneI have a problem rounding off the QgsPointXY to say 3 decimals? How can I do that?If I use the numpy.round(point,decimals) then I get an np.array back as a type and not a QgsPointXY.Can someone help?
Kind regardsAsim
what are you trying to achieve? Keep in mind that in general decimal fractions do not have exact representations in floating point, so if you round a coordinate to 3 decimals, store it somewhere, then print it, there will almost certainly be more than three numbers past the decimal point. If it's the printed representation of the number that matters, deal with it in the formatting of the printed representation.
That said, you set() method of QgsPointXY to set the values to their rounded values. If my_pt is a QgsPointXY, then
my_pt.set(round(my_pt.x(), 3), round(my_pt.y(), 3))
_______________________________________________ Qgis-user mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
