Sunday, 12 July 2015

qgis - How to check if two qgsPoints are equal in PyQgis


I have two points:


a=QgsGeometry.fromPoint(QgsPoint(227739,908343))
b=QgsGeometry.fromPoint(QgsPoint(227739,908343))


but when I run:


a==b

it returns False. What am I doing wrong?


Update:


it returns True when I only use:


a=(QgsPoint(227739,908343))
b=(QgsPoint(227739,908343))

Answer




Instead of using ==, just use the following command:


a=QgsGeometry.fromPoint(QgsPoint(227739,908343))
b=QgsGeometry.fromPoint(QgsPoint(227739,908343))

a.equals(b) # -> returns True

EDIT:
Regarding to the comments on this answer:


 a = QgsPoint(227739,908343)
b = QgsPoint(227739,908343)

a == b # TRUE
aa = QgsGeometry.fromPoint(a)
bb = QgsGeometry.fromPoint(b)
aa.equals(bb) # TRUE

Try to investigate the type of your points (are they really QgsPoints?) and if it still doesn't work, than compare the values manually


a.x() == b.x()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...