3
š(ƒh]  ã               @   sD   d Z ddlmZmZ ddlmZ G dd„ deƒZG dd„ deƒ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'Represents the OGREnvelope C Structure.ÚMinXÚMaxXÚMinYÚMaxYN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú_fields_© r   r   úD/tmp/pip-install-q3hcpn_q/Django/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†| j|d ƒ qºtdt	t
|d ƒƒ ƒ‚n2t |ƒdkrª| j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   é   z(Incorrect number of tuple elements (%d).zIncorrect type of argument: %sc             S   s   g | ]}t |ƒ‘qS r   )Úfloat)Ú.0Úar   r   r   ú
<listcomp>:   s    z%Envelope.__init__.<locals>.<listcomp>z#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ÚstrÚ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 )zy
        Returns 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-Returns a string representation of the tuple.)r   r   )r%   r   r   r   Ú__str__R   s    zEnvelope.__str__c             C   s<   t ƒ | _|d | j_|d | j_|d | j_|d | j_dS )zAInitializes 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rrt|d tƒr,| j|d jƒS t|d dƒrpt|d dƒrp| j|d j|d j|d j|d jƒS t|d ttfƒrXt |d ƒdkrÆ| j|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t|d ƒƒ ƒ‚n\t |ƒdkr¢| j|d |d |d |d fƒS t |ƒdkrº| j|ƒS td	t |d ƒ ƒ‚d
S )z 
        Modifies 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   z(Incorrect number of tuple elements (%d).zIncorrect type of argument: %sz#Incorrect number (%d) of arguments.N)r   r   r   Úexpand_to_includer   Úhasattrr.   r/   r   r   r   r   r   r	   r   r   r   r    )r%   r&   ZminxZminyZmaxxZmaxyr   r   r   r0   ^   s2    
(2
"
zEnvelope.expand_to_includec             C   s   | j jS )z.Returns 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.Returns 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.Returns 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.Returns 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#Returns the upper-right coordinate.)r"   r$   )r%   r   r   r   Úurœ   s    zEnvelope.urc             C   s   | j | jfS )z"Returns the lower-left coordinate.)r!   r#   )r%   r   r   r   Úll¡   s    zEnvelope.llc             C   s   | j | j| j| jfS )z*Returns 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 )z5Returns 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+   r,   r   r0   Úpropertyr!   r#   r"   r$   r2   r3   r   r4   r   r   r   r   r      s   *r   N)	r   Úctypesr   r   Zdjango.contrib.gis.gdal.errorr   r   Úobjectr   r   r   r   r   Ú<module>   s   	