

_V                 @   s   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 d  d l m Z d  d l m Z Gd d	   d	 e	 e  Z Gd
 d   d e  Z d S)    )
prototypes)GEOSCoordSeq)GEOSException)GEOSGeometryProjectInterpolateMixin)Point)numpy)rangec                   s  e  Z d  Z e j Z d Z d Z   f d d   Z d d   Z	 d d   Z
 d	 d
   Z e Z d d   Z d d   Z d d   Z e d d    Z e Z d d   Z e d d    Z e d d    Z e d d    Z e d d    Z e d d    Z   S)
LineString   Tc                s;  t  |  d k r | d } n | } t | t t f  r t  |  } | r_ t  | d  } n t d   |  j |  xg t d |  D]V } t | | t t t f  s t d   n  t  | |  | k r t d   q q Wd } n| t r[t | t j	  r[| j
 } t  |  d k r-t d   n  |  j | d  | d } | d } d	 } n t d
   t t j | |  d t | d k  }	 xl t |  D]^ } | r| | d d  f |	 | <qt | | t  r| | j |	 | <q| | |	 | <qW| j d  }
 t t |   j |  j |	 j  d |
 d S)a  
        Initializes on the given sequence -- may take lists, tuples, NumPy arrays
        of X,Y pairs, or Point objects.  If Point objects are used, ownership is
        _not_ transferred to the LineString object.

        Examples:
         ls = LineString((1, 1), (2, 2))
         ls = LineString([(1, 1), (2, 2)])
         ls = LineString(array([(1, 1), (2, 2)]))
         ls = LineString(Point(1, 1), Point(2, 2))
           r   z$Cannot initialize on empty sequence.z4each coordinate should be a sequence (list or tuple)zDimension mismatch.Fr   zToo many dimensions.Tz-Invalid initialization input for LineStrings.z   Nsrid)len
isinstancetuplelist	TypeError	_checkdimr	   r   r   Zndarrayshaper   capi	create_csboolgetsuperr
   __init__
_init_funcptr)selfargskwargscoordsZncoordsndimiZnumpy_coordsr   csr   )	__class__ D/tmp/pip-build-ghmbqnp_/Django/django/contrib/gis/geos/linestring.pyr      sB    		

	*zLineString.__init__c             c   s*   x# t  t |    D] } |  | Vq Wd S)z&Allows iteration over this LineString.N)r	   r   )r   r$   r'   r'   r(   __iter__Q   s    zLineString.__iter__c             C   s   t  |  j  S)z0Returns the number of points in this LineString.)r   _cs)r   r'   r'   r(   __len__V   s    zLineString.__len__c             C   s   |  j  | S)N)r*   )r   indexr'   r'   r(   _get_single_externalZ   s    zLineString._get_single_externalc       	      C   s   |  j  j } |  j  j } t t j | |  d | } x$ t |  D] \ } } | | | <qC W|  j | j  } | r t j	 |  j  | |  _ |  j
 |  j  n t d   d  S)Nr   z3Geometry resulting from slice deletion was invalid.)r*   Zdimshaszr   r   r   	enumerater   r   Zdestroy_geomZ
_post_initr   r   )	r   lengthitemsr#   r.   r%   r$   cr   r'   r'   r(   	_set_list_   s    	zLineString._set_listc             C   s   |  j  |  | |  j | <d  S)N)Z_checkindexr*   )r   r,   valuer'   r'   r(   _set_singleq   s    zLineString._set_singlec             C   s   | d k r t  d   n  d  S)Nr   r   zDimension mismatch.)r   r   )r   )r   Zdimr'   r'   r(   r   u   s    zLineString._checkdimc             C   s
   |  j  j S)zEReturns a tuple version of the geometry from the coordinate sequence.)r*   r   )r   r'   r'   r(   r   z   s    zLineString.tuplec                s@     f d d   t  t |    D } t r8 t j |  S| Sd S)z
        Internal routine that returns a sequence (list) corresponding with
        the given function.  Will return a numpy array if possible.
        c                s   g  |  ] }   |   q Sr'   r'   ).0r$   )funcr'   r(   
<listcomp>   s   	 z'LineString._listarr.<locals>.<listcomp>N)r	   r   r   array)r   r7   lstr'   )r7   r(   _listarr   s    %zLineString._listarrc             C   s   |  j  |  j j  S)z)Returns a numpy array for the LineString.)r;   r*   __getitem__)r   r'   r'   r(   r9      s    zLineString.arrayc             C   s   |  j  t j |  j   S)z*Returns the line merge of this LineString.)Z	_topologyr   Zgeos_linemerger   )r   r'   r'   r(   merged   s    zLineString.mergedc             C   s   |  j  |  j j  S)z0Returns a list or numpy array of the X variable.)r;   r*   ZgetX)r   r'   r'   r(   x   s    zLineString.xc             C   s   |  j  |  j j  S)z0Returns a list or numpy array of the Y variable.)r;   r*   ZgetY)r   r'   r'   r(   y   s    zLineString.yc             C   s$   |  j  s d S|  j |  j j  Sd S)z0Returns a list or numpy array of the Z variable.N)r.   r;   r*   ZgetZ)r   r'   r'   r(   r      s    	zLineString.z)__name__
__module____qualname__r   Zcreate_linestringr   
_minlengthZhas_csr   r)   r+   r-   Z_get_single_internalr3   r5   r   propertyr   r"   r;   r9   r=   r>   r?   r   r'   r'   )r&   r(   r
      s&   	@r
   c               @   s   e  Z d  Z d Z e j Z d S)
LinearRing   N)r@   rA   rB   rC   r   Zcreate_linearringr   r'   r'   r'   r(   rE      s   rE   N)Zdjango.contrib.gis.geosr   r   Z django.contrib.gis.geos.coordseqr   Zdjango.contrib.gis.geos.errorr   Z django.contrib.gis.geos.geometryr   r   Zdjango.contrib.gis.geos.pointr   Zdjango.contrib.gis.shortcutsr   Zdjango.utils.six.movesr	   r
   rE   r'   r'   r'   r(   <module>   s   