3
(hj  ใ               @   st   d Z ddl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 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_doubleฺc_uint)ฺ
prototypes)ฺGEOSBase)ฺGEOSException)ฺCS_PTR)ฺnumpy)ฺrangec               @   sฺ   e Zd ZdZeZd0d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dd  Zd!d" Zed#d$ Zed%d& Zed'd( Zd)d* Zed+d, Zed-d. Zd/S )1ฺGEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc             C   s"   t |tstd|| _|| _dS )z Initializes 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-q3hcpn_q/Django/django/contrib/gis/geos/coordseq.pyฺ__init__   s    
zGEOSCoordSeq.__init__c             c   s"   xt | jD ]}| | V  qW dS )z4Iterates over each point in the coordinate sequence.N)r
   ฺsize)r   ฺir   r   r   ฺ__iter__   s    zGEOSCoordSeq.__iter__c             C   s
   t | jS )z8Returns the number of points in the coordinate sequence.)ฺintr   )r   r   r   r   ฺ__len__!   s    zGEOSCoordSeq.__len__c             C   s
   t | jS )z=Returns the string representation of the coordinate sequence.)ฺstrฺtuple)r   r   r   r   ฺ__str__%   s    zGEOSCoordSeq.__str__c             C   s<   | j || j|g}| jdkr4| jr4|j| j| t|S )z9Returns the coordinate sequence value at the given index.้   )ฺgetXฺgetYฺdimsr   ฺappendฺgetZr   )r   ฺindexZcoordsr   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rD| jrDd}d}nd}d}t||kr`td| j	||d  | j
||d  |r| j||d  d	S )
z6Sets the coordinate sequence value at the given index.zBMust set coordinate with a sequence (list, tuple, or numpy array).r   T้   Fz"Dimension of value does not match.r   ้   N)r   ฺlistr   r	   Zndarrayr   r    r   ฺlenฺsetXฺsetYฺsetZ)r   r#   ฺvalueZn_argsZset_3dr   r   r   ฺ__setitem__0   s     zGEOSCoordSeq.__setitem__c             C   s2   | j }|dk s|dk s||kr.tdt| dS )zChecks the given index.r&   r   zinvalid GEOS Geometry index: %sN)r   ฺ
IndexErrorr   )r   r#   ฺszr   r   r   ฺ_checkindexI   s    zGEOSCoordSeq._checkindexc             C   s    |dk s|dkrt d| dS )zChecks the given dimension.r   r%   zinvalid ordinate dimension "%d"N)r   )r   Zdimr   r   r   ฺ	_checkdimO   s    zGEOSCoordSeq._checkdimc             C   s,   | j | | j| tj| j||tt S )z4Returns the value for the given dimension and index.)r0   r1   ฺcapiZcs_getordinater   r   r   )r   ฺ	dimensionr#   r   r   r   ฺgetOrdinateU   s    

zGEOSCoordSeq.getOrdinatec             C   s*   | j | | j| tj| j||| dS )z1Sets the value for the given dimension and index.N)r0   r1   r2   Zcs_setordinater   )r   r3   r#   r,   r   r   r   ฺsetOrdinate[   s    

zGEOSCoordSeq.setOrdinatec             C   s   | j d|S )zGet the X value at the index.r   )r4   )r   r#   r   r   r   r   a   s    zGEOSCoordSeq.getXc             C   s   | j d|| dS )z(Set X with the value at the given index.r   N)r5   )r   r#   r,   r   r   r   r)   e   s    zGEOSCoordSeq.setXc             C   s   | j d|S )z#Get the Y value at the given index.r&   )r4   )r   r#   r   r   r   r   i   s    zGEOSCoordSeq.getYc             C   s   | j d|| dS )z(Set Y with the value at the given index.r&   N)r5   )r   r#   r,   r   r   r   r*   m   s    zGEOSCoordSeq.setYc             C   s   | j d|S )z(Get Z with the value at the given index.r%   )r4   )r   r#   r   r   r   r"   q   s    zGEOSCoordSeq.getZc             C   s   | j d|| dS )z(Set Z with the value at the given index.r%   N)r5   )r   r#   r,   r   r   r   r+   u   s    zGEOSCoordSeq.setZc             C   s   t j| jtt S )z-Returns the size of this coordinate sequence.)r2   Z
cs_getsizer   r   r   )r   r   r   r   r   z   s    zGEOSCoordSeq.sizec             C   s   t j| jtt S )z3Returns the dimensions of this coordinate sequence.)r2   Z
cs_getdimsr   r   r   )r   r   r   r   r       s    zGEOSCoordSeq.dimsc             C   s   | j S )z
        Returns 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| jS )z Clones this coordinate sequence.)r   r2   Zcs_cloner   r6   )r   r   r   r   ฺclone   s    zGEOSCoordSeq.clonec                s:    j rdndddj fddtt D j  S )z3Returns 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>)r6   ฺjoinr
   r(   ฺstrip)r   r   )r   r:   r   ฺkml   s
    zGEOSCoordSeq.kmlc                s4    j }|dkr d S t fddt|D S dS )z4Returns a tuple version of this coordinate sequence.r&   r   c             3   s   | ]} | V  qd S )Nr   )r9   r   )r   r   r   r;   ค   s    z%GEOSCoordSeq.tuple.<locals>.<genexpr>N)r   r   r
   )r   ฺnr   )r   r   r      s    zGEOSCoordSeq.tupleN)F)ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__r   Zptr_typer   r   r   r   r$   r-   r0   r1   r4   r5   r   r)   r   r*   r"   r+   ฺpropertyr   r    r6   r7   r>   r   r   r   r   r   r      s0   
	r   N)rC   ฺctypesr   r   r   Zdjango.contrib.gis.geosr   r2   Zdjango.contrib.gis.geos.baser   Zdjango.contrib.gis.geos.errorr   Zdjango.contrib.gis.geos.libgeosr   Zdjango.contrib.gis.shortcutsr	   Zdjango.utils.six.movesr
   r   r   r   r   r   ฺ<module>   s   