
    (&hJ+                        d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ g d	Zd
 Z G d de          Zeej        j        d<    G d d          Z G d de
          Zeej        j        d<   ddZdS )z*Polygons and their linear ring components.    N)_geometry_helpers)signed_area)TopologicalError)BaseGeometry)
LineString)Point)
LinearRingPolygonorientc                     t          j        |           }t          j        |          }t          j        |          }|rt          j        ||          }|S N)shapelyfrom_wkbget_sridr   linestring_to_linearringset_srid)wkb
linestringsrid
linearrings       S/var/www/html/reinick/venv/lib/python3.11/site-packages/shapely/geometry/polygon.py_unpickle_linearringr      sR    !#&&JJ''D";JGGJ 8%j$77
    c                   f    e Zd ZdZg ZddZed             Zd Zed             Z	ed             Z
dS )	r	   a  Geometry type composed of one or more line segments that forms a closed loop.

    A LinearRing is a closed, one-dimensional feature.
    A LinearRing that crosses itself or touches itself at a single point is
    invalid and operations on it may fail.

    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.

    Notes
    -----
    Rings are automatically closed. There is no need to specify a final
    coordinate pair identical to the first.

    Examples
    --------
    Construct a square ring.

    >>> from shapely import LinearRing
    >>> ring = LinearRing( ((0, 0), (0, 1), (1 ,1 ), (1 , 0)) )
    >>> ring.is_closed
    True
    >>> list(ring.coords)
    [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]
    >>> ring.length
    4.0

    Nc                    |t          j        d          S t          |t                    r6t	          |          t
          u r|S |j        st          d          |j        }nt          |d          rt          j        |          }t          |t          j                  r%t          j        |j        t          j                  rnVd t          j        fd|D                       }t          j        |j        t          j                  st#          d          t%          |          dk    rt          j        d          S t          j        |          }t          |t
                    st#          d	          |S )
z!Create a new LinearRing geometry.NzLINEARRING EMPTYz"An input LineString must be valid.	__array__c                 ^    t          | t                    r| j        d         S d | D             S )Nr   c                 ,    g | ]}t          |          S  )float.0cs     r   
<listcomp>z7LinearRing.__new__.<locals>._coords.<locals>.<listcomp>[   s    444Qa444r   )
isinstancer   coords)os    r   _coordsz#LinearRing.__new__.<locals>._coordsW   s4    !!U++ 5 x{*44!4444r   c                 &    g | ]} |          S r   r   )r"   r'   r(   s     r   r$   z&LinearRing.__new__.<locals>.<listcomp>]   s!    'H'H'Hq

'H'H'Hr   z&Inconsistent coordinate dimensionalityr   z/Invalid values passed to LinearRing constructor)r   from_wktr%   r   typer	   is_validr   r&   hasattrnpasarrayndarray
issubdtypedtypenumberarray
ValueErrorlenlinearrings)selfcoordinatesgeomr(   s      @r   __new__zLinearRing.__new__=   s    #$6777Z00 	OK  J.."" ) 1&'KLLL *0 {K00 6 j55+rz22 Or}!298 8 O 5 5 5 !h'H'H'H'HK'H'H'HII}[%6	BB O %%MNNN{q   #$6777";//$
++ 	PNOOOr   c                 0    dt          | j                  dS )z9Return a GeoJSON-like mapping of the LinearRing geometry.r	   r+   r9   )tupler&   r8   s    r   __geo_interface__zLinearRing.__geo_interface__m   s     %U4;5G5GHHHr   c                 >    t           t          j        | d          ffS )zPickle support.

        WKB doesn't differentiate between LineString and LinearRing so we
        need to move the coordinate sequence into the correct geometry type
        T)include_srid)r   r   to_wkbr?   s    r   
__reduce__zLinearRing.__reduce__r   s!     %w~d'N'N'N&PQQr   c                 D    t          t          j        |                     S )z0True if the ring is oriented counter clock-wise.)boolr   is_ccwr?   s    r   rG   zLinearRing.is_ccwz   s     GN4(()))r   c                 D    t          t          j        |                     S )zwTrue if the geometry is simple.

        Simple means that any self-intersections are only at boundary points.
        )rF   r   	is_simpler?   s    r   rI   zLinearRing.is_simple   s     G%d++,,,r   r   )__name__
