3
(h                 @   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 G dd	 d	e	eZG d
d deZdS )    )
prototypes)GEOSCoordSeq)GEOSException)GEOSGeometryLinearGeometryMixin)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  ZS )
LineString   Tc                s  t |dkr|d }n|}t|ttfp6to6t|tjs@td|jd}t |}|sttt	| j
| jd|d dS || jk rtd| jj| j|f t|ttfrd}xT|D ]L}t|tttfstd|dkrt |}| j| qt ||krtd	qW d
}n6|j}	t |	dkr"td| j|	d  |	d }d}ttj||t|dkd}
xZt|D ]N}|r||ddf |
|< n,t|| tr|| j|
|< n|| |
|< qbW 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-Invalid initialization input for LineStrings.sridN)r   z'%s requires at least %d points, got %s.z4Each coordinate should be a sequence (list or tuple)zDimension mismatch.Fr   zToo many dimensions.T   )z)len
isinstancetuplelistr   Zndarray	TypeErrorgetsuperr
   __init__
_init_func
_minlength
ValueError	__class____name__r   	_checkdimshaper   capi	create_csboolr	   ptr)selfargskwargscoordsr   ZncoordsndimZcoordZnumpy_coordsr   csi)r    F/tmp/pip-install-q3hcpn_q/Django/django/contrib/gis/geos/linestring.pyr      sR    




zLineString.__init__c             c   s$   xt t| D ]}| | V  qW dS )z&Allows iteration over this LineString.N)r	   r   )r#   r)   r*   r*   r+   __iter__\   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__a   s    zLineString.__len__c             C   s
   | j | S )N)r-   )r#   indexr*   r*   r+   _get_single_externale   s    zLineString._get_single_externalc       	      C   s~   | j j}| j j}ttj|||d}xt|D ]\}}|||< q.W | j|j}|rrtj	| j || _| j
| j ntdd S )N)r   z3Geometry resulting from slice deletion was invalid.)r-   Zdimshaszr   r   r    	enumerater   r"   Zdestroy_geomZ
_post_initr   r   )	r#   lengthitemsr'   r1   r(   r)   cr"   r*   r*   r+   	_set_listj   s    zLineString._set_listc             C   s   | j | || j|< d S )N)Z_checkindexr-   )r#   r/   valuer*   r*   r+   _set_single|   s    
zLineString._set_singlec             C   s   |dkrt dd S )Nr   r   zDimension mismatch.)r   r   )r   )r#   Zdimr*   r*   r+   r      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      s    zLineString.tuplec                s0    fddt t| D }tr(tj|S |S d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S r*   r*   ).0r)   )funcr*   r+   
<listcomp>   s    z'LineString._listarr.<locals>.<listcomp>N)r	   r   r   array)r#   r:   lstr*   )r:   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+   r<      s    zLineString.arrayc             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S dS )z0Returns a list or numpy array of the Z variable.N)r1   r>   r-   ZgetZ)r#   r*   r*   r+   r      s    zLineString.z)r   
__module____qualname__r   Zcreate_linestringr   r   Zhas_csr   r,   r.   r0   Z_get_single_internalr6   r8   r   propertyr   r&   r>   r<   r@   rA   r   __classcell__r*   r*   )r   r+   r
   
   s$   Mr
   c               @   s   e Zd ZdZejZdS )
LinearRing   N)r   rB   rC   r   r   Zcreate_linearringr   r*   r*   r*   r+   rF      s   rF   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
   rF   r*   r*   r*   r+   <module>   s    &