
    Hwgt                     v    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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geos_version_tuple)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      W/var/www/horilla/myenv/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._checkindexE   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._checkdimJ   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_xO        ||DHHeU8:->??r   c                 f    t        j                  | j                  |t        t	                           S r@   )rA   cs_getyr   r   r   r*   s     r   _get_yzGEOSCoordSeq._get_yR   rD   r   c                 f    t        j                  | j                  |t        t	                           S r@   )rA   cs_getzr   r   r   r*   s     r   _get_zzGEOSCoordSeq._get_zU   rD   r   c                 F    t        j                  | j                  ||       y r@   )rA   cs_setxr   r   r+   r6   s      r   _set_xzGEOSCoordSeq._set_xX       TXXue,r   c                 F    t        j                  | j                  ||       y r@   )rA   cs_setyr   rM   s      r   _set_yzGEOSCoordSeq._set_y[   rO   r   c                 F    t        j                  | j                  ||       y r@   )rA   cs_setzr   rM   s      r   _set_zzGEOSCoordSeq._set_z^   rO   r   c                 h    | j                   dk(  r| j                  r| j                  S | j                  S )Nr.   )r2   r   _get_point_3d_get_point_2dr!   s    r   r)   zGEOSCoordSeq._point_gettera   s)    %)YY!^t!!WTEWEWWr   c                 F    | j                  |      | j                  |      fS r@   )rC   rG   r*   s     r   rX   zGEOSCoordSeq._get_point_2de   s    E"DKK$677r   c                 f    | j                  |      | j                  |      | j                  |      fS r@   )rC   rG   rJ   r*   s     r   rW   zGEOSCoordSeq._get_point_3dh   s*    E"DKK$6E8JKKr   c                 V    |\  }}| j                  ||       | j                  ||       y r@   )rN   rR   )r   r+   r6   xys        r   r4   zGEOSCoordSeq._set_point_2dk   s'    1E1E1r   c                 |    |\  }}}| j                  ||       | j                  ||       | j                  ||       y r@   )rN   rR   rU   )r   r+   r6   r\   r]   r   s         r   r3   zGEOSCoordSeq._set_point_3dp   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>   rA   cs_getordinater   r   r   )r   	dimensionr+   s      r   getOrdinatezGEOSCoordSeq.getOrdinatew   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>   rA   cs_setordinater   )r   ra   r+   r6   s       r   setOrdinatezGEOSCoordSeq.setOrdinate}   s4    y!DHHeY>r   c                 &    | j                  d|      S )zGet the X value at the index.r   rb   r*   s     r   getXzGEOSCoordSeq.getX       5))r   c                 *    | j                  d||       y)z(Set X with the value at the given index.r   Nre   rM   s      r   setXzGEOSCoordSeq.setX       E5)r   c                 &    | j                  d|      S )z#Get the Y value at the given index.   rg   r*   s     r   getYzGEOSCoordSeq.getY   ri   r   c                 *    | j                  d||       y)z(Set Y with the value at the given index.ro   Nrk   rM   s      r   setYzGEOSCoordSeq.setY   rm   r   c                 &    | j                  d|      S )z(Get Z with the value at the given index.r/   rg   r*   s     r   getZzGEOSCoordSeq.getZ   ri   r   c                 *    | j                  d||       y)z(Set Z with the value at the given index.r/   Nrk   rM   s      r   setZzGEOSCoordSeq.setZ   rm   r   c                 d    t        j                  | j                  t        t	                           S )z,Return the size of this coordinate sequence.)rA   
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.)rA   
cs_getdimsr   r   r   r!   s    r   r2   zGEOSCoordSeq.dims   ry   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   rA   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     A1ftAw&A   )r}   joinr   r5   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.ro   r   c              3   .   K   | ]  } |        y wr@   r   )r   r   	get_points     r   r   z%GEOSCoordSeq.tuple.<locals>.<genexpr>   s     4aYq\4r   )r   r)   r%   r   )r   nr   s     @r   r%   zGEOSCoordSeq.tuple   s?     II&&	6Q<458444r   c                    t               dk  rRd}t        |       }t        |      D ]2  }|dz   |z  }|| |   d   | |   d   z  z  }|| |   d   | |   d   z  z  }4 |dkD  S t               }t	        j
                  | j                  t        |            s&t        dt        j
                  j                  z        |j                  dk(  S )z<Return whether this coordinate sequence is counterclockwise.)r.      g        ro   r   z*Error encountered in GEOS C function "%s".)r   r5   r   r   rA   	cs_is_ccwr   r   r
   	func_namer6   )r   arear   r   jrets         r   is_counterclockwisez GEOSCoordSeq.is_counterclockwise   s     &( DD	A1X 0UaKQ
T!WQZ//Q
T!WQZ//0 #:h~~dhhc
3<t~~?W?WW  yyA~r   N)F))__name__
__module____qualname____doc__r   ptr_typer   r   r"   r&   r,   r9   r(   r>   rC   rG   rJ   rN   rR   rU   propertyr)   rX   rW   r4   r3   rb   re   rh   rl   rp   rr   rt   rv   r   r2   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   rA   django.contrib.gis.geos.baser   django.contrib.gis.geos.errorr
   django.contrib.gis.geos.libgeosr   r   django.contrib.gis.shortcutsr   r   r   r   r   <module>r      s/   
 3 2 6 1 7 F .M8 Mr   