
    g.                        d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ  G d de	      Z G d	 d
e      Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Zej                    G d de             Z ej                   ed       ej                    G d de             Zej                    G d  d!e             Zej                    G d" d#e             Zej                    G d$ d%e             Zej                    G d& d'e             Zej                    G d( d)e             Zej                    G d* d+e             Z ej                    G d, d-e             Z!ej                    G d. d/e             Z"ej                    G d0 d1e             Z#ej                    G d2 d3e             Z$ej                    G d4 d5e             Z%ej                    G d6 d7e             Z&ej                    G d8 d9e             Z'ej                    G d: d;e             Z( G d< d=e      Z)ej                    G d> d?e)             Z* G d@ dAe)      Z+ej                    G dB dCe+             Z,ej                    G dD dEe+             Z-ej                    G dF dGe+             Z.ej                    G dH dIe+             Z/yJ)K    )BaseSpatialField)Distance)NotSupportedError)
ExpressionLookup	Transform)Query)_lazy_re_compilec                       e Zd Zd Zy)RasterBandTransformc                 8    |j                  | j                        S N)compilelhs)selfcompiler
connections      |/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/db/models/lookups.pyas_sqlzRasterBandTransform.as_sql
   s    ))    N__name__
__module____qualname__r    r   r   r   r   	   s    *r   r   c                   \     e Zd ZdZdZdZdZdZ fdZd Z	d
dZ
d Z fdZd Zd	 Z xZS )	GISLookupNFc                     t        |t        t        f      r|n|g^}| _        t        |   ||       i | _        | j                          y r   )
isinstancelisttuple
rhs_paramssuper__init__template_paramsprocess_rhs_params)r   r   rhs	__class__s      r   r$   zGISLookup.__init__   sC    '1#e}'EC5doc"!!r   c                 L   | j                   rkt        | j                         | j                  dk(  rdndk(  r| j                          y t        | j                         dkD  rt	        d| j                  z        y t        | j                  t              r| j                  d       y y )Nrelate      zTuple too long for lookup %s.T)only_lhs)r"   lenlookup_nameprocess_band_indices
ValueErrorr   r   r   r   s    r   r&   zGISLookup.process_rhs_params   s    ??4??#T-=-=-IqQ))+T__%) !@4CSCS!STT *"56%%t%4 7r   c                    |r&d| _         | j                  j                  dz   | _        yt	        | j                  t
              r| j                  j                  dz   | _        nd| _        | j                  ^| _         | _        y)z
        Extract the lhs band index from the band transform class and the rhs
        band index from the input tuple.
        r,   N)band_rhsr   
band_indexband_lhsr   r   r"   )r   r-   s     r   r0   zGISLookup.process_band_indices%   se     DM HH//!3DMdhh 34 HH//!3DMDM*.//'r   c                 >    d|j                   j                  |      gfS )N%s)opsAdapter)r   valuer   s      r   get_db_prep_lookupzGISLookup.get_db_prep_lookup8   s    z~~--e4566r   c                    t        | j                  t              rt        |   ||      S t        | j                  t
              r*| j                  j                  |j                        | _        t        |   ||      \  }}|j                  j                  | j                  j                  | j                  |      }||z  |fS r   )r   r'   r	   r#   process_rhsr   resolve_expressionqueryr9   get_geom_placeholderr   output_field)r   r   r   r'   r"   placeholderr(   s         r   r>   zGISLookup.process_rhs<   s    dhh&7&x<<dhh
+xx228>>BDH'-h
CZ nn99HH!!488X
 S *,,r   c                 H    |j                   j                  | j                     S r   )r9   gis_operatorsr/   )r   r   r'   s      r   
get_rhs_opzGISLookup.get_rhs_opH   s     ~~++D,<,<==r   c                     | j                  ||      \  }}| j                  ||      \  }}g ||}||dd| j                  }| j                  ||      }	|	j	                  || ||      S )Nr8   )r   r'   r;   )process_lhsr>   r%   rF   r   )
r   r   r   lhs_sql
lhs_paramsrhs_sqlr"   
sql_paramsr%   rhs_ops
             r   r   zGISLookup.as_sqlN   s    "..xD"..xD/z/J/
 
 ""	
 W5}}Z
