add adapt() + custom args use case to user defined types
Issue #2193
resolved
geoalchemy type:
class GeometryBase(TypeEngine):
"""Base Geometry column type for all spatial databases.
Converts bind/result values to/from a generic Persistent value.
This is used as a base class and overridden into dialect specific
Persistent values.
"""
name = 'GEOMETRY'
def __init__(self, dimension=2, srid=4326, spatial_index=True, **kwargs):
self.dimension = dimension
self.srid = srid
self.spatial_index = spatial_index
self.kwargs = kwargs
super(GeometryBase, self).__init__()
def bind_processor(self, dialect):
def process(value):
if value is not None:
if isinstance(value, SpatialElement):
if isinstance(value.desc, SpatialElement):
return value.desc.desc
return value.desc
else:
return value
else:
return value
return process
def result_processor(self, dialect, coltype=None):
def process(value):
if value is not None:
return PersistentSpatialElement(value)
else:
return value
return process
def _compiler_dispatch(self, *args):
"""Required for the Cast() operator when used for the compilation
of DBSpatialElement"""
return self.name
def adapt(self, cls, **kwargs):
return cls(dimension=self.dimension, srid=self.srid,
spatial_index=self.spatial_index,
**self.kwargs)
also figure out what that _compiler_dispatch is about.
Comments (5)
-
Account Deleted -
reporter - changed milestone to 0.7.5
-
reporter the _compiler_dispatch is because they're extending
TypeEngine
and notUserDefinedType
. -
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.7.5 (automated comment)
- Log in to comment
Before commit, to be closer with what we do in GeoAlchemy, we could make init call its superclass: