o
    ÔèFh¹  ã                   @   sl   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	„ 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                   @   sB  e Zd ZdZeZdHdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd „ ƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!ed9d:„ ƒZ"ed;d<„ ƒZ#ed=d>„ ƒZ$d?d@„ Z%edAdB„ ƒZ&edCdD„ ƒZ'edEdF„ ƒZ(dGS )IÚGEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc                 C   s"   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Úz© r   úY/var/www/html/loop/nvenv/lib/python3.10/site-packages/django/contrib/gis/geos/coordseq.pyÚ__init__   s   

zGEOSCoordSeq.__init__c                 c   s    � t | jƒD ]}| | V  qdS )z3Iterate over each point in the coordinate sequence.N)ÚrangeÚsize)r   Úir   r   r   Ú__iter__   s   €ÿzGEOSCoordSeq.__iter__c                 C   ó   | j S )z7Return the number of points in the coordinate sequence.)r   ©r   r   r   r   Ú__len__!   s   zGEOSCoordSeq.__len__c                 C   s
   t | jƒS )z<Return the string representation of the coordinate sequence.)ÚstrÚtupler   r   r   r   Ú__str__%   s   
zGEOSCoordSeq.__str__c                 C   s   |   |¡ |  |¡S )z8Return the coordinate sequence value at the given index.)Ú_checkindexÚ_point_getter©r   Úindexr   r   r   Ú__getitem__)   s   

zGEOSCoordSeq.__getitem__c                 C   s|   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
|ƒ|kr2t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_setterr   r   r   Ú__setitem__.   s    ÿ
zGEOSCoordSeq.__setitem__c                 C   s(   d|  kr| j k sn td| ƒ‚dS )zCheck the given index.r   zinvalid GEOS Geometry index: %sN)r   Ú
IndexErrorr#   r   r   r   r!   F   s   ÿzGEOSCoordSeq._checkindexc                 C   s    |dk s|dkrt d| ƒ‚dS )zCheck the given dimension.r   r'   zinvalid ordinate dimension "%d"Nr   )r   Údimr   r   r   Ú	_checkdimK   s   ÿzGEOSCoordSeq._checkdimc                 C   ó   t  | j|ttƒ ƒ¡S ©N)ÚcapiÚcs_getxr   r   r   r#   r   r   r   Ú_get_xP   ó   zGEOSCoordSeq._get_xc                 C   r5   r6   )r7   Úcs_getyr   r   r   r#   r   r   r   Ú_get_yS   r:   zGEOSCoordSeq._get_yc                 C   r5   r6   )r7   Úcs_getzr   r   r   r#   r   r   r   Ú_get_zV   r:   zGEOSCoordSeq._get_zc                 C   ó   t  | j||¡ d S r6   )r7   Úcs_setxr   ©r   r$   r.   r   r   r   Ú_set_xY   ó   zGEOSCoordSeq._set_xc                 C   r?   r6   )r7   Úcs_setyr   rA   r   r   r   Ú_set_y\   rC   zGEOSCoordSeq._set_yc                 C   r?   r6   )r7   Úcs_setzr   rA   r   r   r   Ú_set_z_   rC   zGEOSCoordSeq._set_zc                 C   s   | j dkr| jr| jS | jS )Nr&   )r*   r   Ú_get_point_3dÚ_get_point_2dr   r   r   r   r"   b   s   zGEOSCoordSeq._point_getterc                 C   s   |   |¡|  |¡fS r6   )r9   r<   r#   r   r   r   rI   f   rC   zGEOSCoordSeq._get_point_2dc                 C   s   |   |¡|  |¡|  |¡fS r6   )r9   r<   r>   r#   r   r   r   rH   i   s   zGEOSCoordSeq._get_point_3dc                 C   s$   |\}}|   ||¡ |  ||¡ d S r6   )rB   rE   )r   r$   r.   ÚxÚyr   r   r   r,   l   s   zGEOSCoordSeq._set_point_2dc                 C   s2   |\}}}|   ||¡ |  ||¡ |  ||¡ d S r6   )rB   rE   rG   )r   r$   r.   rJ   rK   r   r   r   r   r+   q   s   
zGEOSCoordSeq._set_point_3dc                 C   s,   |   |¡ |  |¡ t | j||ttƒ ƒ¡S )z3Return the value for the given dimension and index.)r!   r4   r7   Úcs_getordinater   r   r   )r   Ú	dimensionr$   r   r   r   ÚgetOrdinatex   s   

