
     ht                     ~    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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geos_version_tuple)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/surfInsights/venv3-11/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._checkindexE   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._checkdimJ   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_xO   $    |DHeU8::->->???r   c                 j    t          j        | j        |t          t	                                          S r@   )rA   cs_getyr   r   r   r*   s     r   _get_yzGEOSCoordSeq._get_yR   rD   r   c                 j    t          j        | j        |t          t	                                          S r@   )rA   cs_getzr   r   r   r*   s     r   _get_zzGEOSCoordSeq._get_zU   rD   r   c                 <    t          j        | j        ||           d S r@   )rA   cs_setxr   r   r+   r6   s      r   _set_xzGEOSCoordSeq._set_xX       TXue,,,,,r   c                 <    t          j        | j        ||           d S r@   )rA   cs_setyr   rM   s      r   _set_yzGEOSCoordSeq._set_y[   rO   r   c                 <    t          j        | j        ||           d S r@   )rA   cs_setzr   rM   s      r   _set_zzGEOSCoordSeq._set_z^   rO   r   c                 B    | j         dk    r| j        r| j        n| j        S )Nr.   )r2   r   _get_point_3d_get_point_2dr!   s    r   r)   zGEOSCoordSeq._point_gettera   s#    %)Y!^^^t!!TEWWr   c                 V    |                      |          |                     |          fS r@   )rC   rG   r*   s     r   rX   zGEOSCoordSeq._get_point_2de   s%    E""DKK$6$677r   c                 ~    |                      |          |                     |          |                     |          fS r@   )rC   rG   rJ   r*   s     r   rW   zGEOSCoordSeq._get_point_3dh   s3    E""DKK$6$6E8J8JKKr   c                 h    |\  }}|                      ||           |                     ||           d S r@   )rN   rR   )r   r+   r6   xys        r   r4   zGEOSCoordSeq._set_point_2dk   s9    1E1E1r   c                     |\  }}}|                      ||           |                     ||           |                     ||           d S r@   )rN   rR   rU   )r   r+   r6   r\   r]   r   s         r   r3   zGEOSCoordSeq._set_point_3dp   sO    1aE1E1E1r   c           	          |                      |           |                     |           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   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>   rA   cs_setordinater   )r   ra   r+   r6   s       r   setOrdinatezGEOSCoordSeq.setOrdinate}   sG    y!!!DHeY>>>>>r   c                 .    |                      d|          S )zGet the X value at the index.r   rb   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re   rM   s      r   setXzGEOSCoordSeq.setX        E5)))))r   c                 .    |                      d|          S )z#Get the Y value at the given index.   rg   r*   s     r   getYzGEOSCoordSeq.getY   ri   r   c                 4    |                      d||           dS )z(Set Y with the value at the given index.ro   Nrk   rM   s      r   setYzGEOSCoordSeq.setY   rm   r   c                 .    |                      d|          S )z(Get Z with the value at the given index.r/   rg   r*   s     r   getZzGEOSCoordSeq.getZ   ri   r   c                 4    |                      d||           dS )z(Set Z with the value at the given index.r/   Nrk   rM   s      r   setZzGEOSCoordSeq.setZ   rm   r   c                 h    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   "     txvxx999r   c                 h    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     wr   c                 Z    t          t          j        | j                  | j                  S )zClone this coordinate sequence.)r   rA   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   r5   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.ro   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                      dk     rqd}t          |           }t          |          D ]J}|dz   |z  }|| |         d         | |         d         z  z  }|| |         d         | |         d         z  z  }K|dk    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1XX 0 0UaKQ
T!WQZ//Q
T!WQZ//#:hh~dhc

33 	<t~?WW   yA~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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   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 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 F F F F F F F F . . . . . .M M M M M8 M M M M Mr   