U
    ޟi                     @   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   Z_fields_ r   r   V/var/www/SKSBV.IN/venv/lib/python3.8/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rt|d tr&|d | _qt|d ttfrnt |d dkr^tdt |d  q| |d  qtdt	|d  n2t |dkr| dd |D  ntdt | | j
| jkrtd	| j| jkrt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rt|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__G   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   a   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   hasattrr1   r2   r   r   r   r   r   r	   r   r    r!   )r&   r'   ZminxZminyZmaxxZmaxyr   r   r   r3   i   sD    
   *
"
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,   r/   r   r3   propertyr"   r$   r#   r%   r5   r6   r   r7   r   r   r   r   r      s,   !0






r   N)r   ctypesr   r   Zdjango.contrib.gis.gdal.errorr   r   r   r   r   r   r   <module>   s   
