o
    "7ht                     @   s<   d dl mZ d dlmZ d dlmZmZ G dd deZdS )    )GeometryField)DatabaseSchemaEditor)ColFuncc                       s   e Zd ZdZdZdZdZdZdd Z fdd	Z	d
d fdd
Z
 fddZ	d fdd	Zdd Z fddZdd Z  ZS )PostGISSchemaEditorGISTGIST_GEOMETRY_OPS_NDzST_ConvexHull(%(expressions)s)zLALTER COLUMN %(column)s TYPE %(type)s USING ST_Force3D(%(column)s)::%(type)szLALTER COLUMN %(column)s TYPE %(type)s USING ST_Force2D(%(column)s)::%(type)sc                 C   s   | j j|S N)
connectionopsgeo_quote_name)selfname r   /var/www/epreuve.sigeris.cm/public_html/epreuve/venv/lib/python3.10/site-packages/django/contrib/gis/db/backends/postgis/schema.pyr      s   z"PostGISSchemaEditor.geo_quote_namec                    s   t |ddrdS t ||S )Nspatial_indexFT)getattrsuper_field_should_be_indexedr   modelfield	__class__r   r   r      s   z,PostGISSchemaEditor._field_should_be_indexedN)fieldsc                   sR   |d u st |dkst|d dst j|fd|i|S | j||d fi |S )N   r   geodeticr   )lenhasattrr   _create_index_sql_create_spatial_index_sql)r   r   r   kwargsr   r   r   r      s   "z%PostGISSchemaEditor._create_index_sqlc                    s   t |dr
t |dst ||||||S |jdkr#|jdkr#| j}n|jdkr1|jdkr1| j}n| j}|| |j|dd g fg fS )z6
        Special case when dimension changed.
        dim       )columntype	collation)	r   r   _alter_column_type_sqlr"   sql_alter_column_to_3dsql_alter_column_to_2dsql_alter_column_type
quote_namer&   )r   table	old_field	new_fieldnew_typeold_collationnew_collation	sql_alterr   r   r   r)       s&   
	z*PostGISSchemaEditor._alter_column_type_sqlFc	              
      s   t  j||||||||d t|to|j}	t|to|j}
|	s-|
r-| | || d S |	r<|
s>| | || d S d S d S )N)strict)r   _alter_field
isinstancer   r   executer    _delete_spatial_index_sql)r   r   r/   r0   old_typer1   old_db_paramsnew_db_paramsr5   old_field_spatial_indexnew_field_spatial_indexr   r   r   r6   >   s&   z PostGISSchemaEditor._alter_fieldc                 C   s   |  |jj|jgdS )N_id)_create_index_name_metadb_tabler&   r   r   r   r   _create_spatial_index_name_   s   z.PostGISSchemaEditor._create_spatial_index_namec                    s   d }d }|g}|j dkrttd || jd}d }n|jdkr%|js%| jg}|d }s2| ||}t	 j
|||d| j ||dS )NRASTER)templater#   r   z	 USING %s)r   r   using	opclassesexpressions)	geom_typer   r   rast_index_templater"   	geographygeom_index_ops_ndgetrC   r   r   geom_index_type)r   r   r   r!   rH   rG   r   r   r   r   r   r    b   s$   
z-PostGISSchemaEditor._create_spatial_index_sqlc                 C   s   |  ||}| ||S r	   )rC   _delete_index_sql)r   r   r   
index_namer   r   r   r9   z   s   z-PostGISSchemaEditor._delete_spatial_index_sql)F)__name__
__module____qualname__rN   rL   rJ   r*   r+   r   r   r   r)   r6   rC   r    r9   __classcell__r   r   r   r   r      s"    '!r   N)django.contrib.gis.db.modelsr   $django.db.backends.postgresql.schemar   django.db.models.expressionsr   r   r   r   r   r   r   <module>   s    