o
    EDi                      @   sZ   d dl Z d dlZejrd dlZnd dlmZ dd Zdd Zdd Zddd	Z	d
d Z
dS )    Nc                 c   sJ    g }t | D ]\}}|| t||kr|V  g }q|r#|V  dS dS )a  
    Creates a generator by slicing ``data`` into chunks of ``block_size``.

    >>> data = range(10)
    >>> list(block_splitter(data, 2))
    [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]

    If ``data`` cannot be evenly divided by ``block_size``, the last block will
    simply be the remainder of the data. Example:

    >>> data = range(10)
    >>> list(block_splitter(data, 3))
    [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]

    If the ``block_size`` is greater than the total length of ``data``, a
    single block will be generated:

    >>> data = range(3)
    >>> list(block_splitter(data, 4))
    [[0, 1, 2]]

    :param data:
        Any iterable. If ``data`` is a generator, it will be exhausted,
        obviously.
    :param int block_site:
        Desired (maximum) block size.
    N)	enumerateappendlen)data
block_sizebufidatum r
   D/var/www/Datamplify/venv/lib/python3.10/site-packages/geomet/util.pyblock_splitter   s   

r   c                 C   s   t t|| S )z
    Return first n items of the iterable as a list

    Copied shamelessly from
    http://docs.python.org/2/library/itertools.html#recipes.
    )list	itertoolsislice)niterabler
   r
   r   take?   s   r   c                 C   s   t jrd| S t| S )N    )sixPY2joinbytes)a_listr
   r
   r   
as_bin_strI   s   
r   c                    s  | d dkr2| d \}}|g|g}} dur) fdd|D } fdd|D }t t||d }| d d	v r^t| d  \}} durV fd
d|D } fdd|D }t t||}ny| d dv rg }| d D ](}t| \}} dur fdd|D } fdd|D }|t t|| qjnC| d dkr| d }g }|D ]4}	g }
|	D ](}t| \}} durƇ fdd|D } fdd|D }|
t t|| q||
 q| d |dS )z;Round coordinates of a geometric object to given precision.typePointcoordinatesNc                       g | ]}t | qS r
   round.0v	precisionr
   r   
<listcomp>V       zround_geom.<locals>.<listcomp>c                    r   r
   r   r    r#   r
   r   r%   W   r&   r   )
LineString
MultiPointc                    r   r
   r   r    r#   r
   r   r%   \   r&   c                    r   r
   r   r    r#   r
   r   r%   ]   r&   )PolygonMultiLineStringc                    r   r
   r   r    r#   r
   r   r%   d   r&   c                    r   r
   r   r    r#   r
   r   r%   e   r&   MultiPolygonc                    r   r
   r   r    r#   r
   r   r%   o   r&   c                    r   r
   r   r    r#   r
   r   r%   p   r&   )r   r   )tuplezipr   )geomr$   xyxpyp
new_coordspiecepartspartinner_coordsringr
   r#   r   
round_geomP   sF   r9   c                 c   sD    | D ]}t |tjrt |tjst|D ]}|V  qq|V  qdS )zbFlatten a multi-dimensional array-like to a single dimensional sequence
    (as a generator).
    N)
isinstancecollectionsIterabler   string_typesflatten_multi_dim)sequencer/   r0   r
   r
   r   r>   v   s   
r>   )N)r   r   r   r;   collections.abcabcr   r   r   r9   r>   r
   r
   r
   r   <module>   s   
)

&