
    \i%D                         S r SSKrSSKJrJr  SSKJrJrJ	r	J
r
  SSKJrJr  SSKJr  SSKJrJr  SS	/r\S
:  rS rS rS rS rS rS rS rSS jrS rS rS rS r S r!S r"SS jr#g)a+  Provides a conversion to / from a ragged array representation of geometries.

A ragged (or "jagged") array is an irregular array of arrays of which each
element can have a different length. As a result, such an array cannot be
represented as a standard, rectangular nD array.
The coordinates of geometries can be represented as arrays of arrays of
coordinate pairs (possibly multiple levels of nesting, depending on the
geometry type).

Geometries, as a ragged array of coordinates, can be efficiently represented
as contiguous arrays of coordinates provided that there is another data
structure that keeps track of which range of coordinate values corresponds
to a given geometry. This can be done using offsets, counts, or indices.

This module currently implements offsets into the coordinates array. This
is the ragged array representation defined by the the Apache Arrow project
as "variable size list array" (https://arrow.apache.org/docs/format/Columnar.html#variable-size-list-layout).
See for example https://cfconventions.org/Data/cf-conventions/cf-conventions-1.9/cf-conventions.html#representations-features
for different options.

The exact usage of the Arrow list array with varying degrees of nesting for the
different geometry types is defined by the GeoArrow project:
https://github.com/geoarrow/geoarrow

    N)creationgeos_version)GeometryType	get_parts	get_ringsget_type_id)_from_ragged_array_multi_linear_from_ragged_array_multipolygon)get_coordinates)is_empty
