
 X]                 @   s\   d  Z  d d l m Z m Z d d l m Z Gd d   d e  Z Gd 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   N/home/ubuntu/projects/ifolica/build/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   sC  t  |  d k r t | d t  r5 | d |  _ q t | d t t f  r t  | d  d k r t d t  | d    q |  j | d  q t d t	 t
 | d     nE t  |  d k r |  j d d   | D  n t d t  |    |  j |  j k rt d	   n  |  j |  j k r?t d
   n  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 Sr   )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  rU |  j | j k oT |  j | j k oT |  j | j k oT |  j | j k St  | t  r t |  d k r |  j | d k o |  j | d k o |  j | d k o |  j | d k St 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   sP   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   sd  t  |  d k rt | d t  r9 |  j | d j  St | d d  r t | d d  r |  j | d j | d j | d j | d j  St | d t t f  rt  | d  d k r |  j | d d | d d | d d | d d f  St  | d  d k r| d \ } } } } | |  j	 j
 k  rF| |  j	 _
 n  | |  j	 j k  rg| |  j	 _ n  | |  j	 j k r| |  j	 _ n  | |  j	 j k r| |  j	 _ qqt d t  | d    q`t d t t | d     nt t  |  d k r'|  j | d | d | d | d f  St  |  d k rF|  j |  St 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9#)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   sD   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   	