
    Ogp,                        d Z ddlZddlZddlmZ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y)z*Polygons and their linear ring components
    N)is_ccw_implsigned_area)TopologicalError)BaseGeometry)
LineString)Point)orientPolygon
LinearRingc                     t        j                  |       }t        j                  |      }t        j                  t        j                  |            }|rt        j
                  ||      }|S N)shapelyfrom_wkbget_sridlinearringsget_coordinatesset_srid)wkb
linestringsrid
linearrings       ]/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/shapely/geometry/polygon.py_unpickle_linearringr      sX    !!#&JJ'D$$W%<%<Z%HIJ%%j$7
    c                   R    e Zd ZdZg ZddZed        Zd Zed        Z	ed        Z
y)	r   a  
    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.

    >>> 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              r8t	        |      t
        k(  r|S |j                  st        d      |j                  }nt        |d      rt        j                  |      }t        |t        j                        r/t        j                  |j                  t        j                        rned }t        j                   |D cg c]
  } ||       c}      }t        j                  |j                  t        j                        st#        d      t%        |      dk(  rt        j                  d      S t        j&                  |      }t        |t
              st#        d      |S c c}w )NzLINEARRING EMPTYz"An input LineString must be valid.	__array__c                 |    t        | t              r| j                  d   S | D cg c]  }t        |       c}S c c}w Nr   )
isinstancer   coordsfloat)ocs     r   _coordsz#LinearRing.__new__.<locals>._coordsW   s2    !!U+ xx{*234Qa444s   9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lenr   )selfcoordinatesr%   r#   geoms        r   __new__zLinearRing.__new__>   s>    ##$677Z0K J."" ))&'KLL *00 {K0 jj5+rzz2r}}!!2998 5 !hhK'Hq
'HI}}[%6%6		B %%MNN{q  ##$677"";/$
+NOO (Is    Fc                 2    dt        | j                        dS )Nr   r'   r4   )tupler!   r3   s    r   __geo_interface__zLinearRing.__geo_interface__m   s    $U4;;5GHHr   c                 >    t         t        j                  | d      ffS )zWKB doesn't differentiate between LineString and LinearRing so we
        need to move the coordinate sequence into the correct geometry typeT)include_srid)r   r   to_wkbr:   s    r   
__reduce__zLinearRing.__reduce__q   s     %w~~d'N&PQQr   c                 4    t         t               |             S )z/True is the ring is oriented counter clock-wise)boolr   r:   s    r   is_ccwzLinearRing.is_ccwv   s     MKM$'((r   c                 >    t        t        j                  |             S )zsTrue if the geometry is simple, meaning that any self-intersections
        are only at boundary points, else False)rA   r   	is_simpler:   s    r   rD   zLinearRing.is_simple{   s     G%%d+,,r   r   )__name__
__module____qualname____doc__	__slots__r6   propertyr;   r?   rB   rD    r   r   r   r      sY     D I-^ I IR
 ) ) - -r   r      c                   @    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d Zd Zy)	InteriorRingSequenceNr   c                 4    || _         |j                  | _        y r   )_parent_ndim)r3   parents     r   __init__zInteriorRingSequence.__init__   s    \\
r   c                 >    d| _         | j                         | _        | S r   )_index__len___lengthr:   s    r   __iter__zInteriorRingSequence.__iter__   s    ||~r   c                     | j                   | j                  k  r2| j                  | j                         }| xj                   dz  c_         |S t        )N   )rU   rW   	_get_ringStopIteration)r3   rings     r   __next__zInteriorRingSequence.__next__   s=    ;;%>>$++.DKK1KKr   c                 @    t        j                  | j                        S r   )r   get_num_interior_ringsrP   r:   s    r   rV   zInteriorRingSequence.__len__   s    --dll;;r   c                 z   | j                         }t        |t              r6||z   dk  s||k\  rt        d      |dk  r||z   }n|}| j	                  |      S t        |t
              rKg }|j                  |      \  }}}t        |||      D ]"  }|j                  | j	                  |             $ |S t        d      )Nr   zindex out of rangezkey must be an index or slice)
