'The geometry type OID used by PostGIS does not indicate the particular
type of field that a geometry column is (e.g., whether it\'s a
PointField or a PolygonField).  Thus, this routine queries the PostGIS
metadata tables to determine the geometry type,'

def get_geometry_type(self, table_name, geo_col):

    cursor = self.connection.cursor()
    try:
        try:
            cursor.execute('SELECT    "coord_dimension",    "srid",    "type"    FROM    "geometry_columns"    WHERE    "f_table_name"=%s    AND    "f_geometry_column"=%s', (table_name, geo_col))
            row = cursor.fetchone()
            if (not row):
                raise GeoIntrospectionError
        except GeoIntrospectionError:
            if self.connection.ops.geography:
                cursor.execute('SELECT    "coord_dimension",    "srid",    "type"    FROM    "geography_columns"    WHERE    "f_table_name"=%s    AND    "f_geography_column"=%s', (table_name, geo_col))
                row = cursor.fetchone()
        if (not row):
            raise Exception(('Could    not    find    a    geometry    or    geography    column    for    "%s"."%s"' % (table_name, geo_col)))
        field_type = OGRGeomType(row[2]).django
        dim = row[0]
        srid = row[1]
        field_params = {}
        if (srid != 4326):
            field_params['srid'] = srid
        if (dim != 2):
            field_params['dim'] = dim
    finally:
        cursor.close()
    return (field_type, field_params)
