o
    [h                     @   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u rg }n.t |ttfr|}n$t |ttfr1t |ttfr1t |ttfr,|||g}n	||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
   coordspoint	__class__ /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/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!   +      zPoint._to_pickle_wkbc                    s   |d u 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rBt 	|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   sJ   |  ||}|r!| j}t| j || _|d ur|| _|   d S td)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[   r#   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 )zBReturn the number of dimensions for this Point (either 0, 2 or 3).r   r	   r   )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   r6   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   r4   getOrdinater"   r   r   r   r   v      zPoint.xc                 C   s   | j dd| dS )z!Set the X component of the Point.r   Nr3   r   r7   r   r   r   r   {      c                 C   s   | j ddS )z$Return the Y component of the Point.r(   r   r>   r"   r   r   r   r      r@   zPoint.yc                 C   s   | j dd| dS )z!Set the Y component of the Point.r(   r   Nr3   rA   r   r   r   r      rB   c                 C   s   | j r
| jddS dS )z$Return the Z component of the Point.r   r   N)r;   r4   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)r;   r   r4   r5   rA   r   r   r   r      s   c                 C   s   | j jS )zReturn a tuple of the point.)r4   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)r4   )r   tupr   r   r   r      r@   )NNNN)__name__
__module____qualname__Z
_minlengthZ
_maxlengthZhas_csr   r!   r%   r&   classmethodr$   r   r2   r8   r:   r<   r=   Z_get_single_internalpropertyr   setterr   r   r   r   __classcell__r   r   r   r   r   	   sF    

	







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    