
    _?i                     r    d Z ddlmZmZmZ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  G d d	e
      Zy
)z
This module houses the GEOSCoordSeq object, which is used internally
by GEOSGeometry to house the actual coordinates of the Point,
LineString, and LinearRing geometries.
    )byrefc_bytec_doublec_uint)
prototypes)GEOSBaseGEOSException)CS_PTR)numpyc                   (   e Zd ZdZeZd%dZd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!ed        Z"ed        Z#ed        Z$d  Z%ed!        Z&ed"        Z'ed#        Z(y$)&GEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.c                 V    t        |t              st        d      || _        || _        y)zInitialize from a GEOS pointer.z4Coordinate sequence should initialize with a CS_PTR.N)
isinstancer   	TypeError_ptr_z)selfptrzs      r/home/cursorai/projects/django-cronjob-utils/venv/lib/python3.12/site-packages/django/contrib/gis/geos/coordseq.py__init__zGEOSCoordSeq.__init__   s&    #v&RSS	    c              #   N   K   t        | j                        D ]	  }| |     yw)z3Iterate over each point in the coordinate sequence.N)rangesize)r   is     r   __iter__zGEOSCoordSeq.__iter__   s"     tyy!Aq'M "s   #%c                     | j                   S )z7Return the number of points in the coordinate sequence.)r   r   s    r   __len__zGEOSCoordSeq.__len__!   s    yyr   c                 ,    t        | j                        S )z<Return the string representation of the coordinate sequence.)strtupler    s    r   __str__zGEOSCoordSeq.__str__%   s    4::r   c                 F    | j                  |       | j                  |      S )z8Return the coordinate sequence value at the given index.)_checkindex_point_getterr   indexs     r   __getitem__zGEOSCoordSeq.__getitem__)   s!    !!%((r   c                 `   t        |t        t        f      rn,t        rt        |t        j                        rnt        d      | j                  dk(  r| j                  rd}| j                  }nd}| j                  }t        |      |k7  rt        d      | j                  |        |||       y)z5Set the coordinate sequence value at the given index.zBMust set coordinate with a sequence (list, tuple, or numpy array).      z"Dimension of value does not match.N)r   listr$   r   ndarrayr   dimsr   _set_point_3d_set_point_2dlenr'   )r   r*   valuen_argspoint_setters        r   __setitem__zGEOSCoordSeq.__setitem__.   s     edE]+z%7T  99>dggF--LF--Lu:@AAUE"r   c                 N    d|cxk  r| j                   k  sn t        d|       y)zCheck the given index.r   zInvalid GEOS Geometry index: N)r   
IndexErrorr)   s     r   r'   zGEOSCoordSeq._checkindexF   s+    U&TYY&<UGDEE 'r   c                 8    |dk  s|dkD  rt        d|dd      y)zCheck the given dimension.r   r.   zInvalid ordinate dimension: "d"Nr	   )r   dims     r   	_checkdimzGEOSCoordSeq._checkdimK   s+    7cAg"?Awa HII r   c                 f    t        j                  | j                  |t        t	                           S N)capics_getxr   r   r   r)   s     r   _get_xzGEOSCoordSeq._get_xP        ||DHHeU8:->??r   c                 f    t        j                  | j                  |t        t	                           S rA   )rB   cs_getyr   r   r   r)   s     r   _get_yzGEOSCoordSeq._get_yS   rE   r   c                 f    t        j                  | j                  |t        t	                           S rA   )rB   cs_getzr   r   r   r)   s     r   _get_zzGEOSCoordSeq._get_zV   rE   r   c                 F    t        j                  | j                  ||       y rA   )rB   cs_setxr   r   r*   r5   s      r   _set_xzGEOSCoordSeq._set_xY       TXXue,r   c                 F    t        j                  | j                  ||       y rA   )rB   cs_setyr   rN   s      r   _set_yzGEOSCoordSeq._set_y\   rP   r   c                 F    t        j                  | j                  ||       y rA   )rB   cs_setzr   rN   s      r   _set_zzGEOSCoordSeq._set_z_   rP   r   c                 h    | j                   dk(  r| j                  r| j                  S | j                  S )Nr-   )r1   r   _get_point_3d_get_point_2dr    s    r   r(   zGEOSCoordSeq._point_getterb   s)    %)YY!^t!!WTEWEWWr   c                 F    | j                  |      | j                  |      fS rA   )rD   rH   r)   s     r   rY   zGEOSCoordSeq._get_point_2df   s    E"DKK$677r   c                 f    | j                  |      | j                  |      | j                  |      fS rA   )rD   rH   rK   r)   s     r   rX   zGEOSCoordSeq._get_point_3di   s*    E"DKK$6E8JKKr   c                 V    |\  }}| j                  ||       | j                  ||       y rA   )rO   rS   )r   r*   r5   xys        r   r3   zGEOSCoordSeq._set_point_2dl   s'    1E1E1r   c                 |    |\  }}}| j                  ||       | j                  ||       | j                  ||       y rA   )rO   rS   rV   )r   r*   r5   r]   r^   r   s         r   r2   zGEOSCoordSeq._set_point_3dq   s7    1aE1E1E1r   c           	          | j                  |       | j                  |       t        j                  | j                  ||t        t                           S )z3Return the value for the given dimension and index.)r'   r?   rB   cs_getordinater   r   r   )r   	dimensionr*   s      r   getOrdinatezGEOSCoordSeq.getOrdinatex   s>    y!""488UIuXZ?PQQr   c                     | j                  |       | j                  |       t        j                  | j                  |||       y)z0Set the value for the given dimension and index.N)r'   r?   rB   cs_setordinater   )r   rb   r*   r5   s       r   setOrdinatezGEOSCoordSeq.setOrdinate~   s4    y!DHHeY>r   c                 &    | j                  d|      S )zGet the X value at the index.r   rc   r)   s     r   getXzGEOSCoordSeq.getX       5))r   c                 *    | j                  d||       y)z(Set X with the value at the given index.r   Nrf   rN   s      r   setXzGEOSCoordSeq.setX       E5)r   c                 &    | j                  d|      S )z#Get the Y value at the given index.   rh   r)   s     r   getYzGEOSCoordSeq.getY   rj   r   c                 *    | j                  d||       y)z(Set Y with the value at the given index.rp   Nrl   rN   s      r   setYzGEOSCoordSeq.setY   rn   r   c                 &    | j                  d|      S )z(Get Z with the value at the given index.r.   rh   r)   s     r   getZzGEOSCoordSeq.getZ   rj   r   c                 *    | j                  d||       y)z(Set Z with the value at the given index.r.   Nrl   rN   s      r   setZzGEOSCoordSeq.setZ   rn   r   c                 d    t        j                  | j                  t        t	                           S )z,Return the size of this coordinate sequence.)rB   
cs_getsizer   r   r   r    s    r   r   zGEOSCoordSeq.size        txxvx99r   c                 d    t        j                  | j                  t        t	                           S )z2Return the dimensions of this coordinate sequence.)rB   
cs_getdimsr   r   r   r    s    r   r1   zGEOSCoordSeq.dims   rz   r   c                     | j                   S )z
        Return whether this coordinate sequence is 3D. This property value is
        inherited from the parent Geometry.
        )r   r    s    r   haszzGEOSCoordSeq.hasz   s     wwr   c                 h    t        t        j                  | j                        | j                        S )zClone this coordinate sequence.)r   rB   cs_cloner   r~   r    s    r   clonezGEOSCoordSeq.clone   s     DMM$((3TYY??r   c           	            j                   rdndddj                   fdt        t                     D              j	                         z  S )z2Return the KML representation for the coordinates.z	%s,%s,%s z%s,%s,0 z<coordinates>%s</coordinates> c              3   .   K   | ]  }|   z    y wrA    ).0r   r   substrs     r   	<genexpr>z#GEOSCoordSeq.kml.<locals>.<genexpr>   s     A0@1ftAw&0@   )r~   joinr   r4   strip)r   r   s   `@r   kmlzGEOSCoordSeq.kml   sH    
 99 FF+ggAc$i0@AAGGIJ	
