o
    <g\                     @   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   g/var/www/html/venv/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    