
    _ 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y)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       t/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/shapely/geometry/polygon.py_unpickle_linearringr      sM    !!#&JJ'D";;JGJ%%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  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              r7t	        |      t
        u 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 )z!Create a new LinearRing geometry.z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lenlinearrings)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 )z9Return a GeoJSON-like mapping of the LinearRing geometry.r	   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 )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&PQQr   c                 >    t        t        j                  |             S )z0True if the ring is oriented counter clock-wise.)boolr   is_ccwr:   s    r   rB   zLinearRing.is_ccwz   s     GNN4())r   c                 >    t        t        j                  |             S )zwTrue if the geometry is simple.

        Simple means that any self-intersections are only at boundary points.
        )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    B 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                   t    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y)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                 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 )zCreate a new Polygon geometry.NzPOLYGON EMPTYr   )holesz,Invalid values passed to Polygon constructor)r   r%   r   r
   r	   r1   polygonsr0   )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 )z(Return the exterior ring of the polygon.)r   get_exterior_ringr:   s    r   exteriorzPolygon.exterior   s     ((..r   c                 4    | j                   rg S t        |       S )z5Return the sequence of interior rings of the polygon.)is_emptyrN   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 }nUt        | j                   j                        g}| j                  D ]&  }|j                  t        |j                               ( dt        |      dS )z6Return a GeoJSON-like mapping of the Polygon geometry.r
   r8   )rz   r	   r9   r    r}   rg   )r3   r    holes      r   r;   zPolygon.__geo_interface__  se     ==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| dd|z   d| d|	 d	S c c}w c c}w c c}}w c c}w )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?z{},{} zM {} L {} zr   z L rZ   z <path fill-rule="evenodd" fill="z!" stroke="#555555" stroke-width="g       @z" opacity="z" d="z" />)r|   r'   rz   r    formatr}   join)
r3   scale_factor
fill_coloropacityr#   exterior_coordsinterior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
 /zl ; </0G9E$tU	
 N9
s#   C/%C98C4C9(.C?4C9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_bounds<  s(     T4L4,ttTlKLLr   )NN)      ?NN)rE   rF   rG   rH   rI   r6   rJ   rz   r}   r    r;   r   classmethodr   rK   r   r   r
   r
      s    "H I0 / / * * 
 
 A A!
F M M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Cr   )r   )rH   numpyr)   r   r   shapely.algorithms.cgar   shapely.errorsr   shapely.geometry.baser   shapely.geometry.linestringr   shapely.geometry.pointr   __all__r   r	   libregistryrN   r
   r   rK   r   r   <module>r      s    0   % . + . 2 (
-l- l-^ %  Q .: .:bCMl CML "  Q Dr   