
    +'&h                        U d Z ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ  ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zeed <    ed!          Zeed"<    ed#          Z eed$<    ed%          Z!eed&<    ed'          Z"eed(<   ee#eef         Z$ G d) d*ej%                  Z& G d+ d,e&          Z%d-S ).aE  This module defines a ``Comparator`` class for use with geometry and geography objects.

This is where spatial operators, like ``&&``, ``&<``, are defined.
Spatial operators very often apply to the bounding boxes of geometries. For
example, ``geom1 && geom2`` indicates if geom1's bounding box intersects
geom2's.

Examples
--------
Select the objects whose bounding boxes are to the left of the
bounding box of ``POLYGON((-5 45,5 45,5 -45,-5 -45,-5 45))``::

    select([table]).where(table.c.geom.to_left(
        'POLYGON((-5 45,5 45,5 -45,-5 -45,-5 45))'))

The ``<<`` and ``>>`` operators are a bit specific, because they have
corresponding Python operator (``__lshift__`` and ``__rshift__``). The
above ``SELECT`` expression can thus be rewritten like this::

    select([table]).where(
        table.c.geom << 'POLYGON((-5 45,5 45,5 -45,-5 -45,-5 45))')

Operators can also be used when using the ORM. For example::

    Session.query(Cls).filter(
        Cls.geom << 'POLYGON((-5 45,5 45,5 -45,-5 -45,-5 45))')

Now some other examples with the ``<#>`` operator.

Select the ten objects that are the closest to ``POINT(0 0)`` (typical
closed neighbors problem)::

    select([table]).order_by(table.c.geom.distance_box('POINT(0 0)')).limit(10)

Using the ORM::

    Session.query(Cls).order_by(Cls.geom.distance_box('POINT(0 0)')).limit(10)
    )Union)types)DOUBLE_PRECISION)ColumnElement)_FunctionGenerator)	custom_op)UserDefinedType)
WKBElement)
WKTElementz&&
INTERSECTSz&&&INTERSECTS_NDz&<OVERLAPS_OR_TO_LEFTz&>OVERLAPS_OR_TO_RIGHTz&<|OVERLAPS_OR_BELOWz<<TO_LEFTz<<|BELOWz>>TO_RIGHT@	CONTAINEDz|&>OVERLAPS_OR_ABOVEz|>>ABOVE~CONTAINSz~=SAMEz<->DISTANCE_CENTROIDz<#>DISTANCE_BOXc                   L    e Zd ZdZdZd ZdedefdZdedefdZ	dedefdZ
dS )	BaseComparatoraD  A custom comparator base class.

    It adds the ability to call spatial functions on columns that use this kind of comparator.
    It also defines functions that map to operators supported by ``Geometry``, ``Geography``
    and ``Raster`` columns.

    This comparator is used by the :class:`geoalchemy2.types.Raster`.
    Nc                     |                                                     d          st          t          | j                  }t          ||          S )Nst_)expr)lower
startswithAttributeErrorr   r!   getattr)selfnamefunc_s      Q/var/www/html/reinick/venv/lib/python3.11/site-packages/geoalchemy2/comparator.py__getattr__zBaseComparator.__getattr__S   sL    
 zz||&&u-- 	!   #	222ud###    otherreturnc                 P    |                      t          |t          j                  S )z-The ``&&`` operator. A's BBOX intersects B's.result_type)operater   sqltypesBooleanr&   r,   s     r)   
intersectszBaseComparator.intersectsb   s    ||J8;K|LLLr+   c                 P    |                      t          |t          j                  S )z@The ``&<`` operator. A's BBOX overlaps or is to the left of B's.r/   )r1   r   r2   r3   r4   s     r)   overlaps_or_to_leftz"BaseComparator.overlaps_or_to_leftf   s    ||/HDT|UUUr+   c                 P    |                      t          |t          j                  S )zAThe ``&>`` operator. A's BBOX overlaps or is to the right of B's.r/   )r1   r   r2   r3   r4   s     r)   overlaps_or_to_rightz#BaseComparator.overlaps_or_to_rightj   s    ||0%XEU|VVVr+   )__name__
__module____qualname____doc__keyr*   _COMPARATOR_INPUT_TYPEr   r5   r7   r9    r+   r)   r   r   G   s          C$ $ $M 6 M= M M M MV)? VM V V V VW*@ W] W W W W W Wr+   r   c                       e Zd ZdZdedefdZdedefdZdedefdZdedefdZ	dedefdZ
dedefd	Zdedefd
ZdedefdZdedefdZdedefdZdedefdZdedefdZdedefdZdedefdZdS )
ComparatorzA custom comparator class.

    Used in :class:`geoalchemy2.types.Geometry` and :class:`geoalchemy2.types.Geography`.

    This is where spatial operators like ``<<`` and ``<->`` are defined.
    r,   r-   c                 P    |                      t          |t          j                  S )zJThe ``&<|`` operator.

        A's BBOX overlaps or is below B's.
        r/   )r1   r   r2   r3   r4   s     r)   overlaps_or_belowzComparator.overlaps_or_beloww        
 ||-u(BR|SSSr+   c                 P    |                      t          |t          j                  S )zOThe ``<<`` operator.

        A's BBOX is strictly to the left of B's.
        r/   )r1   r   r2   r3   r4   s     r)   to_leftzComparator.to_left~   s    
 ||GU8H|IIIr+   c                 ,    |                      |          S )zThe ``<<`` operator.

        A's BBOX is strictly to the left of B's.

        Same as ``to_left``, so::

            table.c.geom << 'POINT(1 2)'

        is the same as::

            table.c.geom.to_left('POINT(1 2)')
        )rG   r4   s     r)   
__lshift__zComparator.__lshift__   s     ||E"""r+   c                 P    |                      t          |t          j                  S )zGThe ``<<|`` operator.

        A's BBOX is strictly below B's.
        r/   )r1   r   r2   r3   r4   s     r)   belowzComparator.below       
 ||E5h6F|GGGr+   c                 P    |                      t          |t          j                  S )zPThe ``>>`` operator.

        A's BBOX is strictly to the right of B's.
        r/   )r1   r   r2   r3   r4   s     r)   to_rightzComparator.to_right       
 ||He9I|JJJr+   c                 ,    |                      |          S )zThe ``>>`` operator.

        A's BBOX is strictly to the left of B's.

        Same as `to_`right``, so::

            table.c.geom >> 'POINT(1 2)'

        is the same as::

            table.c.geom.to_right('POINT(1 2)')
        )rN   r4   s     r)   
__rshift__zComparator.__rshift__   s     }}U###r+   c                 P    |                      t          |t          j                  S )zCThe ``@`` operator.

        A's BBOX is contained by B's.
        r/   )r1   r   r2   r3   r4   s     r)   	containedzComparator.contained   s    
 ||Iu(:J|KKKr+   c                 P    |                      t          |t          j                  S )zJThe ``|&>`` operator.

        A's BBOX overlaps or is above B's.
        r/   )r1   r   r2   r3   r4   s     r)   overlaps_or_abovezComparator.overlaps_or_above   rE   r+   c                 P    |                      t          |t          j                  S )zGThe ``|>>`` operator.

        A's BBOX is strictly above B's.
        r/   )r1   r   r2   r3   r4   s     r)   abovezComparator.above   rL   r+   c                 P    |                      t          |t          j                  S )z<The ``~`` operator.

        A's BBOX contains B's.
        r/   )r1   r   r2   r3   )r&   r,   kws      r)   containszComparator.contains   rO   r+   c                 P    |                      t          |t          j                  S )zCThe ``~=`` operator.

        A's BBOX is the same as B's.
        r/   )r1   r   r2   r3   r4   s     r)   samezComparator.same   s    
 ||D%X5E|FFFr+   c                 F    |                      t          |t                    S )zHThe ``<->`` operator.

        The distance between two points.
        r/   )r1   r   r   r4   s     r)   distance_centroidzComparator.distance_centroid   s    
 ||-uBR|SSSr+   c                 F    |                      t          |t                    S )z\The ``<#>`` operator.

        The distance between bounding box of two geometries.
        r/   )r1   r   r   r4   s     r)   distance_boxzComparator.distance_box   s    
 ||L%=M|NNNr+   c                 P    |                      t          |t          j                  S )zThe ``&&&`` operator.

        This operator returns TRUE if the n-D bounding box of geometry A
        intersects the n-D bounding box of geometry B.
        r/   )r1   r   r2   r3   r4   s     r)   intersects_ndzComparator.intersects_nd   s     ||M5h>N|OOOr+   N)r:   r;   r<   r=   r?   r   rD   rG   rI   rK   rN   rQ   rS   rU   rW   rZ   r\   r^   r`   rb   r@   r+   r)   rB   rB   o   sR        T'= T- T T T TJ3 J J J J J# 6 #= # # # #H1 Hm H H H HK4 K K K K K$ 6 $= $ $ $ $L5 L- L L L LT'= T- T T T TH1 Hm H H H HK4 K} K K K KG0 G] G G G GT'= T- T T T TO"8 O] O O O OP#9 Pm P P P P P Pr+   rB   N)'r=   typingr   
sqlalchemyr   r2   sqlalchemy.dialects.postgresqlr   sqlalchemy.sql.elementsr   sqlalchemy.sql.functionsr   sqlalchemy.sql.operatorsr   sqlalchemy.typesr	   geoalchemy2.elementsr
   r   r   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r   strr?   rB   r   r@   r+   r)   <module>rm      s  % % %N       ( ( ( ( ( ( ; ; ; ; ; ; 1 1 1 1 1 1 7 7 7 7 7 7 . . . . . . , , , , , , + + + + + + + + + + + +!	$
I ' ' '$9U++y + + +!*4 Y 0 0 0"+)D// i 1 1 1(y// 9 / / /Yt__ $ $ $9U##y # # #ioo) % % % y~~	9 % % %(y// 9 / / /9U##y # # #inn) $ $ $)D//i ! ! !(y// 9 / / /#)E**i * * *sJ
:; %W %W %W %W %W_/ %W %W %WPyP yP yP yP yP yP yP yP yP yPr+   