'DRY routine for calling aggregate spatial stored procedures and
returning their result to the caller of the function.'

def _spatial_aggregate(self, aggregate, field_name=None, geo_field_type=None, tolerance=0.05):

    geo_field = self.query._geo_field(field_name)
    if (not geo_field):
        raise TypeError(('%s    aggregate    only    available    on    GeometryFields.' % aggregate.name))
    if ((not (geo_field_type is None)) and (not isinstance(geo_field, geo_field_type))):
        raise TypeError(('%s    aggregate    may    only    be    called    on    %ss.' % (aggregate.name, geo_field_type.__name__)))
    agg_col = (field_name or geo_field.name)
    agg_kwargs = {}
    if connections[self.db].ops.oracle:
        agg_kwargs['tolerance'] = tolerance
    return self.aggregate(geoagg=aggregate(agg_col, **agg_kwargs))['geoagg']
