U
    ¡‹®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   úD/tmp/pip-unpacked-wheel-ye1bytdm/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 | _q¶t|d ttfƒrnt |d ƒdkr^tdt |d ƒ ƒ‚q‚|  |d ¡ q¶tdt	|d ƒ ƒ‚n2t |ƒdkr¦|  dd„ |D ƒ¡ ntdt |ƒ ƒ‚| j
| jkrÊtd	ƒ‚| j| jkrÞt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o8| j|jko8| j|jko8| j|jkS t |tƒrˆt|ƒdkrˆ| j|d ko†| j|d ko†| j|d ko†| j|d kS tdƒ‚dS )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.N)	r   r   r#   r%   r$   r&   r   r   r   )r'   Úotherr   r   r   Ú__eq__D   s    

ÿ
ÿÿÿzEnvelope.__eq__c                 C   s
   t | jƒS )z,Return a string representation of the tuple.)Ústrr   ©r'   r   r   r   Ú__str__R   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    V   s
    zEnvelope._from_sequencec                 G   sÎ  t |ƒdkrnt|d tƒr,|  |d j¡S t|d dƒrpt|d dƒrp|  |d j|d j|d j|d j¡S t|d ttfƒrXt |d ƒdkrÆ|  |d d |d d |d d |d d f¡S t |d ƒdkrB|d \}}}}|| j	j
k  rþ|| j	_
|| j	jk r|| j	_|| j	jkr*|| j	_|| j	jkrV|| j	_ntdt |d ƒ ƒ‚ntdt|d ƒ ƒ‚n\t |ƒdkrž|  |d |d |d |d f¡S t |ƒdkr¶|  |¡S td	t |d ƒ ƒ‚d
S )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(   ZminxZminyZmaxxZmaxyr   r   r   r4   ^   s2    
(2
"
zEnvelope.expand_to_includec                 C   s   | j jS )z-Return the value of the minimum X coordinate.)r   r   r/   r   r   r   r#   ˆ   s    zEnvelope.min_xc                 C   s   | j jS )z-Return the value of the minimum Y coordinate.)r   r   r/   r   r   r   r%      s    zEnvelope.min_yc                 C   s   | j jS )z-Return the value of the maximum X coordinate.)r   r   r/   r   r   r   r$   ’   s    zEnvelope.max_xc                 C   s   | j jS )z-Return the value of the maximum Y coordinate.)r   r	   r/   r   r   r   r&   —   s    zEnvelope.max_yc                 C   s   | j | jfS )z"Return the upper-right coordinate.)r$   r&   r/   r   r   r   Úurœ   s    zEnvelope.urc                 C   s   | j | jfS )z!Return the lower-left coordinate.)r#   r%   r/   r   r   r   Úll¡   s    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&   r6   r7   r   r8   r   r   r   r   r      s,   *






r   N)r   Úctypesr   r   Zdjango.contrib.gis.gdal.errorr   r   r   r   r   r   r   Ú<module>   s   	