o
    <g                     @   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__ P/var/www/html/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   wkbr   r   r   r%   .   s   zPoint._from_pickle_wkbc                    s   | j r	tjj S t  S r   )r    r   
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   )
capicreate_pointr   	create_csr   itercs_setxnextcs_sety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+   destroy_geomptr_ptr
_post_initr   )r   lengthitemsr7   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   r5   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   r@   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   r>   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   Nr=   r   rA   r   r   r   r   {      c                 C   s   | j ddS )z$Return the Y component of the Point.r*   r   rH   r"   r   r   r   r      rJ   zPoint.yc                 C   s   | j dd| dS )z!Set the Y component of the Point.r*   r   Nr=   rK   r   r   r   r      rL   c                 C   s   | j r
| jddS dS )z$Return the Z component of the Point.r   r   N)rE   r>   rI   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)rE   r   r>   r?   rK   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      rJ   )NNNN)__name__
__module____qualname__
_minlength
_maxlengthhas_csr   r!   r%   r(   classmethodr$   r   r<   rB   rD   rF   rG   _get_single_internalpropertyr   setterr   r   r   r   __classcell__r   r   r   r   r   	   sF    

	







r   N)ctypesr   django.contrib.gisr   django.contrib.gis.geosr   r+   django.contrib.gis.geos.errorr    django.contrib.gis.geos.geometryr   r   r   r   r   r   <module>   s    