is_missingfrom_ragged_arrayto_ragged_array)      r   c                 4   [        XUS9n[        U 5      [        U 5      -  nUR                  5       (       a_  [        R
                  " U5      S   nU[        R                  " [        U5      5      -
  n[        R                  " X5[        R                  SS9nUS4$ )N	include_z	include_mr   axis )
r   r   r   anynpnonzeroarangeleninsertnan)arrr   r   coordsemptiesindicess         X/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/shapely/_ragged_array.py_get_arrays_pointr%   3   sw    SKF smjo-G{{}}**W%a(BIIc'l336BFF;2:    c                 R   [        U 5      S:  a  [        R                  nO[        R                  n[        R                  " [        R
                  " U 5      R                  US9SS5      n[        U5      US-   :w  a+  [        R                  " USUS-   [        U5      -
  4SUS   S9nU$ )Nidtyper      constant)constant_values)r   r   int64int32r   bincountcumsumpad)r#   nr)   offsetss       r$   _indices_to_offsetsr5   B   s     7|j iiG,33%3@!QGG
7|q1u&&AG$%#BK	
 Nr&   c                 `    [        U SS9u  p4[        U[        U 5      5      n[        XUS9nXe44$ )NTreturn_indexr   r   r5   r   r   )r    r   r   _part_indicesr4   r!   s          r$   _get_arrays_multipointr<   W   s9    $7OA!,C9G SKF:r&   c                 N    [        U SXS9u  p4[        U[        U 5      5      nX544$ )NTr8   r   r   )r   r5   r   )r    r   r   r!   r#   r4   s         r$   _get_arrays_linestringr?   c   s2    %$)OF "'3s84G:r&   c                     [        U SS9u  p4[        U[        U 5      5      n[        USXS9u  pg[        U[        U5      5      nXhU44$ NTr7   r>   r9   )	r    r   r   arr_flatr;   offsets2r!   r#   offsets1s	            r$   _get_arrays_multilinestringrE   m   V    &s>H"<S:H &tyOF #7CM:Hh'''r&   c                     [        U SS9u  p4[        U[        U 5      5      n[        USXS9u  pg[        U[        U5      5      nXhU44$ rA   )r   r5   r   r   )	r    r   r   rB   ring_indicesrC   r!   r#   rD   s	            r$   _get_arrays_polygonrI   |   rF   r&   c                     [        U SS9u  p4[        U[        U 5      5      n[        USS9u  pg[        U[        U5      5      n[	        USXS9u  p[        U
[        U5      5      nXX44$ rA   )r   r5   r   r   r   )r    r   r   rB   r;   offsets3	arr_flat2rH   rC   r!   r#   rD   s               r$   _get_arrays_multipolygonrM      sw    &s>H"<S:H (tDI"<X?H &	OF #7C	N;Hh111r&   c           	         SSK JnJn  [        R                  " U 5      n Uc)  [        R
                  " U" U [        U 5      )    5      5      nUc7  [        (       a*  [        R
                  " U" U [        U 5      )    5      5      nOSn[        R                  " [        U 5      5      nXUS:     nXU4n[        U5      S:X  a  [        US   5      nU[        R                  :X  a  [        U6 u  pGOU[        R                  :X  a  [        U6 u  pGOU[        R                   :X  a  [#        U6 u  pGOU[        R$                  :X  a  ['        U6 u  pGOU[        R(                  :X  a  [+        U6 u  pGOU[        R,                  :X  a  [/        U6 u  pGOg[1        SUR2                   S35      e[        U5      S:X  Ga  [5        U5      [        R                  [        R$                  1:X  a  [        R$                  n['        U6 u  pO[5        U5      [        R                  [        R(                  1:X  a  [        R(                  n[+        U6 u  pO[5        U5      [        R                   [        R,                  1:X  a  [        R,                  n[/        U6 u  pOf[1        SU V
s/ s H  n
[        U
5      R2                  PM     sn
 S	35      e[1        SU V
s/ s H  n
[        U
5      R2                  PM     sn
 S	35      eXxU	4$ s  sn
f s  sn
f )
az  Convert geometries to a ragged array representation.

This function converts an array of geometries to a ragged array
(i.e. irregular array of arrays) of coordinates, represented in memory
using a single contiguous array of the coordinates, and
up to 3 offset arrays that keep track where each sub-array
starts and ends.

This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.

Parameters
----------
geometries : array_like
    Array of geometries (1-dimensional).
include_z, include_m : bool, default None
    If both are False, return XY (2D) geometries.
    If both are True, return XYZM (4D) geometries.
    If either is True, return either XYZ or XYM (3D) geometries.
    If a geometry has no Z or M dimension, extra coordinate data will be NaN.
    By default, will infer the dimensionality from the
    input geometries. Note that this inference can be unreliable with
    empty geometries (for a guaranteed result, it is recommended to
    specify the keyword).

    .. versionadded:: 2.1.0
        The ``include_m`` parameter was added to support XYM (3D) and
        XYZM (4D) geometries available with GEOS 3.12.0 or later.
        With older GEOS versions, M dimension coordinates will be NaN.

Returns
-------
tuple of (geometry_type, coords, offsets)
    geometry_type : GeometryType
        The type of the input geometries (required information for
        roundtrip).
    coords : np.ndarray
        Contiguous array of shape (n, 2), (n, 3), or (n, 4) of all
        coordinates of all input geometries.
    offsets: tuple of np.ndarray
        Offset arrays that make it possible to reconstruct the
        geometries from the flat coordinates array. The number of
        offset arrays depends on the geometry type. See
        https://github.com/geoarrow/geoarrow/blob/main/format.md
        for details.
        Uses int32 dtype offsets if possible, otherwise int64 for
        large inputs (coordinates > 32GB).

Notes
-----
Mixed singular and multi geometry types of the same basic type are
allowed (e.g., Point and MultiPoint) and all singular types will be
treated as multi types.
GeometryCollections and other mixed geometry types are not supported.

See Also
--------
from_ragged_array

Examples
--------
Consider a Polygon with one hole (interior ring):

>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon(
...     [(0, 0), (10, 0), (10, 10), (0, 10)],
...     holes=[[(2, 2), (3, 2), (2, 3)]]
... )
>>> polygon
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 3 2, 2 3, 2 2))>

This polygon can be thought of as a list of rings (first ring is the
exterior ring, subsequent rings are the interior rings), and each ring
as a list of coordinate pairs. This is very similar to how GeoJSON
represents the coordinates:

>>> import json
>>> json.loads(shapely.to_geojson(polygon))["coordinates"]
[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]],
 [[2.0, 2.0], [3.0, 2.0], [2.0, 3.0], [2.0, 2.0]]]

This function will return a similar list of lists of lists, but
using a single contiguous array of coordinates, and multiple arrays of
offsets:

>>> geometry_type, coords, offsets = shapely.to_ragged_array([polygon])
>>> geometry_type
<GeometryType.POLYGON: 3>
>>> coords
array([[ 0.,  0.],
       [10.,  0.],
       [10., 10.],
       [ 0., 10.],
       [ 0.,  0.],
       [ 2.,  2.],
       [ 3.,  2.],
       [ 2.,  3.],
       [ 2.,  2.]])

>>> offsets
(array([0, 5, 9], dtype=int32), array([0, 2], dtype=int32))

As an example how to interpret the offsets: the i-th ring in the
coordinates is represented by ``offsets[0][i]`` to ``offsets[0][i+1]``:

>>> exterior_ring_start, exterior_ring_end = offsets[0][0], offsets[0][1]
>>> coords[exterior_ring_start:exterior_ring_end]
array([[ 0.,  0.],
       [10.,  0.],
       [10., 10.],
       [ 0., 10.],
       [ 0.,  0.]])

r   )has_mhas_zFr*   Geometry type  is not supported   z,Geometry type combination is not supported ())shapelyrO   rP   r   asarrayr   r   _geos_ge_312uniquer   r   r   POINTr%   
LINESTRINGr?   POLYGONrI   
MULTIPOINTr<   MULTILINESTRINGrE   MULTIPOLYGONrM   
ValueErrornameset)
geometriesr   r   rO   rP   
geom_typesget_arrays_argstypr!   r4   ts              r$   r   r      s   j %J'JFF5Xj-A,A!BCD	<uZ*1E0E%FGHII;z23J!O,J Y6O
:!:a=),$$$/AOFGL+++4oFOFGL(((1?COFGL+++4oFOFGL0009?KOFGL---6HOFG~chhZ7HIJJ	ZA	z?|11<3J3JKK))C4oFOFG_!8!8,:V:V WW..C9?KOFG_!5!5|7P7P QQ++C6HOFG3=>:a\!_)):>?qB 
 /9:z!a%%z:;1>
 	

  ?
 ;s   K7

K<
c                    [         R                  " U 5      n[        R                  " U 5      R	                  SS9nUR                  5       (       a3  [         R                  " S[        R                  S9R                  5       X'   U$ )Nr*   r   	geom_type)
r   pointsr   isnanallr   emptyr   rY   item)r!   resultr"   s      r$   _point_from_flatcoordsrp   P  s_    __V$F hhv"""*G{{}}"..l6H6HINNPMr&   c                    [        U5      (       a  XS   S  n [        R                  " U 5      n[        R                  " U5      n[        R
                  " [        R                  " [        U5      5      U5      n[        R                  " [        U5      S-
  [        S9n[        R                  " X$US9n[        R                  " S[        R                  S9R                  5       XSS:H  '   U$ Nr   r*   r(   )r#   outrh   )r   r   rj   r   diffrepeatr   rm   objectmultipointsr   r\   rn   )r!   r4   rj   multipoint_partsmultipoint_indicesro   s         r$   _multipoint_from_flatcoordsrz   \  s    
7||
%__V$F www'299S1A-B#CEUVXXc'lQ&f5F!!&&QF$,NN	\,,%
df q ! Mr&   c                    [        U5      (       a  XS   S  n [        R                  " U5      n[        R                  " [        R                  " [        U5      5      U5      n[        R
                  " [        U5      S-
  [        S9n[        R                  " XUS9n[        R
                  " S[        R                  S9R                  5       XBS:H  '   U$ rr   )r   r   rt   ru   r   rm   rv   r   linestringsr   rZ   rn   )r!   r4   linestring_nlinestring_indicesro   s        r$   _linestring_from_flatcoordsr   o  s    
7||
%777#L299S->#?NXXc'lQ&f5F!!&&QF (	\,,!
df 1 Mr&   c                     [         R                  " USS9n[         R                  " USS9n[        XU[        R                  S9nU$ Nr.   r(   )geometry_type)r   rV   r	   r   r]   r!   rD   rC   ro   s       r$   !_multilinestrings_from_flatcoordsr   ~  sB    zz('2Hzz('2H -(,2N2NF Mr&   c                     [         R                  " USS9n[         R                  " USS9n[        XU[        R                  S9nU$ r   )r   rV   r	   r   r[   r   s       r$   _polygon_from_flatcoordsr     sB    zz('2Hzz('2H -(,2F2FF Mr&   c                     [         R                  " USS9n[         R                  " USS9n[         R                  " USS9n[        XX#5      nU$ )Nr.   r(   )r   rV   r
   )r!   rD   rC   rK   ro   s        r$   _multipolygons_from_flatcoordsr     sE    zz('2Hzz('2Hzz('2H -VxRFMr&   c                 2   [         R                  " USS9nU [        R                  :X  a(  Ub  [	        U5      S:X  d  [        S5      e[        U5      $ Uc  [        S5      eU [        R                  :X  a  [        U/UQ76 $ U [        R                  :X  a  [        U/UQ76 $ U [        R                  :X  a  [        U/UQ76 $ U [        R                  :X  a  [        U/UQ76 $ U [        R                  :X  a  [!        U/UQ76 $ [        SU R"                   S35      e)a  Create geometries from a contiguous array of coordinates and offset arrays.

This function creates geometries from the ragged array representation
as returned by ``to_ragged_array``.

This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.

See :func:`to_ragged_array` for more details.

Parameters
----------
geometry_type : GeometryType
    The type of geometry to create.
coords : np.ndarray
    Contiguous array of shape (n, 2) or (n, 3) of all coordinates
    for the geometries.
offsets: tuple of np.ndarray
    Offset arrays that allow to reconstruct the geometries based on the
    flat coordinates array. The number of offset arrays depends on the
    geometry type. See
    https://github.com/geoarrow/geoarrow/blob/main/format.md for details.

Returns
-------
np.ndarray
    Array of geometries (1-dimensional).

See Also
--------
to_ragged_array

float64r(   r   z8'offsets' should not be provided for geometry type PointzA'offsets' must be provided for any geometry type except for PointrQ   rR   )r   rV   r   rY   r   r_   rp   rZ   r   r[   r   r\   rz   r]   r   r^   r   r`   )r   r!   r4   s      r$   r   r     s   F ZZi0F***3w<1#4WXX%f--O
 	
 ///*6<G<<	,..	.'999	,11	1*6<G<<	,66	60B'BB	,33	3-f?w??>-*<*<)==NOPPr&   )NN)N)$__doc__numpyr   rU   r   r   shapely._geometryr   r   r   r   shapely._geometry_helpersr	   r
   shapely.coordinatesr   shapely.predicatesr   r   __all__rW   r%   r5   r<   r?   rE   rI   rM   r   rp   rz   r   r   r   r   r   r   r&   r$   <module>r      s   4  *  0 3 1
2z)*	((2(k b	&		:Qr&   