如何在shapely(python)中实现

2024-04-19 23:15:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于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))

Tags: of函数inselfifnot运算符points