zGEOSCoordSeq.getOrdinatec                 C   s*   |   |¡ |  |¡ t | j|||¡ dS )z0Set the value for the given dimension and index.N)r!   r4   r7   Úcs_setordinater   )r   rM   r$   r.   r   r   r   ÚsetOrdinate~   s   

zGEOSCoordSeq.setOrdinatec                 C   ó   |   d|¡S )zGet the X value at the index.r   ©rN   r#   r   r   r   ÚgetX„   ó   zGEOSCoordSeq.getXc                 C   ó   |   d||¡ dS )z(Set X with the value at the given index.r   N©rP   rA   r   r   r   ÚsetXˆ   ó   zGEOSCoordSeq.setXc                 C   rQ   )z#Get the Y value at the given index.é   rR   r#   r   r   r   ÚgetYŒ   rT   zGEOSCoordSeq.getYc                 C   rU   )z(Set Y with the value at the given index.rY   NrV   rA   r   r   r   ÚsetY�   rX   zGEOSCoordSeq.setYc                 C   rQ   )z(Get Z with the value at the given index.r'   rR   r#   r   r   r   ÚgetZ”   rT   zGEOSCoordSeq.getZc                 C   rU   )z(Set Z with the value at the given index.r'   NrV   rA   r   r   r   ÚsetZ˜   rX   zGEOSCoordSeq.setZc                 C   ó   t  | jttƒ ƒ¡S )z,Return the size of this coordinate sequence.)r7   Ú
cs_getsizer   r   r   r   r   r   r   r   �   ó   zGEOSCoordSeq.sizec                 C   r^   )z2Return the dimensions of this coordinate sequence.)r7   Ú
cs_getdimsr   r   r   r   r   r   r   r*   ¢   r`   zGEOSCoordSeq.dimsc                 C   r   )zƒ
        Return whether this coordinate sequence is 3D. This property value is
        inherited from the parent Geometry.
        )r   r   r   r   r   Úhasz§   s   zGEOSCoordSeq.haszc                 C   s   t t | j¡| jƒS )zClone this coordinate sequence.)r   r7   Úcs_cloner   rb   r   r   r   r   Úclone°   s   zGEOSCoordSeq.clonec                    s:   ˆ j rd‰nd‰dd ‡ ‡fdd„ttˆ ƒƒD ƒ¡ ¡  S )z2Return the KML representation for the coordinates.z	%s,%s,%s z%s,%s,0 z<coordinates>%s</coordinates>Ú c                 3   s   � | ]	}ˆˆ |  V  qd S r6   r   ©Ú.0r   ©r   Úsubstrr   r   Ú	<genexpr>¿   s   € z#GEOSCoordSeq.kml.<locals>.<genexpr>)rb   Újoinr   r-   Ústripr   r   rh   r   Úkml´   s   $ÿÿzGEOSCoordSeq.kmlc                    s6   | j }| j‰ |dkrˆ dƒS t‡ fdd„t|ƒD ƒƒS )z3Return a tuple version of this coordinate sequence.rY   r   c                 3   s   � | ]}ˆ |ƒV  qd S r6   r   rf   ©Ú	get_pointr   r   rj   É   s   € z%GEOSCoordSeq.tuple.<locals>.<genexpr>)r   r"   r   r   )r   Únr   rn   r   r   Â   s
   zGEOSCoordSeq.tuplec                 C   s2   t ƒ }t | jt|ƒ¡stdtjj ƒ‚|jdkS )z<Return whether this coordinate sequence is counterclockwise.z*Error encountered in GEOS C function "%s".rY   )r   r7   Ú	cs_is_ccwr   r   r	   Ú	func_namer.   )r   Úretr   r   r   Úis_counterclockwiseË   s   
ÿ
z GEOSCoordSeq.is_counterclockwiseN)F))Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   Úptr_typer   r   r   r    r%   r1   r!   r4   r9   r<   r>   rB   rE   rG   Úpropertyr"   rI   rH   r,   r+   rN   rP   rS   rW   rZ   r[   r\   r]   r   r*   rb   rd   rm   r   rt   r   r   r   r   r      sX    






r   N)rx   Úctypesr   r   r   r   Údjango.contrib.gis.geosr   r7   Údjango.contrib.gis.geos.baser   Údjango.contrib.gis.geos.errorr	   Údjango.contrib.gis.geos.libgeosr
   Údjango.contrib.gis.shortcutsr   r   r   r   r   r   Ú<module>   s    