
^Q\_                 @   s   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z d  d	 l m Z Gd
 d   d e  Z d S)    N)c_uint)gdal)
prototypes)GEOSException)GEOSGeometry)six)RemovedInDjango20Warning)rangec                   s  e  Z d  Z d Z d Z d Z d d d d   f d d  Z   f d d   Z e d	 d
    Z	 e d d    Z
 d d   Z d d   Z d d   Z d d   Z d d   Z e Z e d d    Z e j d d    Z e d d    Z e j d d    Z e d d    Z e j d d    Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z e d, d-    Z e j d. d-    Z d/ d0   Z d1 d2   Z e Z   S)3Point      TNc                s   | d k r g  } n t  | t t f  r3 | } nx t  | t j t f  r t  | t j t f  r t  | t j t f  r | | | g } q | | g } n t d   |  j t |  |  } t	 t
 |   j | d | d S)a  
        The Point object may be initialized with either a tuple, or individual
        parameters.

        For Example:
        >>> p = Point((5, 23)) # 2D point, passed in as a tuple
        >>> p = Point(5, 23, 8) # 3D point, passed in with individual parameters
        Nz2Invalid parameters given for Point initialization.srid)
isinstancetuplelistr   integer_typesfloat	TypeError_create_pointlensuperr
   __init__)selfxyzr   coordsZpoint)	__class__ C/var/www/dbchiro/venv/build/Django/django/contrib/gis/geos/point.pyr      s    			2zPoint.__init__c                s,   |  j  r t j j j   St t |   j   S)N)emptyr   Z
geometriesr
   _create_emptyr   _ogr_ptr)r   )r   r   r   r"   /   s    zPoint._ogr_ptrc             C   s   |  j  d  d   S)N)r   )clsr   r   r   r!   2   s    zPoint._create_emptyc             C   s   | s t  j d  S| d k  s+ | d k rD t d t |    n  t  j t d  t |   } t |  } t  j | d t |   t  j	 | d t |   | d k r t  j
 | d t |   n  t  j |  S)zO
        Create a coordinate sequence, set X, Y, [Z], and create point
        Nr   r   zInvalid point dimension: %s   r   )capiZcreate_pointr   strZ	create_csr   iterZcs_setxnextZcs_setyZcs_setz)r#   ndimr   csir   r   r   r   6   s    zPoint._create_pointc             C   sN   |  j  | |  } | r> t j |  j  | |  _ |  j   n t d   d  S)Nz3Geometry resulting from slice deletion was invalid.)r   r%   Zdestroy_geomptrZ_ptrZ_set_csr   )r   lengthitemsr,   r   r   r   	_set_listJ   s    	zPoint._set_listc             C   s   |  j  j | d |  d  S)Nr   )_cssetOrdinate)r   indexvaluer   r   r   _set_singleT   s    zPoint._set_singlec             c   s*   x# t  t |    D] } |  | Vq Wd S)z0Allows iteration over coordinates of this Point.N)r	   r   )r   r+   r   r   r   __iter__W   s    zPoint.__iter__c             C   s"   |  j  r d S|  j r d Sd Sd S)zCReturns the number of dimensions for this Point (either 0, 2 or 3).r   r   r   N)r    hasz)r   r   r   r   __len__\   s
    		zPoint.__len__c             C   s=   | d k r |  j  S| d k r& |  j S| d k r9 |  j Sd  S)Nr   r$   r   )r   r   r   )r   r2   r   r   r   _get_single_externale   s    zPoint._get_single_externalc             C   s   |  j  j d d  S)z%Returns the X component of the Point.r   )r0   getOrdinate)r   r   r   r   r   o   s    zPoint.xc             C   s   |  j  j d d |  d S)z"Sets the X component of the Point.r   N)r0   r1   )r   r3   r   r   r   r   t   s    c             C   s   |  j  j d d  S)z%Returns the Y component of the Point.r$   r   )r0   r9   )r   r   r   r   r   y   s    zPoint.yc             C   s   |  j  j d d |  d S)z"Sets the Y component of the Point.r$   r   N)r0   r1   )r   r3   r   r   r   r   ~   s    c             C   s    |  j  r |  j j d d  Sd S)z%Returns the Z component of the Point.r   r   N)r6   r0   r9   )r   r   r   r   r      s    zPoint.zc             C   s2   |  j  s t d   n  |  j j d d |  d S)z"Sets the Z component of the Point.zCannot set Z on 2D Point.r   r   N)r6   r   r0   r1   )r   r3   r   r   r   r      s    	c             C   s   t  j d t d  |  j S)Nz6`get_x()` is deprecated, use the `x` property instead.r   )warningswarnr   r   )r   r   r   r   get_x   s    
zPoint.get_xc             C   s    t  j d t d  | |  _ d  S)Nz6`set_x()` is deprecated, use the `x` property instead.r   )r:   r;   r   r   )r   r3   r   r   r   set_x   s    
zPoint.set_xc             C   s   t  j d t d  |  j S)Nz6`get_y()` is deprecated, use the `y` property instead.r   )r:   r;   r   r   )r   r   r   r   get_y   s    
zPoint.get_yc             C   s    t  j d t d  | |  _ d  S)Nz6`set_y()` is deprecated, use the `y` property instead.r   )r:   r;   r   r   )r   r3   r   r   r   set_y   s    
zPoint.set_yc             C   s   t  j d t d  |  j S)Nz6`get_z()` is deprecated, use the `z` property instead.r   )r:   r;   r   r   )r   r   r   r   get_z   s    
zPoint.get_zc             C   s    t  j d t d  | |  _ d  S)Nz6`set_z()` is deprecated, use the `z` property instead.r   )r:   r;   r   r   )r   r3   r   r   r   set_z   s    
zPoint.set_zc             C   s
   |  j  j S)zReturns a tuple of the point.)r0   r   )r   r   r   r   r      s    zPoint.tuplec             C   s   | |  j  d <d S)z7Sets the coordinates of the point with the given tuple.r   N)r0   )r   tupr   r   r   r      s    c             C   s   t  j d t d  |  j S)Nz?`get_coords()` is deprecated, use the `tuple` property instead.r   )r:   r;   r   r   )r   r   r   r   
get_coords   s    
zPoint.get_coordsc             C   s    t  j d t d  | |  _ d  S)Nz?`set_coords()` is deprecated, use the `tuple` property instead.r   )r:   r;   r   r   )r   rB   r   r   r   
set_coords   s    
zPoint.set_coords) __name__
__module____qualname__Z
_minlengthZ
_maxlengthZhas_csr   r"   classmethodr!   r   r/   r4   r5   r7   r8   Z_get_single_internalpropertyr   setterr   r   r<   r=   r>   r?   r@   rA   r   rC   rD   r   r   r   )r   r   r
      s<   
	r
   )r:   ctypesr   Zdjango.contrib.gisr   Zdjango.contrib.gis.geosr   r%   Zdjango.contrib.gis.geos.errorr   Z django.contrib.gis.geos.geometryr   Zdjango.utilsr   Zdjango.utils.deprecationr   Zdjango.utils.six.movesr	   r
   r   r   r   r   <module>   s   