a
    Kcòf\  ã                   @   s,   d dl mZ d dlmZ G dd„ deƒZdS )é    )ÚOGRGeomType)ÚDatabaseIntrospectionc                       s6   e Zd Zi Zejg d¢ Z‡ fdd„Zdd„ Z‡  ZS )ÚPostGISIntrospection)Zgeography_columnsZgeometry_columnsZraster_columnsZspatial_ref_sysZraster_overviewsc                    sn   | j s`| j ¡ �(}| d¡ t| ¡ ƒ| _ W d   ƒ n1 s>0    Y  | j dd„ | j D ƒ¡ tƒ  	||¡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   úq/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/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  ¡ �’}| d||jf¡ | ¡ }|s<td||jf ƒ‚|\}}}t|ƒj}i }| j 	|j
¡dkrnd|d< |dkr~||d< |dkrŽ||d< W d	  ƒ n1 s¢0    Y  ||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   Ú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   Ú__classcell__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   