
 Xj                 @   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 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)numpy)rangec               @   sE  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 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)0GEOSCoordSeqzGThe internal representation of a list of coordinates inside a Geometry.Fc             C   s4   t  | t  s t d   n  | |  _ | |  _ 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   N/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/geos/coordseq.py__init__   s    	zGEOSCoordSeq.__init__c             c   s'   x  t  |  j  D] } |  | Vq Wd 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   sY   |  j  |  |  j |  g } |  j d k rO |  j rO | j |  j |   n  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 r3 t  | t j  r3 n t d   |  j d k rf |  j rf d } d } n d } d } t |  | k r t d   n  |  j	 | | d  |  j
 | | d  | r |  j | | d  n  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   sJ   |  j  } | d k  s- | d k  s- | | k rF t d t |    n  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 |   n  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   s7   |  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                sQ     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                sD     j  } | d k r   d St   f d d   t |  D  Sd 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)__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   