

_VC                 @   sz   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)
    )c_uint)
prototypes)GEOSException)GEOSGeometry)six)rangec                   s-  e  Z d  Z d Z d Z d Z d d d   f d d  Z d d   Z d	 d
   Z d d   Z	 d d   Z
 d d   Z d d   Z e Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z e e e  Z e e e  Z e e e  Z d d    Z d! d"   Z e e e  Z e Z   S)#Point      TNc                s   t  | t t f  r* t |  } | } n t  | t j t f  r t  | t j t f  r t  | t j t f  r d } | | | g } q d } | | g } n t d   |  j | |  } 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
        r
   r	   z2Invalid parameters given for Point initialization.sridN)
isinstancetuplelistlenr   integer_typesfloat	TypeError_create_pointsuperr   __init__)selfxyzr   ndimcoordsZpoint)	__class__ ?/tmp/pip-build-ghmbqnp_/Django/django/contrib/gis/geos/point.pyr      s    		2zPoint.__init__c             C   s   | d k  s | d k r1 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
        r	   r
   zInvalid point dimension: %s   r   )r   strcapiZ	create_csr   iterZcs_setxnextZcs_setyZcs_setzZcreate_point)r   r   r   csir   r   r   r   -   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_list=   s    	zPoint._set_listc             C   s   |  j  j | d |  d  S)Nr   )_cssetOrdinate)r   indexvaluer   r   r   _set_singleG   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__J   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)emptyhasz)r   r   r   r   __len__O   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   r,   r   r   r   _get_single_externalX   s    zPoint._get_single_externalc             C   s   |  j  j d d  S)z%Returns the X component of the Point.r   )r*   getOrdinate)r   r   r   r   get_xb   s    zPoint.get_xc             C   s   |  j  j d d |  d S)z"Sets the X component of the Point.r   N)r*   r+   )r   r-   r   r   r   set_xf   s    zPoint.set_xc             C   s   |  j  j d d  S)z%Returns the Y component of the Point.r   r   )r*   r4   )r   r   r   r   get_yj   s    zPoint.get_yc             C   s   |  j  j d d |  d S)z"Sets the Y component of the Point.r   r   N)r*   r+   )r   r-   r   r   r   set_yn   s    zPoint.set_yc             C   s$   |  j  r |  j j d d  Sd Sd S)z%Returns the Z component of the Point.r	   r   N)r1   r*   r4   )r   r   r   r   get_zr   s    	zPoint.get_zc             C   s2   |  j  r" |  j j d d |  n t d   d S)z"Sets the Z component of the Point.r	   r   zCannot set Z on 2D Point.N)r1   r*   r+   r   )r   r-   r   r   r   set_zy   s    	zPoint.set_zc             C   s
   |  j  j S)zReturns a tuple of the point.)r*   r   )r   r   r   r   
get_coords   s    zPoint.get_coordsc             C   s   | |  j  d <d S)z7Sets the coordinates of the point with the given tuple.r   N)r*   )r   tupr   r   r   
set_coords   s    zPoint.set_coords)__name__
__module____qualname__Z
_minlengthZ
_maxlengthZhas_csr   r   r)   r.   r/   r2   r3   Z_get_single_internalr5   r6   r7   r8   r9   r:   propertyr   r   r   r;   r=   r   r   r   r   )r   r   r   
   s0   
	r   N)ctypesr   Zdjango.contrib.gis.geosr   r!   Zdjango.contrib.gis.geos.errorr   Z django.contrib.gis.geos.geometryr   Zdjango.utilsr   Zdjango.utils.six.movesr   r   r   r   r   r   <module>   s   