rV   r    int
IndexErrorr[   sliceindicesrangeappend	TypeError)r3   keymiresstartstopstrides           r   __getitem__z InteriorRingSequence.__getitem__   s    LLNc3Qw{cQh !566QwG>>!$$U#C"%++a.E45$/ .

4>>!,-.J;<<r   c                 B    t        j                  | j                  |      S r   )r   get_interior_ringrP   )r3   rk   s     r   r[   zInteriorRingSequence._get_ring   s    ((q99r   )rE   rF   rG   rP   rQ   rU   rW   rS   rX   r^   rV   rp   r[   rK   r   r   rN   rN      s4    GEFG"
 <=&:r   rN   c                        e Zd ZdZg ZddZed        Zed        Zed        Z	d Z
 fdZed        Zdd	Zed
        Z xZ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

    >>> coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
    >>> polygon = Polygon(coords)
    >>> polygon.area
    1.0
    c                 2   |t        j                  d      S t        |t              r|S t	        |      }|)t        |      dk(  rd }n|D cg c]  }t	        |       }}t        j                  ||      }t        |t              st        d      |S c c}w )NzPOLYGON EMPTYr   )holesz,Invalid values passed to Polygon constructor)r   r&   r    r
   r   r2   polygonsr1   )r3   shellru   r]   r5   s        r   r6   zPolygon.__new__   s    = ##O44w'Lu%E5zQ6;<dD)<<U3$(KLL =s   Bc                 ,    t        j                  |       S r   )r   get_exterior_ringr:   s    r   exteriorzPolygon.exterior   s    ((..r   c                 4    | j                   rg S t        |       S r   )is_emptyrN   r:   s    r   	interiorszPolygon.interiors   s    ==I#D))r   c                     t        d      )NzCComponent rings have coordinate sequences, but the polygon does not)NotImplementedErrorr:   s    r   r!   zPolygon.coords   s    !Q
 	
r   c           
      |   t        |t              st        S t        |t              sy| j                  |j                  f}t        |      ryt        |      ry| j                  j                  g| j                  D cg c]  }|j                   c}z   }|j                  j                  g|j                  D cg c]  }|j                   c}z   }t        |      t        |      k(  syt        j
                  t        ||      D cg c]  \  }}t        j                  ||       c}}      S c c}w c c}w c c}}w )NFT)r    r   NotImplementedr
   r|   allanyrz   r!   r}   r2   r*   ziparray_equal)r3   othercheck_emptyinterior	my_coordsother_coordsleftrights           r   __eq__zPolygon.__eq__  s   %.!!%)}}enn5{]]))*,0NN.
 (HOO.
 
	 --.,1OO2
 (HOO2
 
 9~\!22vv $'y,#?D% tU+
 	
.
2
s   <D.8D3 D8
c                      t         |          S r   )super__hash__)r3   	__class__s    r   r   zPolygon.__hash__  s    w!!r   c                     | j                   t               k(  rg }nUt        | j                   j                        g}| j                  D ]&  }|j                  t        |j                               ( dt        |      dS )Nr
   r8   )rz   r   r9   r!   r}   rg   )r3   r!   holes      r   r;   zPolygon.__geo_interface__!  sc    ==JL(FDMM0012F 2eDKK012!%-@@r   c                    | j                   ry|| j                  rdnd}|d}| j                  j                  D cg c]  } dj                  |  c}g}| j
                  D cg c])  }|j                  D cg c]  } dj                  |  c}+ }}}dj                  ||z   D cg c])  }dj	                  |d	   d
j                  |dd             + c}      }	dj	                  d|z  |	||      S c c}w c c}w c c}}w c c}w )a  Returns 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?z{},{} zM {} L {} zr   z L rZ   za<path fill-rule="evenodd" fill="{2}" stroke="#555555" stroke-width="{0}" opacity="{3}" d="{1}" />g       @)r|   r(   rz   r!   formatr}   join)
r3   scale_factor
fill_coloropacityr$   exterior_coordsr   interior_coordsr!   paths
             r   svgzPolygon.svg+  s    ==&*mmJ?G8<8L8LM1NGNNA.MNJN..
>F9A^W^^Q9
 
 xx .? $$VAY

6!":0FG
:
&|#T:w
?	@ N9
s#   C4%C>8C9C>(.D9C>c                 *     | ||f||f||f||fg      S )z,Construct a `Polygon()` from spatial bounds.rK   )clsxminyminxmaxymaxs        r   from_boundszPolygon.from_boundsM  s(     T4L4,ttTlKLLr   )NN)      ?NN)rE   rF   rG   rH   rI   r6   rJ   rz   r}   r!   r   r   r;   r   classmethodr   __classcell__)r   s   @r   r
   r
      s    !F I. / / * *
 
 


4" A A @D M Mr   r
      c                    t        |      }g }| j                  }t        |      |z  dk\  r|j                  |       n*|j                  t	        |j
                        d d d          | j                  D ]O  }t        |      |z  dk  r|j                  |       &|j                  t	        |j
                        d d d          Q t        |d   |dd        S )Ng        r   rZ   )r"   rz   r   rg   listr!   r}   r
   )polygonsignsringsr]   s        r   r	   r	   V  s    dAED41#TT$++&tt,-!! 2tq C'LLLLdkk*4R401	2
 58U12Y''r   )r   )rH   numpyr*   r   shapely.algorithms.cgar   r   shapely.errorsr   shapely.geometry.baser   shapely.geometry.linestringr   shapely.geometry.pointr   __all__r   r   libregistryrN   r
   r	   rK   r   r   <module>r      s      ; + . 2 (
-f- f-R %  Q /: /:dYMl YMx "  Q (r   