B
    CVvg@  ã               @   sp   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	„ 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               @   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	   Ú	TypeErrorZ_ptrÚ_z)ÚselfÚptrÚz© r   úD/tmp/pip-install-o3oxmrkh/Django/django/contrib/gis/geos/coordseq.pyÚ__init__   s    
zGEOSCoordSeq.__init__c             c   s"   xt | jƒD ]}| | V  qW dS )z3Iterate over each point in the coordinate sequence.N)ÚrangeÚsize)r   Úir   r   r   Ú__iter__   s    zGEOSCoordSeq.__iter__c             C   s   | 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Útuple)r   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rF| jrFd}| j}n
d}| j	}t
|ƒ|krdt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   Zndarrayr   Údimsr   Ú_set_point_3dÚ_set_point_2dÚlenr   )r   r    ÚvalueZn_argsZ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   Ú
IndexError)r   r    r   r   r   r   C   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"N)r   )r   Zdimr   r   r   Ú	_checkdimH   s    zGEOSCoordSeq._checkdimc             C   s   t  | j|ttƒ ƒ¡S )N)ÚcapiZcs_getxr   r   r   )r   r    r   r   r   Ú_get_xM   s    zGEOSCoordSeq._get_xc             C   s   t  | j|ttƒ ƒ¡S )N)r-   Zcs_getyr   r   r   )r   r    r   r   r   Ú_get_yP   s    zGEOSCoordSeq._get_yc             C   s   t  | j|ttƒ ƒ¡S )N)r-   Zcs_getzr   r   r   )r   r    r   r   r   Ú_get_zS   s    zGEOSCoordSeq._get_zc             C   s   t  | j||¡ d S )N)r-   Zcs_setxr   )r   r    r)   r   r   r   Ú_set_xV   s    zGEOSCoordSeq._set_xc             C   s   t  | j||¡ d S )N)r-   Zcs_setyr   )r   r    r)   r   r   r   Ú_set_yY   s    zGEOSCoordSeq._set_yc             C   s   t  | j||¡ d S )N)r-   Zcs_setzr   )r   r    r)   r   r   r   Ú_set_z\   s    zGEOSCoordSeq._set_zc             C   s   | j dkr| jr| jS | jS )Nr"   )r%   r   Ú_get_point_3dÚ_get_point_2d)r   r   r   r   r   _   s    zGEOSCoordSeq._point_getterc             C   s   |   |¡|  |¡fS )N)r.   r/   )r   r    r   r   r   r5   c   s    zGEOSCoordSeq._get_point_2dc             C   s   |   |¡|  |¡|  |¡fS )N)r.   r/   r0   )r   r    r   r   r   r4   f   s    zGEOSCoordSeq._get_point_3dc             C   s$   |\}}|   ||¡ |  ||¡ d S )N)r1   r2   )r   r    r)   ÚxÚyr   r   r   r'   i   s    zGEOSCoordSeq._set_point_2dc             C   s2   |\}}}|   ||¡ |  ||¡ |  ||¡ d S )N)r1   r2   r3   )r   r    r)   r6   r7   r   r   r   r   r&   n   s    
zGEOSCoordSeq._set_point_3dc             C   s,   |   |¡ |  |¡ t | j||ttƒ ƒ¡S )z3Return the value for the given dimension and index.)r   r,   r-   Zcs_getordinater   r   r   )r   Ú	dimensionr    r   r   r   ÚgetOrdinateu   s    

zGEOSCoordSeq.getOrdinatec             C   s*   |   |¡ |  |¡ t | j|||¡ dS )z0Set the value for the given dimension and index.N)r   r,   r-   Zcs_setordinater   )r   r8   r    r)   r   r   r   ÚsetOrdinate{   s    

zGEOSCoordSeq.setOrdinatec             C   s   |   d|¡S )zGet the X value at the index.r   )r9   )r   r    r   r   r   ÚgetX   s    zGEOSCoordSeq.getXc             C   s   |   d||¡ dS )z(Set X with the value at the given index.r   N)r:   )r   r    r)   r   r   r   ÚsetX…   s    zGEOSCoordSeq.setXc             C   s   |   d|¡S )z#Get the Y value at the given index.é   )r9   )r   r    r   r   r   ÚgetY‰   s    zGEOSCoordSeq.getYc             C   s   |   d||¡ dS )z(Set Y with the value at the given index.r=   N)r:   )r   r    r)   r   r   r   ÚsetY   s    zGEOSCoordSeq.setYc             C   s   |   d|¡S )z(Get Z with the value at the given index.r#   )r9   )r   r    r   r   r   ÚgetZ‘   s    zGEOSCoordSeq.getZc             C   s   |   d||¡ dS )z(Set Z with the value at the given index.r#   N)r:   )r   r    r)   r   r   r   ÚsetZ•   s    zGEOSCoordSeq.setZc             C   s   t  | jttƒ ƒ¡S )z,Return the size of this coordinate sequence.)r-   Z
cs_getsizer   r   r   )r   r   r   r   r   š   s    zGEOSCoordSeq.sizec             C   s   t  | jttƒ ƒ¡S )z2Return the dimensions of this coordinate sequence.)r-   Z
cs_getdimsr   r   r   )r   r   r   r   r%   Ÿ   s    zGEOSCoordSeq.dimsc             C   s   | j S )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   r-   Z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 )Nr   )Ú.0r   )r   Úsubstrr   r   ú	<genexpr>»   s    z#GEOSCoordSeq.kml.<locals>.<genexpr>)rB   Újoinr   r(   Ústrip)r   r   )r   rF   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.r=   r   c             3   s   | ]}ˆ |ƒV  qd S )Nr   )rE   r   )Ú	get_pointr   r   rG   Ä   s    z%GEOSCoordSeq.tuple.<locals>.<genexpr>)r   r   r   r   )r   Únr   )rK   r   r   ½   s
    zGEOSCoordSeq.tuplec             C   s¦   t ƒ dk rtd}t| ƒ}xTt|ƒD ]H}|d | }|| | d | | d  7 }|| | d | | d  8 }q W |dkS tƒ }t | jt|ƒ¡sœtdtjj	 ƒ‚|j
dkS )z<Return whether this coordinate sequence is counterclockwise.)r"   é   g        r=   r   z*Error encountered in GEOS C function "%s".)r
   r(   r   r   r-   Z	cs_is_ccwr   r   r   Ú	func_namer)   )r   ÚarearL   r   ÚjÚretr   r   r   Úis_counterclockwiseÆ   s    
 z GEOSCoordSeq.is_counterclockwiseN)F))Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   Zptr_typer   r   r   r   r!   r*   r   r,   r.   r/   r0   r1   r2   r3   Úpropertyr   r5   r4   r'   r&   r9   r:   r;   r<   r>   r?   r@   rA   r   r%   rB   rC   rJ   r   rR   r   r   r   r   r      sH   
		r   N)rV   Úctypesr   r   r   r   Zdjango.contrib.gis.geosr   r-   Zdjango.contrib.gis.geos.baser   Zdjango.contrib.gis.geos.errorr   Zdjango.contrib.gis.geos.libgeosr	   r
   Zdjango.contrib.gis.shortcutsr   r   r   r   r   r   Ú<module>   s   