我有一个关于shapely和{.equals()
。但是==
不起作用。在
Point((0, 2)).equals(Point((0,2))
返回True。在
但是:
^{pr2}$返回False
我希望能够使用==
运算符来检查列表中是否已经存在Point
。一个用例可以是:
if Point not in list_of_points:
list_of_points.append(Point)
据我所知,这不起作用,因为==
返回{any()
函数可以替代in
,但我更喜欢in
关键字:
if not any(Point.equals(point) for point in list_of_points):
list_of_points.append(Point)
在shapely/geometry/base.py
中实现__eq__
会是一个很大的努力吗?
你觉得这是什么?在
class BaseGeometry(object):
def __eq__(self, other):
return self.equals(other)
或者
class BaseGeometry(object):
def __eq__(self, other):
return bool(self.impl['equals'](self, other))
实现
__eq__
的一个副作用是,点不再是字典中的键。如果需要该功能,可以添加以下内容:相关问题 更多 >
编程相关推荐