U
    d                     @   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 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| 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-unpacked-wheel-7vj2equ7/django/contrib/gis/geos/point.pyr      s    	
zPoint.__init__c                    s   | j r
d S t  S N)emptyr   _to_pickle_wkbr   r   r   r   r    +   s    zPoint._to_pickle_wkbc                    s   |d kr|   S t |S r   )_create_emptyr   _from_pickle_wkb)r   Zwkbr   r   r   r#   .   s    zPoint._from_pickle_wkbc                    s   | j rtjj S t  S r   )r   r   Z
geometriesr   r"   r   _ogr_ptrr!   r   r   r   r$   1   s    zPoint._ogr_ptrc                 C   s   |  d d S r   )r   )clsr   r   r   r"   6   s    zPoint._create_emptyc                 C   s   |st dS |dk s|dkr*td| t tdt|}t|}t |dt| t |dt| |dkrt 	|dt| t |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   :   s    
zPoint._create_pointc                 C   sL   |  ||}|r@| j}t| j || _|d k	r6|| _|   ntdd S )Nz3Geometry resulting from slice deletion was invalid.)r   r
   r'   Zdestroy_geomptrZ_ptrZ
_post_initr   )r   lengthitemsr-   r
   r   r   r   	_set_listN   s    
zPoint._set_listc                 C   s   | j |d| d S )Nr   _cssetOrdinate)r   indexvaluer   r   r   _set_single[   s    zPoint._set_singlec                 c   s    t t| D ]}| | V  qdS )z'Iterate over coordinates of this Point.N)ranger   )r   r,   r   r   r   __iter__^   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   haszr!   r   r   r   __len__c   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   r4   r   r   r   _get_single_externall   s    zPoint._get_single_externalc                 C   s   | j ddS )z$Return the X component of the Point.r   r2   getOrdinater!   r   r   r   r   v   s    zPoint.xc                 C   s   | j dd| dS )z!Set the X component of the Point.r   Nr1   r   r5   r   r   r   r   {   s    c                 C   s   | j ddS )z$Return the Y component of the Point.r&   r   r<   r!   r   r   r   r      s    zPoint.yc                 C   s   | j dd| dS )z!Set the Y component of the Point.r&   r   Nr1   r>   r   r   r   r      s    c                 C   s   | j r| jddS dS )z$Return the Z component of the Point.r   r   N)r9   r2   r=   r!   r   r   r   r      s    zPoint.zc                 C   s"   | j std| jdd| dS )z!Set the Z component of the Point.zCannot set Z on 2D Point.r   r   N)r9   r   r2   r3   r>   r   r   r   r      s    c                 C   s   | j jS )zReturn a tuple of the point.)r2   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)r2   )r   tupr   r   r   r      s    )NNNN)__name__
__module____qualname__Z
_minlengthZ
_maxlengthZhas_csr   r    r#   r$   classmethodr"   r   r0   r6   r8   r:   r;   Z_get_single_internalpropertyr   setterr   r   r   r   __classcell__r   r   r   r   r   	   sD   

	







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
   