3
®?d]·  ã               @   s¾   d Z ddlZejd dk reZddlmZmZmZ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
gZG dd	„ d	eƒZG dd„ deeƒZdd
„ Zdd„ Zdd„ Zedkrºeƒ  dS )z1Collections of linestrings and related utilities
é    Né   )Úc_doubleÚc_void_pÚcastÚPOINTER)Úlgeos)ÚBaseMultipartGeometryÚgeos_geom_from_py)Ú
linestring)ÚCachingGeometryProxyÚMultiLineStringÚasMultiLineStringc                   s@   e Zd ZdZd‡ fdd„	Zdd„ Zedd„ ƒZdd
d„Z‡  Z	S )r   zÆ
    A collection of one or more line strings
    
    A MultiLineString has non-zero length and zero area.

    Attributes
    ----------
    geoms : sequence
        A sequence of LineStrings
    Nc                s(   t t| ƒjƒ  |snt|ƒ\| _| _dS )a�  
        Parameters
        ----------
        lines : sequence
            A sequence of line-like coordinate sequences or objects that
            provide the numpy array interface, including instances of
            LineString.

        Example
        -------
        Construct a collection containing one line string.

          >>> lines = MultiLineString( [[[0.0, 0.0], [1.0, 2.0]]] )
        N)Úsuperr   Ú__init__Úgeos_multilinestring_from_pyZ_geomÚ_ndim)ÚselfÚlines)Ú	__class__© úC/tmp/pip-build-op5p2y5_/shapely/shapely/geometry/multilinestring.pyr      s    zMultiLineString.__init__c             G   s
   t j|Ž S )N)r
   Z
LineString)r   Úargsr   r   r   Úshape_factory6   s    zMultiLineString.shape_factoryc             C   s   dt dd„ | jD ƒƒdœS )Nr   c             s   s"   | ]}t d d„ |jD ƒƒV  qdS )c             s   s   | ]
}|V  qd S )Nr   )Ú.0Úcr   r   r   ú	<genexpr>=   s    z>MultiLineString.__geo_interface__.<locals>.<genexpr>.<genexpr>N)ÚtupleZcoords)r   Úgr   r   r   r   =   s    z4MultiLineString.__geo_interface__.<locals>.<genexpr>)ÚtypeZcoordinates)r   Úgeoms)r   r   r   r   Ú__geo_interface__9   s    z!MultiLineString.__geo_interface__ç      ð?c                sB   | j r
dS ˆdkr | jrdnd‰ddj‡ ‡fdd„| D ƒƒ d	 S )
aƒ  Returns a group of SVG polyline elements for the LineString geometry.

        Parameters
        ==========
        scale_factor : float
            Multiplication factor for the SVG stroke-width.  Default is 1.
        stroke_color : str, optional
            Hex string for stroke color. Default is to use "#66cc99" if
            geometry is valid, and "#ff3333" if invalid.
        z<g />Nz#66cc99z#ff3333z<g>Ú c             3   s   | ]}|j ˆ ˆƒV  qd S )N)Úsvg)r   Úp)Úscale_factorÚstroke_colorr   r   r   P   s    z&MultiLineString.svg.<locals>.<genexpr>z</g>)Zis_emptyZis_validÚjoin)r   r%   r&   r   )r%   r&   r   r#   @   s    zMultiLineString.svg)N)r!   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr    r#   Ú__classcell__r   r   )r   r   r      s
   
c               @   s(   e Zd ZdZdZdd„ Zedd„ ƒZdS )ÚMultiLineStringAdapterNFc             C   s   || _ t| _d S )N)Úcontextr   Úfactory)r   r/   r   r   r   r   Y   s    zMultiLineStringAdapter.__init__c             C   sX   y0| j d j}|d d }|dks.|dks.t‚|S  tk
rR   t| j d d ƒS X d S )Nr   Úshapeé   é   r   )r/   Z__array_interface__ÚAssertionErrorÚAttributeErrorÚlen)r   ÚarrayÚnr   r   r   r   ]   s    zMultiLineStringAdapter._ndim)r(   r)   r*   r/   Z_other_ownedr   r,   r   r   r   r   r   r.   T   s   r.   c             C   s   t | ƒS )z=Adapts a sequence of objects to the MultiLineString interface)r.   )r/   r   r   r   r   j   s    c       	      C   sÄ   t | tƒrt| ƒS t| d| ƒ}t|ƒ}|dks2t‚|d }yt|d ƒ}W n tk
rd   |j}Y nX |dkrvtdƒ‚t	| ƒ }x0t
|ƒD ]$}tj|| ƒ\}}t|t	ƒ||< qŠW tjd||ƒ|fS )	Nr   r2   r   r3   r   z!Invalid coordinate dimensionalityé   )r3   r   )Ú
isinstancer   r	   Úgetattrr6   r4   Ú	TypeErrorr   Ú
ValueErrorr   Úranger
   Zgeos_linestring_from_pyr   r   ZGEOSGeom_createCollection)	ÚobZobsÚLZexemplarÚNÚsubsÚlZgeomZndimsr   r   r   r   o   s"    

r   c              C   s   dd l } | jƒ  d S )Nr   )ÚdoctestÚtestmod)rD   r   r   r   Ú_test�   s    rF   Ú__main__)r+   ÚsysÚversion_infoÚxranger>   Úctypesr   r   r   r   Zshapely.geosr   Zshapely.geometry.baser   r	   Zshapely.geometryr
   Zshapely.geometry.proxyr   Ú__all__r   r.   r   r   rF   r(   r   r   r   r   Ú<module>   s    A