KKr   )F)r   r   r   sql_templatetransform_funcdistancer4   r6   r$   r&   r0   r<   r>   rF   r   __classcell__r(   s   @r   r   r      s@    LNHHH"5:&7
->Lr   r   c                       e Zd ZdZdZy)OverlapsLeftLookupzy
    The overlaps_left operator returns true if A's bounding box overlaps or is to the
    left of B's bounding box.
    overlaps_leftNr   r   r   __doc__r/   r   r   r   rT   rT   b   s    
 "Kr   rT   c                       e Zd ZdZdZy)OverlapsRightLookupz}
    The 'overlaps_right' operator returns true if A's bounding box overlaps or is to the
    right of B's bounding box.
    overlaps_rightNrV   r   r   r   rY   rY   l       
 #Kr   rY   c                       e Zd ZdZdZy)OverlapsBelowLookupzs
    The 'overlaps_below' operator returns true if A's bounding box overlaps or is below
    B's bounding box.
    overlaps_belowNrV   r   r   r   r]   r]   v   r[   r   r]   c                       e Zd ZdZdZy)OverlapsAboveLookupzs
    The 'overlaps_above' operator returns true if A's bounding box overlaps or is above
    B's bounding box.
    overlaps_aboveNrV   r   r   r   r`   r`      r[   r   r`   c                       e Zd ZdZdZy)
LeftLookupzo
    The 'left' operator returns true if A's bounding box is strictly to the left
    of B's bounding box.
    leftNrV   r   r   r   rc   rc      s    
 Kr   rc   c                       e Zd ZdZdZy)RightLookupzq
    The 'right' operator returns true if A's bounding box is strictly to the right
    of B's bounding box.
    rightNrV   r   r   r   rf   rf      s    
 Kr   rf   c                       e Zd ZdZdZy)StrictlyBelowLookupzp
    The 'strictly_below' operator returns true if A's bounding box is strictly below B's
    bounding box.
    strictly_belowNrV   r   r   r   ri   ri      r[   r   ri   c                       e Zd ZdZdZy)StrictlyAboveLookupzp
    The 'strictly_above' operator returns true if A's bounding box is strictly above B's
    bounding box.
    strictly_aboveNrV   r   r   r   rl   rl      r[   r   rl   c                       e Zd ZdZdZy)SameAsLookupz
    The "~=" operator is the "same as" operator. It tests actual geometric
    equality of two features. So if A and B are the same feature,
    vertex-by-vertex, the operator returns true.
    same_asNrV   r   r   r   ro   ro      s     Kr   ro   exactc                       e Zd ZdZdZy)BBContainsLookupzq
    The 'bbcontains' operator returns true if A's bounding box completely contains
    by B's bounding box.
    
bbcontainsNrV   r   r   r   rs   rs          
 Kr   rs   c                       e Zd ZdZdZy)BBOverlapsLookupzc
    The 'bboverlaps' operator returns true if A's bounding box overlaps B's
    bounding box.
    
bboverlapsNrV   r   r   r   rw   rw      ru   r   rw   c                       e Zd ZdZdZy)ContainedLookupzt
    The 'contained' operator returns true if A's bounding box is completely contained
    by B's bounding box.
    	containedNrV   r   r   r   rz   rz      s    
 Kr   rz   c                       e Zd ZdZy)ContainsLookupcontainsNr   r   r   r/   r   r   r   r}   r}          Kr   r}   c                       e Zd ZdZy)ContainsProperlyLookupcontains_properlyNr   r   r   r   r   r      s    %Kr   r   c                       e Zd ZdZy)CoveredByLookup	coveredbyNr   r   r   r   r   r      s    Kr   r   c                       e Zd ZdZy)CoversLookupcoversNr   r   r   r   r   r          Kr   r   c                       e Zd ZdZy)CrossesLookupcrossesNr   r   r   r   r   r          Kr   r   c                       e Zd ZdZy)DisjointLookupdisjointNr   r   r   r   r   r      r   r   r   c                       e Zd ZdZy)EqualsLookupequalsNr   r   r   r   r   r     r   r   r   c                       e Zd ZdZy)IntersectsLookup
intersectsNr   r   r   r   r   r     s    Kr   r   c                       e Zd ZdZy)OverlapsLookupoverlapsNr   r   r   r   r   r     r   r   r   c                   6     e Zd ZdZdZ ed      Z fdZ xZS )RelateLookupr*   z%(func)s(%(lhs)s, %(rhs)s, %%s)z^[012TF*]{9}$c                 L   | j                   d   }|j                  j                  | j                     }t	        |d      r|j                  |       n9t        |t              r| j                  j                  |      st        d|z        t        | 1  ||      \  }}|||gz   fS )Nr   check_relate_argumentz)Invalid intersection matrix pattern "%s".)r"   r9   rE   r/   hasattrr   r   strpattern_regexmatchr1   r#   r>   )r   r   r   pattern
backend_opsqlparamsr(   s          r   r>   zRelateLookup.process_rhs  s    //!$^^11$2B2BC
:67,,W5GS)1C1C1I1I'1RH7RSSg)(J?VFgY&&&r   )	r   r   r   r/   rN   r
   r   r>   rQ   rR   s   @r   r   r     s"    K4L$%56M	' 	'r   r   c                       e Zd ZdZy)TouchesLookuptouchesNr   r   r   r   r   r   "  r   r   r   c                       e Zd ZdZy)WithinLookupwithinNr   r   r   r   r   r   '  r   r   r   c                        e Zd ZdZdZd Zd Zy)DistanceLookupBaseTz+%(func)s(%(lhs)s, %(rhs)s) %(op)s %(value)sc                 V   dt        | j                        cxk  rdk  sn t        d| j                  z        t        | j                        dk(  r| j                  d   dk7  rt        d      t        | j                        dkD  r$| j                  d   dk7  r| j	                          y y y )Nr,      z22, 3, or 4-element tuple required for '%s' lookup.r+   spheroidzHFor 4-element tuples the last argument must be the 'spheroid' directive.)r.   r"   r1   r/   r0   r2   s    r   r&   z%DistanceLookupBase.process_rhs_params0  s    C(-A-DtGWGWW  !Q&4??1+=+K  t!#(:j(H%%' )I#r   c                    | j                   d   }t        |d      r*|j                  |j                  |j                              S d|j
                  j                  | j                  j                  | j                   | j                        fS )Nr   r?   r8   )
r"   r   r   r?   r@   r9   get_distancer   rB   r/   )r   r   r   
dist_params       r   process_distancez#DistanceLookupBase.process_distance?  s}    __Q'
 z#78 Z::8>>JK		
 ++HH))4??D<L<L		
r   N)r   r   r   rP   rN   r&   r   r   r   r   r   r   ,  s    H@L(
r   r   c                   0     e Zd ZdZdZ fdZ fdZ xZS )DWithinLookupdwithinz%%(func)s(%(lhs)s, %(rhs)s, %(value)s)c                     | j                   d   }|j                  j                  s't        |d      rt	        |t
              st        d      t        | !  ||      S )Nr   r?   zXThis backend does not support expressions for specifying distance in the dwithin lookup.)	r"   featuressupports_dwithin_distance_exprr   r   r   r   r#   r   )r   r   r   r   r(   s       r   r   zDWithinLookup.process_distanceR  s[    __Q'
##BB
$89z84#2  w'*==r   c                     | j                  ||      \  }}|| j                  d<   t        |   ||      \  }}|||z   fS )Nr;   )r   r%   r#   r>   )r   r   r   dist_sqldist_paramsrK   r   r(   s          r   r>   zDWithinLookup.process_rhs_  sO     $ 5 5h
 K+(0W%'-h
C,,,r   )r   r   r   r/   rN   r   r>   rQ   rR   s   @r   r   r   M  s    K:L>- -r   r   c                       e Zd Zd Zy)DistanceLookupFromFunctionc                 z   t        | j                        dk(  xr | j                  d   dk(  xs d }|j                  j                  | j                  | j
                  |      }|j                  |j                  |j                              \  }}| j                  ||      \  }}d|| j                  |dz  ||z   fS )Nr+   r   )r   z%(func)s %(op)s %(dist)s)funcopdist)r.   r"   r9   distance_expr_for_lookupr   r'   r   r?   r@   r   r   )	r   r   r   r   distance_exprr   r   r   r   s	            r   r   z!DistanceLookupFromFunction.as_sqlg  s     A%K$//"*=*K 	 #??HHdhh @ 
 &&}'G'G'WXV $ 5 5h
 K+&#TWWh)WW[ 
 	
r   Nr   r   r   r   r   r   f  s    
r   r   c                       e Zd ZdZdZy)DistanceGTLookupdistance_gt>Nr   r   r   r/   r   r   r   r   r   r   v      K	Br   r   c                       e Zd ZdZdZy)DistanceGTELookupdistance_gtez>=Nr   r   r   r   r   r   |       K	Br   r   c                       e Zd ZdZdZy)DistanceLTLookupdistance_lt<Nr   r   r   r   r   r     r   r   r   c                       e Zd ZdZdZy)DistanceLTELookupdistance_ltez<=Nr   r   r   r   r   r     r   r   r   N)0#django.contrib.gis.db.models.fieldsr   django.contrib.gis.measurer   	django.dbr   django.db.modelsr   r   r   django.db.models.sql.queryr	   django.utils.regex_helperr
   r   r   register_lookuprT   rY   r]   r`   rc   rf   ri   rl   ro   rs   rw   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s(   @ / ' : : , 6*) *
LL LLh !!" " "" !!#) # "# !!#) # "# !!#) # "# !!  " !!)  " !!#) # "# !!#) # "# !!9  " !     w 7 !!y  " !!y  " !!i  " !!Y  " !!&Y & "& !!i  " !!9  " !!I  " !!Y  " !!9  " !!y  " !!Y  " !!'9 ' "'" !!I  " !!9  "
 
B !!-& - "-0
!3 
  !!1  "
 !!2  "
 !!1  "
 !!2  "r   