3
[[                 @   sP   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
 G dd de
ZdS )	    )c_uint)gdal)
prototypes)GEOSException)GEOSGeometryc                   s   e Zd ZdZdZdZ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ed d! Zejd"d! ZeZ  ZS )$Point      TNc                s   |dkrg }n\t |ttfr"|}nHt |ttfrbt |ttfrbt |ttfrX|||g}qj||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
        Nz2Invalid parameters given for Point initialization.)srid)

isinstancetuplelistfloatint	TypeError_create_pointlensuper__init__)selfxyzr
   coordsZpoint)	__class__ A/tmp/pip-install-j7i95hgp/django/django/contrib/gis/geos/point.pyr      s    	
zPoint.__init__c                s   | j rtjjj S 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   .   s    zPoint._create_emptyc             C   s   |st jdS |dk s|dkr*td| t jtdt|}t|}t j|dt| t j|dt| |dkrt j	|dt| 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   Z	create_csr   iterZcs_setxnextZcs_setyZcs_setz)r    ndimr   csir   r   r   r   2   s    
zPoint._create_pointc             C   s8   | 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
_post_initr   )r   lengthitemsr(   r   r   r   	_set_listF   s    
zPoint._set_listc             C   s   | j j|d| d S )Nr   )_cssetOrdinate)r   indexvaluer   r   r   _set_singleP   s    zPoint._set_singlec             c   s$   xt t| D ]}| | V  qW dS )z'Iterate over coordinates of this Point.N)ranger   )r   r'   r   r   r   __iter__S   s    zPoint.__iter__c             C   s   | j r
dS | jrdS dS dS )zBReturn the number of dimensions for this Point (either 0, 2 or 3).r   r	   r   N)r   hasz)r   r   r   r   __len__X   s
    zPoint.__len__c             C   s.   |dkr| j S |dkr| jS |dkr*| jS d S )Nr   r!   r   )r   r   r   )r   r.   r   r   r   _get_single_externala   s    zPoint._get_single_externalc             C   s   | j jddS )z$Return the X component of the Point.r   )r,   getOrdinate)r   r   r   r   r   k   s    zPoint.xc             C   s   | j jdd| dS )z!Set the X component of the Point.r   N)r,   r-   )r   r/   r   r   r   r   p   s    c             C   s   | j jddS )z$Return the Y component of the Point.r!   r   )r,   r6   )r   r   r   r   r   u   s    zPoint.yc             C   s   | j jdd| dS )z!Set the Y component of the Point.r!   r   N)r,   r-   )r   r/   r   r   r   r   z   s    c             C   s   | j r| jjddS dS )z$Return the Z component of the Point.r   r   N)r3   r,   r6   )r   r   r   r   r      s    zPoint.zc             C   s"   | j std| jjdd| dS )z!Set the Z component of the Point.zCannot set Z on 2D Point.r   r   N)r3   r   r,   r-   )r   r/   r   r   r   r      s    c             C   s   | j jS )zReturn a tuple of the point.)r,   r   )r   r   r   r   r      s    zPoint.tuplec             C   s   || j d< dS )z6Set the coordinates of the point with the given tuple.r   N)r,   )r   tupr   r   r   r      s    )NNNN)__name__
__module____qualname__Z
_minlengthZ
_maxlengthZhas_csr   r   classmethodr   r   r+   r0   r2   r4   r5   Z_get_single_internalpropertyr   setterr   r   r   r   __classcell__r   r   )r   r   r   	   s,   
	r   N)ctypesr   Zdjango.contrib.gisr   Zdjango.contrib.gis.geosr   r"   Zdjango.contrib.gis.geos.errorr   Z django.contrib.gis.geos.geometryr   r   r   r   r   r   <module>   s
   