'Returns the spatial aggregate SQL template and function for the
given Aggregate instance.'

def spatial_aggregate_sql(self, agg):

    agg_name = agg.__class__.__name__
    if (not self.check_aggregate_support(agg)):
        raise NotImplementedError(('%s    spatial    aggregate    is    not    implmented    for    this    backend.' % agg_name))
    agg_name = agg_name.lower()
    if (agg_name == 'union'):
        agg_name += 'agg'
    sql_template = '%(function)s(%(field)s)'
    sql_function = getattr(self, agg_name)
    return (sql_template, sql_function)
