
    Dvg.                        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/dJS )K    )BaseSpatialField)Distance)NotSupportedError)
ExpressionLookup	Transform)Query)_lazy_re_compilec                       e Zd Zd ZdS )RasterBandTransformc                 6    |                     | j                  S N)compilelhs)selfcompiler
connections      a/var/www/pixelcanvas.ch/venv/lib/python3.11/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 | _        |                                  d S r   )
isinstancelisttuple
rhs_paramssuper__init__template_paramsprocess_rhs_params)r   r   rhs	__class__s      r   r$   zGISLookup.__init__   sb    '1#e}'E'E PC5doc"""!!!!!!r   c                 P   | j         rlt          | j                   | j        dk    rdndk    r|                                  d S t          | j                   dk    rt	          d| j        z            d S t          | j        t                    r|                     d           d S d S )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    ? 	54?##T-=-I-IqQQ))+++++T_%%)) !@4CS!STTT *)"566 	5%%t%44444	5 	5r   c                     |rd| _         | j        j        dz   | _        dS t	          | j        t
                    r| j        j        dz   | _        nd| _        | j        ^| _         | _        dS )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%   sl      	DM H/!3DMFdh 344 	 H/!3DMMDM*./'r   c                 <    d|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4566r   c                    t          | j        t                    r"t                                          ||          S t          | j        t
                    r$| j                            |j                  | _        t                                          ||          \  }}|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    dh&& 	=77&&x<<<dh
++ 	Cx228>BBDH''--h
CCZ n99H!48X
 
 S *,,r   c                 0    |j         j        | j                 S r   )r9   gis_operatorsr/   )r   r   r'   s      r   
get_rhs_opzGISLookup.get_rhs_opH   s     ~+D,<==r   c                     |                      ||          \  }}|                     ||          \  }}g ||R }||dd| 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D"..xDD/z/J//
 
 
 "	
 W55}}Z
K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 5 5: : : :&7 7 7
- 
- 
- 
- 
-> > >L L L L L L Lr   r   c                       e Zd ZdZdZdS )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         
 "KKKr   rT   c                       e Zd ZdZdZdS )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            
 #KKKr   rY   c                       e Zd ZdZdZdS )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dS )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dS )
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         
 KKKr   rc   c                       e Zd ZdZdZdS )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         
 KKKr   rf   c                       e Zd ZdZdZdS )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dS )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dS )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          KKKr   ro   exactc                       e Zd ZdZdZdS )BBContainsLookupzq
    The 'bbcontains' operator returns true if A's bounding box completely contains
    by B's bounding box.
    
bbcontainsNrV   r   r   r   rs   rs               
 KKKr   rs   c                       e Zd ZdZdZdS )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dS )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         
 KKKr   rz   c                       e Zd ZdZdS )ContainsLookupcontainsNr   r   r   r/   r   r   r   r}   r}              KKKr   r}   c                       e Zd ZdZdS )ContainsProperlyLookupcontains_properlyNr   r   r   r   r   r      s        %KKKr   r   c                       e Zd ZdZdS )CoveredByLookup	coveredbyNr   r   r   r   r   r      s        KKKr   r   c                       e Zd ZdZdS )CoversLookupcoversNr   r   r   r   r   r              KKKr   r   c                       e Zd ZdZdS )CrossesLookupcrossesNr   r   r   r   r   r              KKKr   r   c                       e Zd ZdZdS )DisjointLookupdisjointNr   r   r   r   r   r      r   r   r   c                       e Zd ZdZdS )EqualsLookupequalsNr   r   r   r   r   r     r   r   r   c                       e Zd ZdZdS )IntersectsLookup
intersectsNr   r   r   r   r   r     s        KKKr   r   c                       e Zd ZdZdS )OverlapsLookupoverlapsNr   r   r   r   r   r     r   r   r   c                   <     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                 t   | j         d         }|j        j        | j                 }t	          |d          r|                    |           nAt          |t                    r| j        	                    |          st          d|z            t                                          ||          \  }}|||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$2BC
:677 	T,,W5555GS)) 	T1C1I1I'1R1R 	TH7RSSSgg))(J??VFgY&&&r   )	r   r   r   r/   rN   r
   r   r>   rQ   rR   s   @r   r   r     sS        K4L$$%566M	' 	' 	' 	' 	' 	' 	' 	' 	'r   r   c                       e Zd ZdZdS )TouchesLookuptouchesNr   r   r   r   r   r   "  r   r   r   c                       e Zd ZdZdS )WithinLookupwithinNr   r   r   r   r   r   '  r   r   r   c                   "    e Zd ZdZdZd Zd ZdS )DistanceLookupBaseTz+%(func)s(%(lhs)s, %(rhs)s) %(op)s %(value)sc                 h   dt          | j                  cxk    rdk    sn t          d| j        z            t          | j                  dk    r | j        d         dk    rt          d          t          | j                  dk    r'| j        d         dk    r|                                  d S d S d S )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----DtGWW   !!Q&&4?1+=+K+K   t!##(:j(H(H%%''''' $#(H(Hr   c                     | j         d         }t          |d          r-|                    |                    |j                            n1d|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8HZ::8>JJKKK ++H)4?D<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        s4t          |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  sy    _Q'
#B	
$899	 z844	
 $2   ww''*===r   c                     |                      ||          \  }}|| 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_  sW     $ 5 5h
 K K+(0W%''--h
C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dS )DistanceLookupFromFunctionc                 ^   t          | j                  dk    o| j        d         dk    pd }|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 	 #??Hdh @ 
 
 &&}'G'G'W'WXXV $ 5 5h
 K K+&#TWh)W)WW[ 
 	
r   Nr   r   r   r   r   r   f  s#        
 
 
 
 
r   r   c                       e Zd ZdZdZdS )DistanceGTLookupdistance_gt>Nr   r   r   r/   r   r   r   r   r   r   v          K	BBBr   r   c                       e Zd ZdZdZdS )DistanceGTELookupdistance_gtez>=Nr   r   r   r   r   r   |           K	BBBr   r   c                       e Zd ZdZdZdS )DistanceLTLookupdistance_lt<Nr   r   r   r   r   r     r   r   r   c                       e Zd ZdZdZdS )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 6 6 6 6 6* * * * *) * * *
LL LL LL LL LL LL LL LLh !" " " " " " " "!" !# # # # #) # # "!# !# # # # #) # # "!# !# # # # #) # # "!# !       "! !    )   "! !# # # # #) # # "!# !# # # # #) # # "!# !    9   "! !   w 7 7 7 !    y   "! !    y   "! !    i   "! !    Y   "! !& & & & &Y & & "!& !    i   "! !    9   "! !    I   "! !    Y   "! !    9   "! !    y   "! !    Y   "! !' ' ' ' '9 ' ' "!'" !    I   "! !    9   "!
 
 
 
 
 
 
 
B !- - - - -& - - "!-0
 
 
 
 
!3 
 
 
  !    1   "!
 !    2   "!
 !    1   "!
 !    2   "!  r   