'Retrieve the proxied geometry or raster with the corresponding class
specified during initialization.
To set geometries, use values of None, HEXEWKB, or WKT.
To set rasters, use JSON or dict values.'

def __set__(self, instance, value):

    gtype = self._field.geom_type
    if ((gtype == 'RASTER') and ((value is None) or isinstance(value, (str, dict, self._klass)))):
        pass
    elif (isinstance(value, self._klass) and ((str(value.geom_type).upper() == gtype) or (gtype == 'GEOMETRY'))):
        if (value.srid is None):
            value.srid = self._field.srid
    elif ((value is None) or isinstance(value, (str, memoryview))):
        pass
    else:
        raise TypeError(('Cannot    set    %s    SpatialProxy    (%s)    with    value    of    type:    %s' % (instance.__class__.__name__, gtype, type(value))))
    instance.__dict__[self._field.attname] = value
    return value
