a
    ŠJ5d‚  ã                   @   sV   d Z ddlZddlZddlmZmZ ddlmZ dgZ	G dd„ deƒZ
e
ejjd< dS )z#Line strings and related utilities
é    N)ÚBaseGeometryÚ
JOIN_STYLE)ÚPointÚ
LineStringc                   @   sf   e Zd ZdZg Zddd„Zedd„ ƒZddd	„Zed
d„ ƒZ	de
jdfdd„Zdde
jdfdd„ZdS )r   a  
    A geometry type composed of one or more line segments.

    A LineString is a one-dimensional feature and has a non-zero length but
    zero area. It may approximate a curve and need not be straight. Unlike a
    LinearRing, a LineString is not closed.

    Parameters
    ----------
    coordinates : sequence
        A sequence of (x, y, [,z]) numeric coordinate pairs or triples, or
        an array-like with shape (N, 2) or (N, 3).
        Also can be a sequence of Point objects.

    Examples
    --------
    Create a LineString with two segments

    >>> a = LineString([[0, 0], [1, 0], [1, 1]])
    >>> a.length
    2.0
    Nc                    s¶   |d u rt  d¡S t|tƒr4t|ƒtkr,|S |j}nLt|dƒrHt |¡}t|tj	ƒrft 
|jtj¡rfndd„ ‰ ‡ fdd„|D ƒ}t|ƒdkr–t  d¡S t  |¡}t|tƒs²tdƒ‚|S )	NzLINESTRING EMPTYZ	__array__c                 S   s&   t | tƒr| jd S dd„ | D ƒS d S )Nr   c                 S   s   g | ]}t |ƒ‘qS © )Úfloat©Ú.0Úcr   r   úW/var/www/html/django/DPS/env/lib/python3.9/site-packages/shapely/geometry/linestring.pyÚ
<listcomp>@   ó    z7LineString.__new__.<locals>._coords.<locals>.<listcomp>)Ú
isinstancer   Úcoords)Úor   r   r   Ú_coords<   s    

z#LineString.__new__.<locals>._coordsc                    s   g | ]}ˆ |ƒ‘qS r   r   )r	   r   ©r   r   r   r   B   r   z&LineString.__new__.<locals>.<listcomp>r   z/Invalid values passed to LineString constructor)ÚshapelyZfrom_wktr   r   Útyper   ÚhasattrÚnpZasarrayZndarrayZ
issubdtypeZdtypeÚnumberÚlenZlinestringsÚ
ValueError)ÚselfÚcoordinatesZgeomr   r   r   Ú__new__&   s(    



ÿ


zLineString.__new__c                 C   s   dt | jƒdœS )Nr   )r   r   )Útupler   ©r   r   r   r   Ú__geo_interface__N   s    zLineString.__geo_interface__ç      ð?c                 C   sV   | j r
dS |du r | jrdnd}|du r,d}d dd„ | jD ƒ¡}d	 |d
| ||¡S )aà  Returns SVG polyline element 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.
        opacity : float
            Float number between 0 and 1 for color opacity. Default value is 0.8
        z<g />Nz#66cc99z#ff3333gš™™™™™é?ú c                 S   s   g | ]}d j |Ž ‘qS )z{},{})Úformatr   r   r   r   r   e   r   z"LineString.svg.<locals>.<listcomp>zS<polyline fill="none" stroke="{2}" stroke-width="{1}" points="{0}" opacity="{3}" />g       @)Zis_emptyZis_validÚjoinr   r"   )r   Zscale_factorZstroke_colorZopacityZ
pnt_formatr   r   r   ÚsvgR   s    ÿýzLineString.svgc                 C   s   | j jS )zÓSeparate arrays of X and Y coordinate values

        Example:

          >>> x, y = LineString([(0, 0), (1, 1)]).xy
          >>> list(x)
          [0.0, 1.0]
          >>> list(y)
          [0.0, 1.0]
        )r   Úxyr   r   r   r   r%   k   s    zLineString.xyé   g      @c                 C   s6   |dkrt dƒ‚nt |¡s$t dƒ‚t | ||||¡S )aò  Returns a LineString or MultiLineString geometry at a distance from
        the object on its right or its left side.

        The side is determined by the sign of the `distance` parameter
        (negative for right side offset, positive for left side offset). The
        resolution of the buffer around each vertex of the object increases
        by increasing the `quad_segs` keyword parameter.

        The join style is for outside corners between line segments. Accepted
        values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
        JOIN_STYLE.bevel (3).

        The mitre ratio limit is used for very sharp corners. It is the ratio
        of the distance from the corner to the end of the mitred offset corner.
        When two line segments meet at a sharp angle, a miter join will extend
        far beyond the original geometry. To prevent unreasonable geometry, the
        mitre limit allows controlling the maximum length of the join corner.
        Corners with a ratio which exceed the limit will be beveled.

        Note: the behaviour regarding orientation of the resulting line
        depends on the GEOS version. With GEOS < 3.11, the line retains the
        same direction for a left offset (positive distance) or has reverse
        direction for a right offset (negative distance), and this behaviour
        was documented as such in previous Shapely versions. Starting with
        GEOS 3.11, the function tries to preserve the orientation of the
        original line.
        g        z3Cannot compute offset from zero-length line segmentz$offset_curve distance must be finite)r   r   Úisfiniter   Úoffset_curve)r   ÚdistanceÚ	quad_segsÚ
join_styleÚmitre_limitr   r   r   r(   y   s
    "

zLineString.offset_curveÚrightc                 C   s"   |dkr|d9 }| j ||||dS )a›  
        Alternative method to :meth:`offset_curve` method.

        Older alternative method to the :meth:`offset_curve` method, but uses
        ``resolution`` instead of ``quad_segs`` and a ``side`` keyword
        ('left' or 'right') instead of sign of the distance. This method is
        kept for backwards compatibility for now, but is is recommended to
        use :meth:`offset_curve` instead.
        r-   éÿÿÿÿ)r*   r+   r,   )r(   )r   r)   ZsideÚ
resolutionr+   r,   r   r   r   Úparallel_offset¡   s    üzLineString.parallel_offset)N)r    NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Úpropertyr   r$   r%   r   Úroundr(   r0   r   r   r   r   r      s"   
(


û
+úé   )r4   Únumpyr   r   Zshapely.geometry.baser   r   Zshapely.geometry.pointr   Ú__all__r   ÚlibÚregistryr   r   r   r   Ú<module>   s    1