
    Dvg                     z    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d
S )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                   T   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(d%S )'GEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc                 j    t          |t                    st          d          || _        || _        dS )zInitialize from a GEOS pointer.z4Coordinate sequence should initialize with a CS_PTR.N)
isinstancer   	TypeError_ptr_z)selfptrzs      ]/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/gis/geos/coordseq.py__init__zGEOSCoordSeq.__init__   s6    #v&& 	TRSSS	    c              #   L   K   t          | j                  D ]}| |         V  dS )z3Iterate over each point in the coordinate sequence.N)rangesize)r   is     r   __iter__zGEOSCoordSeq.__iter__   s8      ty!! 	 	Aq'MMMM	 	r   c                     | j         S )z7Return the number of points in the coordinate sequence.)r   r   s    r   __len__zGEOSCoordSeq.__len__!   s
    y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                 V    |                      |           |                     |          S )z8Return the coordinate sequence value at the given index.)_checkindex_point_getterr   indexs     r   __getitem__zGEOSCoordSeq.__getitem__)   s*    !!%(((r   c                 r   t          |t          t          f          rn1t          rt          |t          j                  rnt          d          | j        dk    r| j        r
d}| j        }n	d}| j	        }t          |          |k    rt          d          |                     |            |||           dS )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7 	T   9>>dg>F-LLF-Lu::@AAAUE"""""r   c                 R    d|cxk    r| j         k     sn t          d|z            dS )zCheck the given index.r   zinvalid GEOS Geometry index: %sN)r   
IndexErrorr)   s     r   r'   zGEOSCoordSeq._checkindexF   s?    U&&&&TY&&&&>FGGG '&r   c                 B    |dk     s|dk    rt          d|z            dS )zCheck the given dimension.r   r.   zinvalid ordinate dimension "%d"Nr	   )r   dims     r   	_checkdimzGEOSCoordSeq._checkdimK   s.    77cAgg AC GHHH gr   c                 j    t          j        | j        |t          t	                                          S N)capics_getxr   r   r   r)   s     r   _get_xzGEOSCoordSeq._get_xP   $    |DHeU8::->->???r   c                 j    t          j        | j        |t          t	                                          S r?   )r@   cs_getyr   r   r   r)   s     r   _get_yzGEOSCoordSeq._get_yS   rC   r   c                 j    t          j        | j        |t          t	                                          S r?   )r@   cs_getzr   r   r   r)   s     r   _get_zzGEOSCoordSeq._get_zV   rC   r   c                 <    t          j        | j        ||           d S r?   )r@   cs_setxr   r   r*   r5   s      r   _set_xzGEOSCoordSeq._set_xY       TXue,,,,,r   c                 <    t          j        | j        ||           d S r?   )r@   cs_setyr   rL   s      r   _set_yzGEOSCoordSeq._set_y\   rN   r   c                 <    t          j        | j        ||           d S r?   )r@   cs_setzr   rL   s      r   _set_zzGEOSCoordSeq._set_z_   rN   r   c                 B    | j         dk    r| j        r| j        n| j        S )Nr-   )r1   r   _get_point_3d_get_point_2dr    s    r   r(   zGEOSCoordSeq._point_getterb   s#    %)Y!^^^t!!TEWWr   c                 V    |                      |          |                     |          fS r?   )rB   rF   r)   s     r   rW   zGEOSCoordSeq._get_point_2df   s%    E""DKK$6$677r   c                 ~    |                      |          |                     |          |                     |          fS r?   )rB   rF   rI   r)   s     r   rV   zGEOSCoordSeq._get_point_3di   s3    E""DKK$6$6E8J8JKKr   c                 h    |\  }}|                      ||           |                     ||           d S r?   )rM   rQ   )r   r*   r5   xys        r   r3   zGEOSCoordSeq._set_point_2dl   s9    1E1E1r   c                     |\  }}}|                      ||           |                     ||           |                     ||           d S r?   )rM   rQ   rT   )r   r*   r5   r[   r\   r   s         r   r2   zGEOSCoordSeq._set_point_3dq   sO    1aE1E1E1r   c           	          |                      |           |                     |           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   sM    y!!!"48UIuXZZ?P?PQQQr   c                     |                      |           |                     |           t          j        | j        |||           dS )z0Set the value for the given dimension and index.N)r'   r=   r@   cs_setordinater   )r   r`   r*   r5   s       r   setOrdinatezGEOSCoordSeq.setOrdinate~   sG    y!!!DHeY>>>>>r   c                 .    |                      d|          S )zGet the X value at the index.r   ra   r)   s     r   getXzGEOSCoordSeq.getX       5)))r   c                 4    |                      d||           dS )z(Set X with the value at the given index.r   Nrd   rL   s      r   setXzGEOSCoordSeq.setX        E5)))))r   c                 .    |                      d|          S )z#Get the Y value at the given index.   rf   r)   s     r   getYzGEOSCoordSeq.getY   rh   r   c                 4    |                      d||           dS )z(Set Y with the value at the given index.rn   Nrj   rL   s      r   setYzGEOSCoordSeq.setY   rl   r   c                 .    |                      d|          S )z(Get Z with the value at the given index.r.   rf   r)   s     r   getZzGEOSCoordSeq.getZ   rh   r   c                 4    |                      d||           dS )z(Set Z with the value at the given index.r.   Nrj   rL   s      r   setZzGEOSCoordSeq.setZ   rl   r   c                 h    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   "     txvxx999r   c                 h    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     wr   c                 Z    t          t          j        | j                  | j                  S )zClone this coordinate sequence.)r   r@   cs_cloner   r|   r    s    r   clonezGEOSCoordSeq.clone   s     DM$(33TY???r   c           	            j         rdnddd                     fdt          t                               D                                                       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  V  d S r?    ).0r   r   substrs     r   	<genexpr>z#GEOSCoordSeq.kml.<locals>.<genexpr>   s,      AA1ftAw&AAAAAAr   )r|   joinr   r4   strip)r   r   s   `@r   kmlzGEOSCoordSeq.kml   sk    
 9 	  FFF+ggAAAAAc$ii0@0@AAAAAGGI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   | ]} |          V  d S r?   r   )r   r   	get_points     r   r   z%GEOSCoordSeq.tuple.<locals>.<genexpr>   s+      44aYYq\\444444r   )r   r(   r$   r   )r   nr   s     @r   r$   zGEOSCoordSeq.tuple   sT     I&	669Q<<4444588444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   sV     hh~dhc

33 	<t~?WW   yA~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MH     
    ) ) )
# # #0H H H
I I I
@ @ @@ @ @@ @ @- - -- - -- - - X X XX8 8 8L L L  
  R R R? ? ?* * ** * ** * ** * ** * ** * *
 : : X: : : X:   X@ @ @ 
 
 X
 5 5 X5   X  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 2 2 2 2 2 2 2 2 2 2 6 6 6 6 6 6 1 1 1 1 1 1 7 7 7 7 7 7 2 2 2 2 2 2 . . . . . .C C C C C8 C C C C Cr   