The cause for your error is the fact that you are attempting to access coordinates using
point[...] which does not work on objects of user defined classes which do not implement the
__getitem__ magic method.
So, start by adding a
__getitem__ method to your class.
def __init__(self, x, y):
self.x = float(x)
self.y = float(y)
def __getitem__(self, idx):
return [self.x, self.y][idx]
raise ValueError("Invalid Index") from None
Note to readers -
raise ... from None is supported from python3 onwards. For older versions, use
raise ValueError("Invalid Index").
Now, your existing code should work.
>>> p = Point(1, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 9, in __getitem__
ValueError: Invalid Index
As an aside, you should seriously consider the use of
LineString.bounds method is also flawed. My guess is you want to find the min/max across all points. If that's the case, you're supposed to first get all the coordinates, and call
min outside the loop.
X = [p for p in points]
y = [p[-1] for p in points]
return min(y), min(X), max(y), max(X)