How to implement __eq__ in shapely (python) -


i have question regarding shapely , usage of == operator. there exists function test equality of geometric object: .equals(). == not work.

point((0, 2)).equals(point((0,2)) 

returns true.

however:

point((0, 2)) ==  point((0, 2)) 

returns false

i able use == operator check if point present in list. 1 use case be:

if point not in list_of_points:     list_of_points.append(point) 

as far understand, not work because == returns false. know there exists alternative in using any() function, prefer in keyword:

if not any(point.equals(point) point in list_of_points):     list_of_points.append(point) 

would large effort implement __eq__ in shapely/geometry/base.py? think of naive implementation of __eq__?

class basegeometry(object):     def __eq__(self, other):         return self.equals(other) 

or

class basegeometry(object):     def __eq__(self, other):         return bool(self.impl['equals'](self, other)) 

one side effect of implementing __eq__ point can no longer key in dictionary. if want feature, can add this:

def __hash__(self):     return hash(id(self)) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -