o
    <g                     @   sB   d Z ddlmZmZ ddlmZ G dd deZG dd dZdS )	a  
 The GDAL/OGR library uses an Envelope structure to hold the bounding
 box information for a geometry.  The envelope (bounding box) contains
 two pairs of coordinates, one for the lower left coordinate and one
 for the upper right coordinate:

                           +----------o Upper right; (max_x, max_y)
                           |          |
                           |          |
                           |          |
 Lower left (min_x, min_y) o----------+
    )	Structurec_double)GDALExceptionc                   @   s,   e Zd ZdZdefdefdefdefgZdS )OGREnvelopez&Represent the OGREnvelope C Structure.MinXMaxXMinYMaxYN)__name__
__module____qualname____doc__r   _fields_ r   r   S/var/www/html/venv/lib/python3.10/site-packages/django/contrib/gis/gdal/envelope.pyr      s    r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
e	dd Ze	dd Ze	dd Ze	dd Ze	dd Ze	dd Ze	dd ZdS )Envelopez
    The Envelope object is a C structure that contains the minimum and
    maximum X, Y coordinates for a rectangle bounding box.  The naming
    of the variables is compatible with the OGR Envelope structure.
    c                 G   s   t |dkr@t|d tr|d | _nFt|d ttfr6t |d dkr.tdt |d  | |d  n#tdt	|d  t |dkrQ| dd |D  ntdt | | j
| jkrctd	| j| jkrmtd
dS )z
        The initialization function may take an OGREnvelope structure, 4-element
        tuple or list, or 4 individual arguments.
           r      (Incorrect number of tuple elements (%d).Incorrect type of argument: %sc                 S   s   g | ]}t |qS r   )float).0ar   r   r   
<listcomp>>   s    z%Envelope.__init__.<locals>.<listcomp>#Incorrect number (%d) of arguments.zEnvelope minimum X > maximum X.zEnvelope minimum Y > maximum Y.N)len
isinstancer   	_envelopetuplelistr   _from_sequence	TypeErrortypemin_xmax_xmin_ymax_y)selfargsr   r   r   __init__'   s$   zEnvelope.__init__c                 C   s   t |tr| j|jko| j|jko| j|jko| j|jkS t |trDt|dkrD| j|d koC| j|d koC| j|d koC| j|d kS td)zx
        Return True if the envelopes are equivalent; can compare against
        other Envelopes and 4-tuples.
        r   r   r         z4Equivalence testing only works with other Envelopes.)	r   r   r#   r%   r$   r&   r   r   r   )r'   otherr   r   r   __eq__H   s"   



zEnvelope.__eq__c                 C   s
   t | jS )z,Return a string representation of the tuple.)strr   r'   r   r   r   __str__^   s   
zEnvelope.__str__c                 C   s<   t  | _|d | j_|d | j_|d | j_|d | j_dS )z@Initialize the C OGR Envelope structure from the given sequence.r   r   r*   r+   N)r   r   r   r   r   r	   )r'   seqr   r   r   r    b   s
   zEnvelope._from_sequencec                 G   s  t |dkrt|d tr| |d jS t|d dr7t|d dr7| |d j|d j|d j|d jS t|d ttfrt |d dkra| |d d |d d |d d |d d fS t |d dkr|d \}}}}|| j	j
k r{|| j	_
|| j	jk r|| j	_|| j	jkr|| j	_|| j	jkr|| j	_d
S d
S tdt |d  tdt|d  t |dkr| |d |d |d |d fS t |dkr| |S td	t |d  )z
        Modify the envelope to expand to include the boundaries of
        the passed-in 2-tuple (a point), 4-tuple (an extent) or
        envelope.
        r   r   xyr*   r   r   r   r   N)r   r   r   expand_to_includer   hasattrr2   r3   r   r   r   r   r   r	   r   r!   r"   )r'   r(   minxminymaxxmaxyr   r   r   r4   j   s@   
 *"
zEnvelope.expand_to_includec                 C      | j jS )z-Return the value of the minimum X coordinate.)r   r   r/   r   r   r   r#         zEnvelope.min_xc                 C   r:   )z-Return the value of the minimum Y coordinate.)r   r   r/   r   r   r   r%      r;   zEnvelope.min_yc                 C   r:   )z-Return the value of the maximum X coordinate.)r   r   r/   r   r   r   r$      r;   zEnvelope.max_xc                 C   r:   )z-Return the value of the maximum Y coordinate.)r   r	   r/   r   r   r   r&      r;   zEnvelope.max_yc                 C      | j | jfS )z"Return the upper-right coordinate.)r$   r&   r/   r   r   r   ur      zEnvelope.urc                 C   r<   )z!Return the lower-left coordinate.)r#   r%   r/   r   r   r   ll   r>   zEnvelope.llc                 C   s   | j | j| j| jfS )z)Return a tuple representing the envelope.)r#   r%   r$   r&   r/   r   r   r   r      s   zEnvelope.tuplec                 C   s0   d| j | j| j | j| j| j| j| j| j | jf
 S )z4Return WKT representing a Polygon for this envelope.z(POLYGON((%s %s,%s %s,%s %s,%s %s,%s %s)))r#   r%   r&   r$   r/   r   r   r   wkt   s   zEnvelope.wktN)r
   r   r   r   r)   r-   r0   r    r4   propertyr#   r%   r$   r&   r=   r?   r   r@   r   r   r   r   r       s.    !0






r   N)r   ctypesr   r   django.contrib.gis.gdal.errorr   r   r   r   r   r   r   <module>   s
    