__module____qualname____doc__	__slots__r;   propertyr@   rD   rG   rI   r   r   r   r	   r	      s         B I. . . .` I I XIR R R * * X* - - X- - -r   r	      c                   B    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d Zd ZdS )	InteriorRingSequenceNr   c                 ,    || _         |j        | _        d S r   )_parent_ndim)r8   parents     r   __init__zInteriorRingSequence.__init__   s    \


r   c                 F    d| _         |                                 | _        | S )Nr   )_index__len___lengthr?   s    r   __iter__zInteriorRingSequence.__iter__   s    ||~~r   c                     | j         | j        k     r,|                     | j                   }| xj         dz  c_         |S t          )N   )rY   r[   	_get_ringStopIteration)r8   rings     r   __next__zInteriorRingSequence.__next__   s?    ;%%>>$+..DKK1KKKr   c                 4    t          j        | j                  S r   )r   get_num_interior_ringsrT   r?   s    r   rZ   zInteriorRingSequence.__len__   s    -dl;;;r   c                    |                                  }t          |t                    rA||z   dk     s||k    rt          d          |dk     r||z   }n|}|                     |          S t          |t
                    rYg }|                    |          \  }}}t          |||          D ]*}|                    |                     |                     +|S t          d          )Nr   zindex out of rangezkey must be an index or slice)
rZ   r%   int
IndexErrorr_   sliceindicesrangeappend	TypeError)r8   keymiresstartstopstrides           r   __getitem__z InteriorRingSequence.__getitem__   s    LLNNc3 	=Qw{{cQhh !5666QwwG>>!$$$U## 	=C"%++a..E45$// . .

4>>!,,----J;<<<r   c                 6    t          j        | j        |          S r   )r   get_interior_ringrT   )r8   ro   s     r   r_   zInteriorRingSequence._get_ring   s    (q999r   )rJ   rK   rL   rT   rU   rY   r[   rW   r\   rb   rZ   rt   r_   r   r   r   rR   rR      s        GEFG" " "  
     < < <= = =&: : : : :r   rR   c                       e Zd ZdZg ZddZed             Zed             Zed             Z	ed             Z
dd	Zed
             ZdS )r
   ae  A geometry type representing an area that is enclosed by a linear ring.

    A polygon is a two-dimensional feature and has a non-zero area. It may
    have one or more negative-space "holes" which are also bounded by linear
    rings. If any rings cross each other, the feature is invalid and
    operations on it may fail.

    Parameters
    ----------
    shell : 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.
    holes : sequence
        A sequence of objects which satisfy the same requirements as the
        shell parameters above

    Attributes
    ----------
    exterior : LinearRing
        The ring which bounds the positive space of the polygon.
    interiors : sequence
        A sequence of rings which bound all existing holes.

    Examples
    --------
    Create a square polygon with no holes

    >>> from shapely import Polygon
    >>> coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
    >>> polygon = Polygon(coords)
    >>> polygon.area
    1.0

    Nc                 :   |t          j        d          S t          |t                    r|S t	          |          }|"t          |          dk    rd}nd |D             }t          j        ||          }t          |t                    st          d          |S )zCreate a new Polygon geometry.NzPOLYGON EMPTYr   c                 ,    g | ]}t          |          S r   )r	   )r"   ra   s     r   r$   z#Polygon.__new__.<locals>.<listcomp>   s     <<<dD))<<<r   )holesz,Invalid values passed to Polygon constructor)r   r*   r%   r
   r	   r6   polygonsr5   )r8   shellrz   r:   s       r   r;   zPolygon.__new__   s    = #O444w'' 	&Lu%%E5zzQ<<e<<<U333$(( 	MKLLLr   c                 *    t          j        |           S )z(Return the exterior ring of the polygon.)r   get_exterior_ringr?   s    r   exteriorzPolygon.exterior   s     (...r   c                 2    | j         rg S t          |           S )z5Return the sequence of interior rings of the polygon.)is_emptyrR   r?   s    r   	interiorszPolygon.interiors   s!     = 	I#D)))r   c                      t          d          )zNot implemented for polygons.zCComponent rings have coordinate sequences, but the polygon does not)NotImplementedErrorr?   s    r   r&   zPolygon.coords  s     "Q
 
 	
r   c                     | j         t                      k    rg }nKt          | j         j                  g}| j        D ])}|                    t          |j                             *dt          |          dS )z6Return a GeoJSON-like mapping of the Polygon geometry.r
   r=   )r   r	   r>   r&   r   rk   )r8   r&   holes      r   r@   zPolygon.__geo_interface__  su     =JLL((FFDM0112F 2 2eDK001111!%--@@@r         ?c           	          | j         rdS || j        rdnd}|d}d | j        j        D             g}d | j        D             }d                    d	 ||z   D                       }d
| dd|z   d| d| d	S )a  Return SVG path element for the Polygon geometry.

        Parameters
        ----------
        scale_factor : float
            Multiplication factor for the SVG stroke-width.  Default is 1.
        fill_color : str, optional
            Hex string for fill 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.6

        z<g />Nz#66cc99z#ff3333g333333?c                 "    g | ]} d j         | S z{},{}formatr!   s     r   r$   zPolygon.svg.<locals>.<listcomp>-  s!    MMM1NGNA.MMMr   c                 0    g | ]}d  |j         D             S )c                 "    g | ]} d j         | S r   r   r!   s     r   r$   z*Polygon.svg.<locals>.<listcomp>.<listcomp>/  s!    999A^W^Q999r   )r&   )r"   interiors     r   r$   zPolygon.svg.<locals>.<listcomp>.  s6     
 
 
>F99999
 
 
r    c           
      |    g | ]9}d                      |d         d                    |dd                             :S )zM {} L {} zr   z L r^   N)r   join)r"   r&   s     r   r$   zPolygon.svg.<locals>.<listcomp>2  sP        $$VAY

6!"":0F0FGG  r   z <path fill-rule="evenodd" fill="z!" stroke="#555555" stroke-width="g       @z" opacity="z" d="z" />)r   r,   r   r&   r   r   )r8   scale_factor
fill_coloropacityexterior_coordsinterior_coordspaths          r   svgzPolygon.svg  s     = 	7&*mBJ?GMM8LMMMN
 
JN.
 
 
 xx -?  
 
Uz U U </U U<CU UJNU U U	
r   c                 0     | ||f||f||f||fg          S )z,Construct a `Polygon()` from spatial bounds.r   )clsxminyminxmaxymaxs        r   from_boundszPolygon.from_bounds<  s-     sT4L4,ttTlKLLLr   )NN)r   NN)rJ   rK   rL   rM   rN   r;   rO   r   r   r&   r@   r   classmethodr   r   r   r   r
   r
      s        " "H I   0 / / X/ * * X* 
 
 X
 A A XA!
 !
 !
 !
F M M [M M Mr   r
      r   c                 6    t          j        | |dk               S )a  Return an oriented polygon.

    It is recommended to use :func:`shapely.orient_polygons` instead.

    Parameters
    ----------
    polygon : shapely.Polygon
    sign : float, default 1.
        The sign of the result's signed area.
        A non-negative sign means that the coordinates of the geometry's exterior
        rings will be oriented counter-clockwise.

    Returns
    -------
    Geometry or array_like

    Refer to :func:`shapely.orient_polygons` for full documentation.

    g        )exterior_cw)r   orient_polygons)polygonsigns     r   r   r   E  s    ( "7s
CCCCr   )r   )rM   numpyr.   r   r   shapely.algorithms.cgar   shapely.errorsr   shapely.geometry.baser   shapely.geometry.linestringr   shapely.geometry.pointr   __all__r   r	   libregistryrR   r
   r   r   r   r   <module>r      s   0 0      % % % % % % . . . . . . + + + + + + . . . . . . 2 2 2 2 2 2 ( ( ( ( ( (
-
-
-  l- l- l- l- l- l- l- l-^ % Q .: .: .: .: .: .: .: .:bCM CM CM CM CMl CM CM CML " Q D D D D D Dr   