3
®?d]‘  ã               @   sz   d Z ddlZddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ejd dk rVeZG dd	„ d	eƒZG d
d„ de
ƒZdS )zCoordinate sequence utilities
é    N)Úarray)ÚbyrefÚc_doubleÚc_uint)Úlgeos)Ú
Validatingé   c               @   sl   e Zd ZdZdZdZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zedd„ ƒZdd„ ZeeƒZedd„ ƒZdS )ÚCoordinateSequencezî
    Iterative access to coordinate tuples from the parent geometry's coordinate
    sequence.

    Example:

      >>> from shapely.wkt import loads
      >>> g = loads('POINT (0.0 0.0)')
      >>> list(g.coords)
      [(0.0, 0.0)]

    Nc             C   s
   || _ d S )N)Ú__p__)ÚselfÚparent© r   ú1/tmp/pip-build-op5p2y5_/shapely/shapely/coords.pyÚ__init__)   s    zCoordinateSequence.__init__c             C   s   | j j| _tj| j jƒ| _d S )N)r
   Ú_ndimr   ÚGEOSGeom_getCoordSeqÚ_geomÚ_cseq)r   r   r   r   Ú_update,   s    
zCoordinateSequence._updatec             C   s(   | j ƒ  tdƒ}tj| jt|ƒƒ |jS )Nr   )r   r   r   ÚGEOSCoordSeq_getSizer   r   Úvalue)r   Úcs_lenr   r   r   Ú__len__0   s    zCoordinateSequence.__len__c             c   s    | j ƒ  tƒ }tƒ }tƒ }| jdk}xvt| jƒ ƒD ]f}tj| j|t|ƒƒ tj	| j|t|ƒƒ |rŠtj
| j|t|ƒƒ |j|j|jfV  q2|j|jfV  q2W d S )Nr   )r   r   r   Úranger   r   ÚGEOSCoordSeq_getXr   r   ÚGEOSCoordSeq_getYÚGEOSCoordSeq_getZr   )r   ÚdxÚdyÚdzÚhas_zÚir   r   r   Ú__iter__6   s    
zCoordinateSequence.__iter__c             C   sx  | j ƒ  tƒ }tƒ }tƒ }| jƒ }| jdk}t|tƒrÆ|| dk sJ||krRtdƒ‚|dk rd|| }n|}tj| j	|t
|ƒƒ tj| j	|t
|ƒƒ |r¸tj| j	|t
|ƒƒ |j|j|jfS |j|jfS n®t|tƒ�rlg }|j|ƒ\}	}
}x€t|	|
|ƒD ]p}tj| j	|t
|ƒƒ tj| j	|t
|ƒƒ |�rRtj| j	|t
|ƒƒ |j|j|j|jfƒ qô|j|j|jfƒ qôW |S tdƒ‚d S )Nr   r   zindex out of rangezkey must be an index or slice)r   r   r   r   Ú
isinstanceÚintÚ
IndexErrorr   r   r   r   r   r   r   ÚsliceÚindicesr   ÚappendÚ	TypeError)r   Úkeyr   r   r   Úmr    r!   ÚresÚstartÚstopZstrider   r   r   Ú__getitem__E   s<    


zCoordinateSequence.__getitem__c             C   sÀ   | j ƒ  | jdk}| j}| jƒ }t||  }|ƒ }tƒ }x‚t|ƒD ]v}tj| j|t|ƒƒ |j	||| < tj
| j|t|ƒƒ |j	||| d < |rBtj| j|t|ƒƒ |j	||| d < qBW |S )Nr   é   é   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r    Únr+   Z
array_typeÚdataÚtempr!   r   r   r   Úctypesi   s     
zCoordinateSequence.ctypesc             C   sR   t jdkrd}nt jdkr d}ntdƒ‚d|| jdœ}|jdt| ƒ| jfiƒ |S )	z!Provide the Numpy array protocol.Úlittlez<f8Úbigz>f8z4Unsupported byteorder: neither little nor big-endianr   )ÚversionÚtypestrr3   Úshape)ÚsysÚ	byteorderÚ
ValueErrorr5   ÚupdateÚlenr   )r   r9   Zair   r   r   Úarray_interface|   s    


z"CoordinateSequence.array_interfacec             C   s€   | j ƒ  | jƒ }tdƒ}tdƒ}tƒ }xPt|ƒD ]D}tj| j|t|ƒƒ |j	|j
ƒ tj| j|t|ƒƒ |j	|j
ƒ q0W ||fS )zX and Y arraysÚd)r   r   r   r   r   r   r   r   r   r(   r   r   )r   r+   ÚxÚyr4   r!   r   r   r   Úxy�   s    zCoordinateSequence.xy)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r   r   r   r"   r/   Úpropertyr5   r@   Z__array_interface__rD   r   r   r   r   r	      s   
$r	   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBoundsOpc             G   s   d S )Nr   )r   Úargsr   r   r   r   ¡   s    zBoundsOp.__init__c             C   sÜ   | j |ƒ |j}|jdkr |jS tj|jjƒ}tdƒ}tj	|t
|ƒƒ d}d}d}d}tƒ }	xrt|jƒD ]d}
tj||
t
|	ƒƒ |	j}||k r�|}||krœ|}tj||
t
|	ƒƒ |	j}||k rÀ|}||krh|}qhW ||||fS )NZPointr   g@Œµx¯Dg@Œµx¯Äg@Œµx¯Ä)Ú	_validateZenvelopeZ	geom_typeZboundsr   r   Zexteriorr   r   r   r   r   r   r   r   r   )r   ÚthisÚenvÚcsr   ZminxZmaxxZminyZmaxyr4   r!   rB   rC   r   r   r   Ú__call__¤   s4    

    zBoundsOp.__call__N)rE   rF   rG   r   rP   r   r   r   r   rJ   Ÿ   s   rJ   )rH   r;   r   r5   r   r   r   Zshapely.geosr   Zshapely.topologyr   Úversion_infoÚxranger   Úobjectr	   rJ   r   r   r   r   Ú<module>   s    