
vลฯ^  ใ               @   s   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 Gd 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)ฺnumpyc               @   sฯ  e  Z d  Z d Z e Z d 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 d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z d- d.   Z d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z  d7 d8   Z! e d9 d:    Z" e d; d<    Z# e d= d>    Z$ d? d@   Z% e dA dB    Z& e dC dD    Z' dE S)FฺGEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc             C   s1   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   ๚B/tmp/pip-build-8lau8j11/django/django/contrib/gis/geos/coordseq.pyฺ__init__   s    	zGEOSCoordSeq.__init__c             c   s'   x  t  |  j  D] } |  | Vq Wd S)z3Iterate over each point in the coordinate sequence.N)ฺrangeฺsize)r   ฺir   r   r   ฺ__iter__   s    zGEOSCoordSeq.__iter__c             C   s   t  |  j  S)z7Return 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<Return the string representation of the coordinate sequence.)ฺstrฺtuple)r   r   r   r   ฺ__str__$   s    zGEOSCoordSeq.__str__c             C   s   |  j  |  |  j |  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 r3 t  | t j  r3 n t d   |  j d k ri |  j ri d } |  j } n d } |  j	 } t
 |  | k r t d   |  j |  | | |  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   s3   d | k o |  j  k  n s/ 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 |  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 |  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 |  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 |  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 |  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 |  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   |  j  |  |  j |  f S)N)r-   r.   )r   r   r   r   r   r4   c   s    zGEOSCoordSeq._get_point_2dc             C   s(   |  j  |  |  j |  |  j |  f S)N)r-   r.   r/   )r   r   r   r   r   r3   f   s    zGEOSCoordSeq._get_point_3dc             C   s0   | \ } } |  j  | |  |  j | |  d  S)N)r0   r1   )r   r   r(   ฺxฺyr   r   r   r&   i   s    zGEOSCoordSeq._set_point_2dc             C   sC   | \ } } } |  j  | |  |  j | |  |  j | |  d  S)N)r0   r1   r2   )r   r   r(   r5   r6   r   r   r   r   r%   n   s    zGEOSCoordSeq._set_point_3dc             C   s<   |  j  |  |  j |  t j |  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   s7   |  j  |  |  j |  t j |  j | | |  d S)z0Set the value for the given dimension and index.N)r   r+   r,   Zcs_setordinater   )r   r7   r   r(   r   r   r   ฺsetOrdinate{   s    zGEOSCoordSeq.setOrdinatec             C   s   |  j  d |  S)zGet the X value at the index.r   )r8   )r   r   r   r   r   ฺgetX   s    zGEOSCoordSeq.getXc             C   s   |  j  d | |  d S)z(Set X with the value at the given index.r   N)r9   )r   r   r(   r   r   r   ฺsetX   s    zGEOSCoordSeq.setXc             C   s   |  j  d |  S)z#Get the Y value at the given index.้   )r8   )r   r   r   r   r   ฺgetY   s    zGEOSCoordSeq.getYc             C   s   |  j  d | |  d S)z(Set Y with the value at the given index.r<   N)r9   )r   r   r(   r   r   r   ฺsetY   s    zGEOSCoordSeq.setYc             C   s   |  j  d |  S)z(Get Z with the value at the given index.r"   )r8   )r   r   r   r   r   ฺgetZ   s    zGEOSCoordSeq.getZc             C   s   |  j  d | |  d S)z(Set Z with the value at the given index.r"   N)r9   )r   r   r(   r   r   r   ฺsetZ   s    zGEOSCoordSeq.setZc             C   s   t  j |  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 |  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  |  j  S)zClone this coordinate sequence.)r
   r,   Zcs_cloner   rA   )r   r   r   r   ฺcloneญ   s    zGEOSCoordSeq.clonec                sQ     j  r d  n d  d d j    f d d   t t     D  j   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>)rA   ฺjoinr   r'   ฺstrip)r   r   )r   rE   r   ฺkmlฑ   s
    		zGEOSCoordSeq.kmlc                sK   |  j  } |  j   | d k r(   d  St   f d d   t |  D  S)z3Return a tuple version of this coordinate sequence.r<   r   c             3   s   |  ] }   |  Vq d  S)Nr   )rD   r   )ฺ	get_pointr   r   rF   ฤ   s    z%GEOSCoordSeq.tuple.<locals>.<genexpr>)r   r   r   r   )r   ฺnr   )rJ   r   r   ฝ   s
    		
zGEOSCoordSeq.tupleN)(ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__r   Zptr_typer   r   r   r   r    r)   r   r+   r-   r.   r/   r0   r1   r2   ฺpropertyr   r4   r3   r&   r%   r8   r9   r:   r;   r=   r>   r?   r@   r   r$   rA   rB   rI   r   r   r   r   r   r
      sF   	r
   N)rO   ฺctypesr   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   Zdjango.contrib.gis.shortcutsr	   r
   r   r   r   r   ฺ<module>   s   