U
    d                     @   sr   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 G dd de	eZG d	d
 d
eZdS )    )
prototypes)GEOSCoordSeq)GEOSException)GEOSGeometryLinearGeometryMixin)Point)numpyc                       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s@tr8t|tjs@td|d}t |}|spt j	| 
d|d dS || jk rtd| jj| j|f t|ttf }|r|j}t |dkrtd	| |d  |d }nXd}|D ]N}	t|	tttfstd
|dkrt |	}| | qt |	|krtdqtt||t|dkd}
|dkr\|
jn|
j}t|D ]L}|r||ddf }n$t|| tr|| j}n|| }||| qjt j	| 
|
j|d dS )a  
        Initialize 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.r
   zToo many dimensions.z4Each coordinate should be a sequence (list or tuple)Dimension mismatch.   z)len
isinstancetuplelistr   Zndarray	TypeErrorgetsuper__init__
_init_func
_minlength
ValueError	__class____name__shape	_checkdimr   r   capi	create_csboolZ_set_point_3dZ_set_point_2drangeptr)selfargskwargscoordsr   ZncoordsZnumpy_coordsr   ndimZcoordcsZpoint_setteriZpoint_coordsr    F/tmp/pip-unpacked-wheel-7vj2equ7/django/contrib/gis/geos/linestring.pyr      sh    



	


zLineString.__init__c                 c   s    t t| D ]}| | V  qdS )z%Allow iteration over this LineString.N)r#   r   )r%   r+   r-   r-   r.   __iter__c   s    zLineString.__iter__c                 C   s
   t | jS )z/Return the number of points in this LineString.)r   _csr%   r-   r-   r.   __len__h   s    zLineString.__len__c                 C   s
   | j | S Nr0   )r%   indexr-   r-   r.   _get_single_externall   s    zLineString._get_single_externalc           
      C   s   | j j}| j j}| j}tt|||d}t|D ]\}}|||< q2| |j	}	|	r~t
| j	 |	| _	|d k	rt|| _|   ntdd S )Nr   z3Geometry resulting from slice deletion was invalid.)r0   Zdimshaszr   r   r    r!   	enumerater   r$   Zdestroy_geomZ
_post_initr   )
r%   lengthitemsr)   r7   r   r*   r+   cr$   r-   r-   r.   	_set_listq   s    

zLineString._set_listc                 C   s   || j |< d S r3   r4   )r%   r5   valuer-   r-   r.   _set_single   s    zLineString._set_singlec                 C   s   |dkrt dd S )N)r
   r   r   )r   )r%   Zdimr-   r-   r.   r      s    zLineString._checkdimc                 C   s   | j jS )zDReturn a tuple version of the geometry from the coordinate sequence.)r0   r   r1   r-   r-   r.   r      s    zLineString.tuplec                    s0    fddt t| D }tr(t|S |S dS )z{
        Return a sequence (list) corresponding with the given function.
        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%   rA   lstr-   r@   r.   _listarr   s    
zLineString._listarrc                 C   s   |  | jjS )z(Return a numpy array for the LineString.)rE   r0   __getitem__r1   r-   r-   r.   rC      s    zLineString.arrayc                 C   s   |  | jjS )z/Return a list or numpy array of the X variable.)rE   r0   ZgetXr1   r-   r-   r.   x   s    zLineString.xc                 C   s   |  | jjS )z/Return a list or numpy array of the Y variable.)rE   r0   ZgetYr1   r-   r-   r.   y   s    zLineString.yc                 C   s   | j s
dS | | jjS dS )z/Return a list or numpy array of the Z variable.N)r7   rE   r0   ZgetZr1   r-   r-   r.   r      s    zLineString.z)r   
__module____qualname__r    Zcreate_linestringr   r   Zhas_csr   r/   r2   r6   Z_get_single_internalr<   r>   r   propertyr   r(   rE   rC   rG   rH   r   __classcell__r-   r-   r,   r.   r	   	   s.   U



r	   c                   @   s"   e Zd ZdZejZedd ZdS )
LinearRing   c                 C   s   | j rtd| jjS )Nz8Orientation of an empty LinearRing cannot be determined.)emptyr   r0   is_counterclockwiser1   r-   r-   r.   rP      s    zLinearRing.is_counterclockwiseN)	r   rI   rJ   r   r    Zcreate_linearringr   rK   rP   r-   r-   r-   r.   rM      s   rM   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   r	   rM   r-   r-   r-   r.   <module>   s    1