
    g                     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      x/var/www/python.vincentserveurtest.ovh/public_html/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|z        y)zCheck the given index.r   zinvalid GEOS Geometry index: %sN)r   
IndexErrorr)   s     r   r'   zGEOSCoordSeq._checkindexF   s)    U&TYY&>FGG 'r   c                 4    |dk  s|dkD  rt        d|z        y)zCheck the given dimension.r   r.   zinvalid ordinate dimension "%d"Nr	   )r   dims     r   	_checkdimzGEOSCoordSeq._checkdimK   s%    7cAg AC GHH 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 r?   )r@   cs_getyr   r   r   r)   s     r   _get_yzGEOSCoordSeq._get_yS   rC   r   c                 f    t        j                  | j                  |t        t	                           S r?   )r@   cs_getzr   r   r   r)   s     r   _get_zzGEOSCoordSeq._get_zV   rC   r   c                 F    t        j                  | j                  ||       y r?   )r@   cs_setxr   r   r*   r5   s      r   _set_xzGEOSCoordSeq._set_xY       TXXue,r   c                 F    t        j                  | j                  ||       y r?   )r@   cs_setyr   rL   s      r   _set_yzGEOSCoordSeq._set_y\   rN   r   c                 F    t        j                  | j                  ||       y r?   )r@   cs_setzr   rL   s      r   _set_zzGEOSCoordSeq._set_z_   rN   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 r?   )rB   rF   r)   s     r   rW   zGEOSCoordSeq._get_point_2df   s    E"DKK$677r   c                 f    | j                  |      | j                  |      | j                  |      fS r?   )rB   rF   rI   r)   s     r   rV   zGEOSCoordSeq._get_point_3di   s*    E"DKK$6E8JKKr   c                 V    |\  }}| j                  ||       | j                  ||       y r?   )rM   rQ   )r   r*   r5   xys        r   r3   zGEOSCoordSeq._set_point_2dl   s'    1E1E1r   c                 |    |\  }}}| j                  ||       | j                  ||       | j                  ||       y r?   )rM   rQ   rT   )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=   r@   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=   r@   cs_setordinater   )r   r`   r*   r5   s       r   setOrdinatezGEOSCoordSeq.setOrdinate~   s4    y!DHHeY>r   c                 &    | j                  d|      S )zGet the X value at the index.r   ra   r)   s     r   getXzGEOSCoordSeq.getX       5))r   c                 *    | j                  d||       y)z(Set X with the value at the given index.r   Nrd   rL   s      r   setXzGEOSCoordSeq.setX       E5)r   c                 &    | j                  d|      S )z#Get the Y value at the given index.   rf   r)   s     r   getYzGEOSCoordSeq.getY   rh   r   c                 *    | j                  d||       y)z(Set Y with the value at the given index.rn   Nrj   rL   s      r   setYzGEOSCoordSeq.setY   rl   r   c                 &    | j                  d|      S )z(Get Z with the value at the given index.r.   rf   r)   s     r   getZzGEOSCoordSeq.getZ   rh   r   c                 *    | j                  d||       y)z(Set Z with the value at the given index.r.   Nrj   rL   s      r   setZzGEOSCoordSeq.setZ   rl   r   c                 d    t        j                  | j                  t        t	                           S )z,Return the size of this coordinate sequence.)r@   
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.)r@   
cs_getdimsr   r   r   r    s    r   r1   zGEOSCoordSeq.dims   rx   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   r@   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r?    ).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.rn   r   c              3   .   K   | ]  } |        y wr?   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".rn   )r   r@   	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=   rB   rF   rI   rM   rQ   rT   propertyr(   rW   rV   r3   r2   ra   rd   rg   rk   ro   rq   rs   ru   r   r1   r|   r   r   r$   r   r   r   r   r   r      s'   MH
)
#0H
I
@@@--- X X8L
R?******
 : : : :  @ 
 
 5 5  r   r   N)r   ctypesr   r   r   r   django.contrib.gis.geosr   r@   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   