o
    ˜¨Êh\  ã                   @   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)Úgeography_columnsÚgeometry_columnsÚraster_columnsÚspatial_ref_sysÚraster_overviewsc                    sn   | j s0| j ¡ �}| d¡ t| ¡ ƒ| _ W d   ƒ n1 sw   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 )ÚGeometryFieldN© )Ú.0Úoidr   r   úf/var/www/html/env/lib/python3.10/site-packages/django/contrib/gis/db/backends/postgis/introspection.pyÚ	<genexpr>   s   € 
ÿz6PostGISIntrospection.get_field_type.<locals>.<genexpr>)
Úpostgis_oid_lookupÚ
connectionÚcursorÚexecuteÚdictÚfetchallÚdata_types_reverseÚupdateÚsuperÚget_field_type)ÚselfÚ	data_typeÚdescriptionr   ©Ú	__class__r   r   r      s   ÿúÿz#PostGISIntrospection.get_field_typec           	      C   sÎ   | j  ¡ �V}| d||jf¡ | ¡ }|std||jf ƒ‚|\}}}t|ƒj}i }| j 	|j
¡dkr7d|d< |dkr?||d< |dkrQ||d< W d	  ƒ ||fS W d	  ƒ ||fS 1 s^w   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"Ú	geographyTiæ  Úsridé   ÚdimN)r   r   r   ÚnameÚfetchoneÚ	Exceptionr   Údjangor   ÚgetÚ	type_code)	r   Ú
table_namer   r   Úrowr"   r    Ú
field_typeÚfield_paramsr   r   r   Úget_geometry_type#   s8   ø
ÿÿ



äþ
åãz&PostGISIntrospection.get_geometry_type)	Ú__name__Ú
__module__Ú__qualname__r   r   Úignored_tablesr   r-   Ú__classcell__r   r   r   r   r      s
    r   N)Údjango.contrib.gis.gdalr   Ú+django.db.backends.postgresql.introspectionr   r   r   r   r   r   Ú<module>   s    