
    \iOd                     f   S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJr  / SQr " S	 S
5      r\" 5       r\R*                  r\R,                  r\R.                  r\R0                  rSS jrSS jrS rS rS rS rS r " S S5      r \ RB                  r!SS jr"S r#SS jr$g)z-Support for various GEOS geometry operations.    N)	polylabel)GeometryTypeError)GeometryCollection
LineStringMultiLineString
MultiPointPointPolygonshape)BaseGeometry)prep)clip_by_rect	linemergenearest_pointsoperatororient
polygonizepolygonize_fullshared_pathssnapsplit	substring	transformtriangulateunary_unionvalidatevoronoi_diagramc                   6    \ rS rSrS rS rS rS	S jrS rSr	g)
CollectionOperator&   c                     [        U[        5      (       a  U$  [        U5      $ ! [        [        4 a    [        U5      s $ f = fN)
isinstancer   r   
ValueErrorAttributeErrorr   )selfobs     N/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/shapely/ops.pyshapeupCollectionOperator.shapeup'   sA    b,''I&Ry / &!"~%&s   
$ AAc                 N   [        USS5      =(       d    Un [        U5      nU Vs/ s H  o0R                  U5      PM     nn[        R
                  " U5      nUR                  $ ! [         a    U/n NQf = fs  snf ! U Vs/ s H  o0R                  U5      PM     nnf s  snf = f)zCreate polygons from a source of lines.

The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings.
geomsN)getattriter	TypeErrorr)   shapelyr   r,   )r&   linessourcelineobs
collections         r(   r   CollectionOperator.polygonize0   s     .7%	:&\F 399&$<<%&C9'',
  	XF	 :&9&$<<%&C9C9s4   A% A8%A52A= 4A55A= =B$BB$c                 6   [        USS5      =(       d    Un [        U5      nU Vs/ s H  o0R                  U5      PM     nn[        R
                  " U5      $ ! [         a    U/n NEf = fs  snf ! U Vs/ s H  o0R                  U5      PM     nnf s  snf = f)a@  Create polygons from a source of lines.

The polygons and leftover geometries are returned as well.

The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings.

Returns a tuple of objects: (polygons, cut edges, dangles, invalid ring
lines). Each are a geometry collection.

Dangles are edges which have one or both ends which are not incident on
another edge endpoint. Cut edges are connected at both ends but do not
form part of polygon. Invalid ring lines form rings which are invalid
(bowties, etc).
r,   N)r-   r.   r/   r)   r0   r   )r&   r1   r2   r3   r4   s        r(   r   "CollectionOperator.polygonize_full@   s      .7%	:&\F 399&$<<%&C9&&s++	  	XF	 :&9&$<<%&C9C9s4   A A,A)&A1 (A))A1 1B6BBc                    Sn[        USS5      S:X  a  UnOx[        US5      (       a0  [        UR                   Vs/ s H  oDR                  PM     sn5      nO7[        US5      (       a&   [        U Vs/ s H  oDR                  PM     sn5      nUc  [        SU 35      e[        R                  " X2S9$ s  snf s  snf ! [
         a    [        U5      n NFf = f)zMerge all connected lines from a source.

The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings.  Returns a
LineString or MultiLineString when lines are not contiguous.
N	geom_typer   r,   __iter__zCannot linemerge )directed)	r-   hasattrr   r,   coordsr%   r$   r0   
line_merge)r&   r1   r<   r2   lss        r(   r   CollectionOperator.linemergeY   s     5+t,0AAFUG$$$%++%F+Bii+%FGFUJ''0(e)De))e)DE >0899!!&<< &G *E! 0(/0s)   B4*	B> 3B9B> 9B> >CCc                 ,    [         R                  " USS9$ )zReturn the union of a sequence of geometries.

Usually used to convert a collection into the smallest set of polygons
that cover the same area.
N)axis)r0   	union_all)r&   r,   s     r(   r   CollectionOperator.unary_uniono   s       T22     NF)
__name__
__module____qualname____firstlineno__r)   r   r   r   r   __static_attributes__rG   rF   r(   r   r   &   s    &  ,2=,3rF   r   c                 V    [         R                  " XUS9n[        UR                  5      $ )a  Create the Delaunay triangulation and return a list of geometries.

The source may be any geometry type. All vertices of the geometry will be
used as the points of the triangulation.

From the GEOS documentation:
tolerance is the snapping tolerance used to improve the robustness of
the triangulation computation. A tolerance of 0.0 specifies that no
snapping will take place.

If edges is False, a list of Polygons (triangles) will be returned.
Otherwise the list of LineString edges is returned.

)	tolerance
only_edges)r0   delaunay_triangleslistr,   )geomrO   edgesr5   s       r(   r   r      s(     ++DRWXJ
  !!rF   c                      [         R                  " XXS9nUR                  S:w  a  [        U/5      $ U$ ! [         R                   a)  nSnUSU< S3-  nU(       a  US-  n[        U5      UeSnAff = f)a  Construct a Voronoi Diagram [1] from the given geometry.

Returns a list of geometries.

Parameters
----------
geom: geometry
    the input geometry whose vertices will be used to calculate
    the final diagram.
envelope: geometry, None
    clipping envelope for the returned diagram, automatically
    determined if None. The diagram will be clipped to the larger
    of this envelope or an envelope surrounding the sites.
tolerance: float, 0.0
    sets the snapping tolerance used to improve the robustness
    of the computation. A tolerance of 0.0 specifies that no
    snapping will take place.
edges: bool, False
    If False, return regions as polygons. Else, return only
    edges e.g. LineStrings.

GEOS documentation can be found at [2]

Returns
-------
GeometryCollection
    geometries representing the Voronoi regions.

Notes
-----
The tolerance `argument` can be finicky and is known to cause the
algorithm to fail in several cases. If you're using `tolerance`
and getting a failure, try removing it. The test cases in
tests/test_voronoi_diagram.py show more details.


References
----------
[1] https://en.wikipedia.org/wiki/Voronoi_diagram
[2] https://geos.osgeo.org/doxygen/geos__c_8h_source.html  (line 730)

)rO   	extend_torP   z;Could not create Voronoi Diagram with the specified inputs (z).z0 Try running again with default tolerance value.Nr   )r0   voronoi_polygonsGEOSExceptionr$   r:   r   )rS   enveloperO   rT   resulterrerrstrs          r(   r   r      s    V	*))
 //!6(++M    *NAcWB-HHF c)*s   5 A2	$A--A2c                 .    [         R                  " U 5      $ )z%Return True if the geometry is valid.)r0   is_valid_reason)rS   s    r(   r   r      s    ""4((rF   c                 J   UR                   (       a  U$ UR                  S;   a   UR                  S;   a*  [        U5      " [        U " [        UR                  6 6 6 5      $ UR                  S:X  a  [        UR
                  5      " [        U " [        UR
                  R                  6 6 6 5      nUR                   Vs/ s H-  n[        U5      " [        U " [        UR                  6 6 6 5      PM/     nn[        U5      " X$5      $ gUR                  R                  S5      (       d  UR                  S:X  a5  [        U5      " UR                   Vs/ s H  n[        X5      PM     sn5      $ [        SUR                  < S35      es  snf ! [         Ga    UR                  S;   a6  [        U5      " UR                   Vs/ s H  oP" U6 PM	     Os  snf sn5      s $ UR                  S:X  a  [        UR
                  5      " UR
                  R                   Vs/ s H  oP" U6 PM	     Os  snf sn5      nUR                   VVs/ s H7  n[        U5      " UR                   Vs/ s H  oP" U6 PM	     Os  snf sn5      PM9     Os  snnf nnn[        U5      " X$5      s $  gf = fs  snf )	a  Apply `func` to all coordinates of `geom`.

Returns a new geometry of the same type from the transformed coordinates.

`func` maps x, y, and optionally z to output xp, yp, zp. The input
parameters may iterable types like lists or arrays or single values.
The output shall be of the same type. Scalars in, scalars out.
Lists in, lists out.

For example, here is an identity function applicable to both types
of input.

  def id_func(x, y, z=None):
      return tuple(filter(None, [x, y, z]))

  g2 = transform(id_func, g1)

Using pyproj >= 2.1, this example will accurately project Shapely geometries:

  import pyproj

  wgs84 = pyproj.CRS('EPSG:4326')
  utm = pyproj.CRS('EPSG:32618')

  project = pyproj.Transformer.from_crs(wgs84, utm, always_xy=True).transform

  g2 = transform(project, g1)

Note that the always_xy kwarg is required here as Shapely geometries only support
X,Y coordinate ordering.

Lambda expressions such as the one in

  g2 = transform(lambda x, y, z=None: (x+1.0, y+1.0), g1)

also satisfy the requirements for `func`.
)r	   r   
LinearRingr
   )r	   r   ra   r
   Multir   zType z not recognizedN)is_emptyr:   typezipr>   exterior	interiorsr/   
startswithr,   r   r   )funcrS   shellringholescparts          r(   r   r      s/   L }}~~II
	0~~!FFDz#tS$++->'?"@AA9,T]]+CsDMM<P<P7Q1R,ST !% . JsD#t{{*;$<=> .   Dz%// -* 
	"	"7	+	+t~~AU/UDzTZZHZT9T0ZHII%'9 IJJ-  		0~~!FFDzT[["A[48["ABB9,T]]+t}}?S?S,T?S!T1X?S,TU !% . J$++>+Qa+>? .  Dz%// -		0 Isf   9F AF ;4F/F J F 4J;G

	J=JH$
#J?I>I-,I>=JJc                     [         R                  " X5      nUc'  U R                  (       a  [        S5      e[        S5      e[         R                  " US5      n[         R                  " US5      nX44$ )zReturn the calculated nearest points in the input geometries.

The points are returned in the same order as the input geometries.
z!The first input geometry is emptyz"The second input geometry is emptyr      )r0   shortest_linerc   r$   	get_point)g1g2seqp1p2s        r(   r   r     sc    
 


'C
{;;@AAABB			3	"B			3	"B8OrF   c                 0    [         R                  " XU5      $ )a  Snaps an input geometry (g1) to reference (g2) geometry's vertices.

Parameters
----------
g1 : geometry
    The first geometry
g2 : geometry
    The second geometry
tolerance : float
    The snapping tolerance

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

)r0   r   )rs   rt   rO   s      r(   r   r   .  s     <<	**rF   c                     [        U [        5      (       d  [        S5      e[        U[        5      (       d  [        S5      e[        R                  " X5      $ )a  Find paths shared between the two given lineal geometries.

Returns a GeometryCollection with two elements:
 - First element is a MultiLineString containing shared paths with the
   same direction for both inputs.
 - Second element is a MultiLineString containing shared paths with the
   opposite direction for the two inputs.

Parameters
----------
g1 : geometry
    The first geometry
g2 : geometry
    The second geometry

z#First geometry must be a LineStringz$Second geometry must be a LineString)r#   r   r   r0   r   )rs   rt   s     r(   r   r   @  sG    " b*%% EFFb*%% FGG''rF   c                   d    \ rS rSr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r	Sr
g)	SplitOpiX  c                 f   [        U [        5      (       d  [        S5      e[        U[        [        45      (       d  [        S5      eU R
                  R                  U5      n[        U 5      n [        U5       Vs/ s H*  o0R                  UR                  5       5      (       d  M(  UPM,     sn$ s  snf )z"Split a Polygon with a LineString.z First argument must be a Polygonz+Second argument must be a (Multi)LineString)r#   r
   r   r   r   boundaryunionr   r   containsrepresentative_point)polysplitterr~   pgs       r(   _split_polygon_with_line SplitOp._split_polygon_with_lineY  s     $((#$FGG(Z$ABB#$QRR##H-
 Dz $E*
*2mmB<S<S<U.VB*
 	
 
s   :'B.%B.c                 z   UR                   S;   a  UR                  n[        U [        5      (       d  [	        S5      e[        U[        5      (       d   [        U[
        5      (       d  [	        S5      eUR                  U 5      nUS   S:X  a  [        S5      eUS   S:X  d	  US   S:X  a  U R                  U5      $ U /$ )	zDSplit a LineString with another (Multi)LineString or (Multi)Polygon.)r
   MultiPolygon#First argument must be a LineStringz@Second argument must be either a LineString or a MultiLineStringr   1z2Input geometry segment overlaps with the splitter.0   )	r:   r}   r#   r   r   r   relater$   
difference)r3   r   relations      r(   _split_line_with_lineSplitOp._split_line_with_lineo  s     !<<((H$
++#$IJJ(J//
o9
 9
 $R  ??4(A;#QRRa[C8A;##5 ??8,, 6MrF   c                    [        U [        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eU R	                  US5      (       d  U /$ U R
                  S   UR
                  S   :X  a  U /$ U R                  U5      n[        U R
                  5      nSn[        [        U5      S-
  5       H  nX5   nX5S-      nUS   US   -
  nUS   US   -
  n	US-  U	S-  -   S-  n
XJ-  nX$:X  a#  [        US	US-    5      [        X5S-   S	 5      /s  $ X$:  d  Me  [        US	US-    UR
                  S   /-   5      [        UR
                  S   /X5S-   S	 -   5      /s  $    U /$ )
z Split a LineString with a Point.r   zSecond argument must be a Pointz	0********r           rp            ?N)
r#   r   r   r	   relate_patternr>   projectrR   rangelen)r3   r   distance_on_liner>   current_positionipoint1point2dxdysegment_lengths              r(   _split_line_with_pointSplitOp._split_line_with_point  s    $
++#$IJJ(E**#$EFF ""8[99
 6M[[^xq116M  <<1dkk"s6{Q'AYFE]FVAY&BVAY&B !eb!em3N.3"6'AE?3Z1uw5PQQ!4 vgA(//!2D1EEF 23fUWoEF  (  vrF   c                 *   [        U [        5      (       d  [        S5      e[        U[        5      (       d  [        S5      eU /nUR                   H?  n/ n[        S U5       H'  nUR                  [        R                  XS5      5        M)     UnMA     U$ )z%Split a LineString with a MultiPoint.r   z$Second argument must be a MultiPointc                 $    U R                   (       + $ r"   )rc   )xs    r(   <lambda>5SplitOp._split_line_with_multipoint.<locals>.<lambda>  s
    ajj.rF   )	r#   r   r   r   r,   filterextendr{   r   )r3   r   chunkspt
new_chunkschunks         r(   _split_line_with_multipoint#SplitOp._split_line_with_multipoint  s     $
++#$IJJ(J//#$JKK..BJ 8&A!!'"@"@"KL B  F ! rF   c           
         U R                   S;   aN  [        U R                   VVs/ s H+  n[        R	                  X!5      R                    H  o3PM     M-     snn5      $ U R                   S:X  a|  UR                   S;   a  [        R
                  nOUR                   S:X  a  [        R                  nOUR                   S:X  a  [        R                  nO|[        SUR                    S35      eU R                   S:X  a:  UR                   S	;   a  [        R                  nO2[        S
UR                    S35      e[        SU R                    S35      e[        U" X5      5      $ s  snnf )a  Split a geometry by another geometry and return a collection of geometries.

This function is the theoretical opposite of the union of
the split geometry parts. If the splitter does not split the geometry, a
collection with a single geometry equal to the input geometry is
returned.

The function supports:
  - Splitting a (Multi)LineString by a (Multi)Point or (Multi)LineString
    or (Multi)Polygon
  - Splitting a (Multi)Polygon by a LineString

It may be convenient to snap the splitter with low tolerance to the
geometry. For example in the case of splitting a line by a point, the
point must be exactly on the line, for the line to be correctly split.
When splitting a line by a polygon, the boundary of the polygon is used
for the operation. When splitting a line by another line, a ValueError
is raised if the two overlap at some segment.

Parameters
----------
geom : geometry
    The geometry to be split
splitter : geometry
    The geometry that will split the input geom

Examples
--------
>>> import shapely.ops
>>> from shapely import Point, LineString
>>> pt = Point((1, 1))
>>> line = LineString([(0,0), (2,2)])
>>> result = shapely.ops.split(line, pt)
>>> result.wkt
'GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), LINESTRING (1 1, 2 2))'

)r   r   r   )r   r   r
   r   r	   r   zSplitting a LineString with a z is not supportedr
   )r   r   zSplitting a Polygon with a z
Splitting z geometry is not supported)
r:   r   r,   r{   r   r   r   r   r   r   )rS   r   rn   r   
split_funcs        r(   r   SplitOp.split  sV   N >>@@%#zzWzt7==3P3V3Va3VzW  ^^|+!! &  %::
##w.$;;
##|3$@@
'4X5G5G4H I$ $ 
 ^^y(!!%FF$==
'1(2D2D1EEVW 
 $T^^,,FG  "*T"<==E Xs   2E
rG   N)rI   rJ   rK   rL   staticmethodr   r   r   r   r   rM   rG   rF   r(   r{   r{   X  sh    
 
*  B ' 'R  " J> J>rF   r{   c                    [        U [        5      (       d  [        SU R                   S35      eX:X  a  U R	                  XS9$ U(       d8  XR
                  :  a)  X R
                  :  a  U R	                  U R
                  US9$ U(       d2  U* U R
                  :  a!  U* U R
                  :  a  U R	                  SUS9$ U(       a  US:  a  US:  a  U R	                  SUS9$ U(       a  U* S:  a  U* S:  a  U R	                  SUS9$ U(       a  XR
                  -  nX R
                  -  nUSs=:  a  U:  a0  O  O-[        U5      U-   U R
                  :X  a  U R	                  U5      $ USs=:  a  U:  a0  O  O-[        U5      U-   U R
                  :X  a  U R	                  U5      $ U R	                  U5      nU R	                  U5      nUS:  a  U R
                  U-   nUS:  a  U R
                  U-   nX:  nU(       a  X!p![        US5      nU(       a  [        UR                  6 /nO[        UR                  6 /n[        U R                  5      nSn	[        XSS 5       HO  u  pXs=:  a  U:  a  O  OUR                  U
5        OX:  a    O&XS   U
S   -
  S-  US   U
S   -
  S-  -   S-  -  n	MQ     U(       a-  UR                  [        UR                  6 5        [        U5      nO!UR                  [        UR                  6 5        [        U5      $ )	a  Return a line segment between specified distances along a LineString.

Negative distance values are taken as measured in the reverse
direction from the end of the geometry. Out-of-range index
values are handled by clamping them to the valid range of values.

If the start distance equals the end distance, a Point is returned.

If the start distance is actually beyond the end distance, then the
reversed substring is returned such that the start distance is
at the first coordinate.

Parameters
----------
geom : LineString
    The geometry to get a substring of.
start_dist : float
    The distance along `geom` of the start of the substring.
end_dist : float
    The distance along `geom` of the end of the substring.
normalized : bool, False
    Whether the distance parameters are interpreted as a
    fraction of the geometry's length.

Returns
-------
Union[Point, LineString]
    The substring between `start_dist` and `end_dist` or a Point
    if they are at the same location.

Raises
------
TypeError
    If `geom` is not a LineString.

Examples
--------
>>> from shapely.geometry import LineString
>>> from shapely.ops import substring
>>> ls = LineString((i, 0) for i in range(6))
>>> ls.wkt
'LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)'
>>> substring(ls, start_dist=1, end_dist=3).wkt
'LINESTRING (1 0, 2 0, 3 0)'
>>> substring(ls, start_dist=3, end_dist=1).wkt
'LINESTRING (3 0, 2 0, 1 0)'
>>> substring(ls, start_dist=1, end_dist=-3).wkt
'LINESTRING (1 0, 2 0)'
>>> substring(ls, start_dist=0.2, end_dist=-0.6, normalized=True).wkt
'LINESTRING (1 0, 2 0)'

Returning a `Point` when `start_dist` and `end_dist` are at the
same location.

>>> substring(ls, 2.5, -2.5).wkt
'POINT (2.5 0)'

z;Can only calculate a substring of LineString geometries. A z was provided.)
normalizedr   rp   Nr   r   )r#   r   r   r:   interpolatelengthabsmaxtupler>   rR   re   appendreversed)rS   
start_distend_distr   start_point	end_pointreversevertex_listr>   current_distancerv   rw   s               r(   r   r     s   v dJ'' 0
 	
 
BBJ++5(kk:Q
CCZK4;;6H9;Sj99	
aHMj99	q(hY!^j99kk!
KK A  S_x%?4;;%N))	A	"
	"s8}z'AT[['P
++"":.K  *IA~[[:-
!|;;)#G'HZ#Ji../0k0012$++FfQRj)383r")ebem1RURU]q4HHSPP * 5+"4"456{+5)"2"234k""rF   c                 X    U R                   (       a  U $ [        R                  " XX#U5      $ )a  Return the portion of a geometry within a rectangle.

The geometry is clipped in a fast but possibly dirty way. The output is
not guaranteed to be valid. No exceptions will be raised for topological
errors.

Parameters
----------
geom : geometry
    The geometry to be clipped
xmin : float
    Minimum x value of the rectangle
ymin : float
    Minimum y value of the rectangle
xmax : float
    Maximum x value of the rectangle
ymax : float
    Maximum y value of the rectangle

Notes
-----
New in 1.7.

)rc   r0   r   )rS   xminyminxmaxymaxs        r(   r   r     s%    2 }}D==rF   c                 0    [         R                  " XS:  S9$ )a  Return a properly oriented copy of the given geometry.

The signed area of the result will have the given sign. A sign of
1.0 means that the coordinates of the product's exterior rings will
be oriented counter-clockwise.

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

Parameters
----------
geom : Geometry
    The original geometry. May be a Polygon, MultiPolygon, or
    GeometryCollection.
sign : float, optional.
    The sign of the result's signed area.

Returns
-------
Geometry

r   )exterior_cw)r0   orient_polygons)rS   signs     r(   r   r     s    , ""4AX>>rF   )r   F)Nr   FrH   )g      ?)%__doc__r0   shapely.algorithms.polylabelr   shapely.errorsr   shapely.geometryr   r   r   r   r	   r
   r   shapely.geometry.baser   shapely.preparedr   __all__r   r   r   r   r   r   r   r   r   r   r   r   r   r{   r   r   r   r   rG   rF   r(   <module>r      s    3  2 ,   / !(O3 O3d   
**	"""&8v)
HKV"+$(0@> @>F 	{#|><?rF   