
v^                 @   s:   d  d l  m Z d  d l m Z Gd d   d e  Z d S)    )OGRGeomType)DatabaseIntrospectionc                   sP   e  Z d  Z i  Z e j d d d d d g Z   f d d   Z d d	   Z   S)
PostGISIntrospectionZgeography_columnsZgeometry_columnsZraster_columnsZspatial_ref_sysZraster_overviewsc          
      sw   |  j  sd |  j j   ) } | j d  t | j    |  _  Wd  QRX|  j j d d   |  j  D  t   j	 | |  S)NzKSELECT oid, typname FROM pg_type WHERE typname IN ('geometry', 'geography')c             s   s   |  ] } | d  f Vq d S)ZGeometryFieldN ).0oidr   r   V/tmp/pip-build-8lau8j11/django/django/contrib/gis/db/backends/postgis/introspection.py	<genexpr>   s    z6PostGISIntrospection.get_field_type.<locals>.<genexpr>)
postgis_oid_lookup
connectioncursorexecutedictZfetchallZdata_types_reverseupdatesuperget_field_type)selfZ	data_typedescriptionr   )	__class__r   r   r      s    	 z#PostGISIntrospection.get_field_typec       	      C   s   |  j  j    } | j d | | j f  | j   } | sV t d | | j f   | \ } } } t |  j } i  } |  j j	 | j
  d k r d | d <| d k r | | d <| d k r | | d <Wd	 QRX| | f S)
a%  
        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.
        a   
                SELECT t.coord_dimension, t.srid, t.type FROM (
                    SELECT * FROM geometry_columns
                    UNION ALL
                    SELECT * FROM geography_columns
                ) AS t WHERE t.f_table_name = %s AND t.f_geometry_column = %s
            z;Could not find a geometry or geography column for "%s"."%s"Z	geographyTi  srid   dimN)r   r   r   nameZfetchone	Exceptionr   Zdjangor
   getZ	type_code)	r   Z
table_namer   r   rowr   r   Z
field_typeZfield_paramsr   r   r   get_geometry_type   s"    

z&PostGISIntrospection.get_geometry_type)__name__
__module____qualname__r
   r   Zignored_tablesr   r   r   r   )r   r   r      s   
r   N)Zdjango.contrib.gis.gdalr   Z+django.db.backends.postgresql.introspectionr   r   r   r   r   r   <module>   s   