Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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))
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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()
share|improve this answer
    
on a (un)related note,can you help me with this too? 'qaz[0] (227739,908343) type(qaz[0]) <class 'qgis.core.QgsPoint'> wxs[0] (227739,908343) type(wxs[0]) <class 'qgis.core.QgsPoint'> qaz[0]==wxs[0] False' –  PeterBorook Apr 2 '13 at 18:18
    
so what is the output of qaz[0].equals(wxs[0]) ? –  Curlew Apr 2 '13 at 18:23
    
AttributeError: 'QgsPoint' object has no attribute 'equals' –  PeterBorook Apr 2 '13 at 18:23
    
so add the same code before your point to get a QgsGeometry Object --> a = QgsGeometry.fromPoint(qaz[0]) –  Curlew Apr 2 '13 at 18:25
    
>>> q= QgsGeometry.fromPoint(qaz[0]) >>> w= QgsGeometry.fromPoint(wxs[0]) q.equals(w) False –  PeterBorook Apr 2 '13 at 18:30
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.