"""Proxy for coordinates stored outside Shapely geometries """ from shapely.geos import lgeos from shapely import wkb EMPTY = wkb.deserialize('010700000000000000'.decode('hex')) class CachingGeometryProxy(object): context = None factory = None __geom__ = EMPTY _gtag = None def __init__(self, context): self.context = context @property def _is_empty(self): return self.__geom__ in [EMPTY, None] def empty(self): if not self._is_empty: lgeos.GEOSGeom_destroy(self.__geom__) self.__geom__ = EMPTY @property def _geom(self): """Keeps the GEOS geometry in synch with the context."""
def __setstate__(self, state): self.empty() self.__geom__ = wkb.deserialize(state)
ob._ndim = 2 return ob def exceptNull(func): """Decorator which helps avoid GEOS operations on null pointers.""" @wraps(func) def wrapper(*args, **kwargs): if not args[0]._geom or args[0].is_empty: raise ValueError("Null/empty geometry supports no operations") return func(*args, **kwargs) return wrapper EMPTY = wkb.deserialize('010700000000000000'.decode('hex')) class BaseGeometry(object): """ Provides GEOS spatial predicates and topological operations. """ # Attributes # ---------- # __geom__ : c_void_p # Cached ctypes pointer to GEOS geometry. Not to be accessed. # _geom : c_void_p # Property by which the GEOS geometry is accessed. # __p__ : object
if lgeos.methods['has_z'](g): ob._ndim = 3 else: ob._ndim = 2 return ob def exceptNull(func): """Decorator which helps avoid GEOS operations on null pointers.""" @wraps(func) def wrapper(*args, **kwargs): if not args[0]._geom or args[0].is_empty: raise ValueError("Null/empty geometry supports no operations") return func(*args, **kwargs) return wrapper EMPTY = wkb.deserialize(bytes.fromhex('010700000000000000')) class BaseGeometry(object): """ Provides GEOS spatial predicates and topological operations. """ # Attributes # ---------- # __geom__ : c_void_p # Cached ctypes pointer to GEOS geometry. Not to be accessed. # _geom : c_void_p # Property by which the GEOS geometry is accessed. # __p__ : object # Parent (Shapely) geometry