r   c                     | j                   }| j                  |dk(  r d      S t        fdt        |      D              S )z3Return a tuple version of this coordinate sequence.rp   r   c              3   .   K   | ]  } |        y wrA   r   )r   r   	get_points     r   r   z%GEOSCoordSeq.tuple.<locals>.<genexpr>   s     48aYq\8r   )r   r(   r$   r   )r   nr   s     @r   r$   zGEOSCoordSeq.tuple   s?     II&&	6Q<458444r   c                     t               }t        j                  | j                  t	        |            s&t        dt        j                  j                  z        |j                  dk(  S )z<Return whether this coordinate sequence is counterclockwise.z*Error encountered in GEOS C function "%s".rp   )r   rB   	cs_is_ccwr   r   r
   	func_namer5   )r   rets     r   is_counterclockwisez GEOSCoordSeq.is_counterclockwise   sP     h~~dhhc
3<t~~?W?WW  yyA~r   N)F))__name__
__module____qualname____doc__r   ptr_typer   r   r!   r%   r+   r8   r'   r?   rD   rH   rK   rO   rS   rV   propertyr(   rY   rX   r3   r2   rc   rf   ri   rm   rq   rs   ru   rw   r   r1   r~   r   r   r$   r   r   r   r   r   r      s'   MH
)
#0F
J
@@@--- X X8L
R?******
 : : : :  @ 
 
 5 5  r   r   N)r   ctypesr   r   r   r   django.contrib.gis.geosr   rB   django.contrib.gis.geos.baser   django.contrib.gis.geos.errorr
   django.contrib.gis.geos.libgeosr   django.contrib.gis.shortcutsr   r   r   r   r   <module>r      s/    3 2 6 1 7 2 .C8 Cr   