Toblerity/Shapely — pull request #34 by pelson (2012-11-19 14:29:19+00:00)
Title: Fixed handling of geom._geom is None

I have some code which produces some geometries which end up having ```poly._geom is None``` which essentially mean that all operations result in a ```ValueError```:

```
>>> import shapely.geometry as sgeom
>>> p = sgeom.Polygon(None)
>>> p._geom = None
>>> p.is_empty
Traceback (most recent call last):
File "", line 1, in
File "shapely/geometry/base.py", line 389, in is_empty
return bool(self.impl['is_empty'](self)) or (self._geom is None)
File "shapely/predicates.py", line 21, in __call__
self._validate(this)
File "shapely/topology.py", line 16, in _validate
raise ValueError("Null geometry supports no operations")
ValueError: Null geometry supports no operations

```

Its fairly hard in my code to track down the precise reasons that such a case is happening, but it seems that the ```is_empty``` property is trying to catch it, but failing. This patch means that the following now works:

```
>>> import shapely.geometry as sgeom
>>> p = sgeom.Polygon(None)
>>> p._geom = None
>>> p.is_empty
True
```

I have not tried to be cleverer than that (I just want a published way of finding out if I can do anything with my geometry), so the following still fails (I would expect this to fail):

```

>>> p.area
Traceback (most recent call last):
File "", line 1, in
File "shapely/geometry/base.py", line 254, in area
return self.impl['area'](self)
File "shapely/topology.py", line 34, in __call__
self._validate(this)
File "shapely/topology.py", line 16, in _validate
raise ValueError("Null geometry supports no operations")
ValueError: Null geometry supports no operations
```

Thanks,