
    rbi%                     x    d Z ddlZddlZddlZddlmZmZm	Z	 ddl
mZmZ ddlmZmZmZmZmZ d Zd
dZdd	ZdS )z+Module to clip vector data using GeoPandas.    N)MultiPolygonPolygonbox)GeoDataFrame	GeoSeries)LINE_GEOM_TYPESPOINT_GEOM_TYPESPOLYGON_GEOM_TYPES
_check_crs_crs_mismatch_warnc                     t           j        j                            |           o-t	          | t
          t          z  t          z  t          z             S )a  
    Check if the input mask is list-like and not an instance of
    specific geometric types.

    Parameters
    ----------
    mask : GeoDataFrame, GeoSeries, (Multi)Polygon, list-like
        Polygon vector layer used to clip ``gdf``.

    Returns
    -------
    bool
        True if `mask` is list-like and not an instance of `GeoDataFrame`,
        `GeoSeries`, `Polygon`, or `MultiPolygon`, otherwise False.
    )	pandasapitypesis_list_like
isinstancer   r   r   r   )masks    d/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/geopandas/tools/clip.py_mask_is_list_like_rectangler      sI      :((.. zlY&0<?8 8 4     Fc                    t          |          }|r
t          | }n|}| j        | j                            |d|                   }|j        dk    }|                                s|S t          |t                    ru|	                                }|r* |j
        j        |         j        | |j        ||j        f<   n|j
        j        |                             |          |j        ||j        f<   nR|	                                }|r |j        |         j        | ||<   n#|j        |                             |          ||<   |r||j                  }|S )as  
    Clip geometry to the polygon/rectangle extent.

    Clip an input GeoDataFrame to the polygon extent of the polygon
    parameter.

    Parameters
    ----------
    gdf : GeoDataFrame, GeoSeries
        Dataframe to clip.

    mask : (Multi)Polygon, list-like
        Reference polygon/rectangle for clipping.

    sort : boolean, default False
        If True, the results will be sorted in ascending order using the
        geometries' indexes as the primary key.

    Returns
    -------
    GeoDataFrame
        The returned GeoDataFrame is a clipped subset of gdf
        that intersects with polygon/rectangle.
    
intersects)	predicatesortPoint)r   r   ilocsindexquery	geom_typeanyr   r   copygeometryvaluesclip_by_rectloc_geometry_column_nameintersectionis_empty)gdfr   r   clipping_by_rectangleintersection_polygongdf_subnon_point_maskclippeds           r   _clip_gdf_with_maskr/   )   s~   2 9>> $"Dz#h
-DQQG
 &'1N  '<(( X,,..  	D '7DdK K(EEFF
  '7DDTJJ K(EEFF
 ,,..  	X&Qgn^&D&QSW&XGN##&-n^&D&Q&QRV&W&WGN# -7++,Nr   c                    t          | t          t          z            st          dt	          |                      t          |          }t          |t          t          z  t          z  t          z            s!|st          dt	          |                     |r"t          |          dk    rt          d          t          |t          t          z            r"t          | |          st          | |d           t          |t          t          z            r|j        }n#|r|}n|j        s|j        nt          j        fdz  }| j        }|d         |d         k    r6|d         |d         k    r$|d	         |d         k    r|d	         |d         k    s| j        d
d         S t          |t          t          z            r|j                                        }n|}t'          | ||          }|rO|j        dk                                    }	| j        dk                                    }
|	o|
 }|
rt-          j        dd           nt1          | j                            t4                                                    | j                            t6                                                    | j                            t8                                                    g          }t1          |j                            t4                                                    |j                            t6                                                    |j                            t8                                                    g          }||k     }|d	k    rt-          j        dd           n|s|r| j        j        d         }|r|                    d          }|t4          v r+|j        |j                            t4                             }n3|t6          v r*|j        |j                            t6                             }|S )as
  Clip points, lines, or polygon geometries to the mask extent.

    Both layers must be in the same Coordinate Reference System (CRS).
    The ``gdf`` will be clipped to the full extent of the clip object.

    If there are multiple polygons in mask, data from ``gdf`` will be
    clipped to the total boundary of all polygons in mask.

    If the ``mask`` is list-like with four elements ``(minx, miny, maxx, maxy)``, a
    faster rectangle clipping algorithm will be used. Note that this can lead to
    slightly different results in edge cases, e.g. if a line would be reduced to a
    point, this point might not be returned.
    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
    ----------
    gdf : GeoDataFrame or GeoSeries
        Vector layer (point, line, polygon) to be clipped to mask.
    mask : GeoDataFrame, GeoSeries, (Multi)Polygon, list-like
        Polygon vector layer used to clip ``gdf``.
        The mask's geometry is dissolved into one geometric feature
        and intersected with ``gdf``.
        If the mask is list-like with four elements ``(minx, miny, maxx, maxy)``,
        ``clip`` will use a faster rectangle clipping (:meth:`~GeoSeries.clip_by_rect`),
        possibly leading to slightly different results.
    keep_geom_type : boolean, default False
        If True, return only geometries of original type in case of intersection
        resulting in multiple geometry types or GeometryCollections.
        If False, return all resulting geometries (potentially mixed-types).
    sort : boolean, default False
        If True, the results will be sorted in ascending order using the
        geometries' indexes as the primary key.

    Returns
    -------
    GeoDataFrame or GeoSeries
         Vector data (points, lines, polygons) from ``gdf`` clipped to
         polygon boundary from mask.

    See Also
    --------
    GeoDataFrame.clip : equivalent GeoDataFrame method
    GeoSeries.clip : equivalent GeoSeries method

    Examples
    --------
    Clip points (grocery stores) with polygons (the Near West Side community):

    >>> import geodatasets
    >>> chicago = geopandas.read_file(
    ...     geodatasets.get_path("geoda.chicago_health")
    ... )
    >>> near_west_side = chicago[chicago["community"] == "NEAR WEST SIDE"]
    >>> groceries = geopandas.read_file(
    ...     geodatasets.get_path("geoda.groceries")
    ... ).to_crs(chicago.crs)
    >>> groceries.shape
    (148, 8)

    >>> nws_groceries = geopandas.clip(groceries, near_west_side)
    >>> nws_groceries.shape
    (7, 8)
    z/'gdf' should be GeoDataFrame or GeoSeries, got zJ'mask' should be GeoDataFrame, GeoSeries,(Multi)Polygon or list-like, got    zIIf 'mask' is list-like, it must have four values (minx, miny, maxx, maxy)   )
stacklevelr         N)r   GeometryCollectionzKkeep_geom_type can not be called on a GeoDataFrame with GeometryCollection.z>keep_geom_type can not be called on a mixed type GeoDataFrame.F)index_parts)r   r   r   	TypeErrortyper   r   r   lenr   r   total_boundsr(   boundsnpnanr   r"   	union_allr/   r   r    warningswarnsumisinr
   r   r	   exploder%   )r)   r   keep_geom_typer   r*   box_maskbox_gdfcombined_maskr.   geomcoll_concatgeomcoll_orignew_collectionorig_types_totalclip_types_total
more_types	orig_types                   r   cliprP   l   s9   B c<)344 WU$s))UUVVV8>>t\I5?,NOO
%
 =04T

= =
 
 	

  
TaW
 
 	
 $y011 8#t$$ 	8sDQ7777$y011 	G$	 G '+mF4;;"&QG
1+
#
#'!**C*CqkWQZ''gajHQK.G.Gx|$y011 //11!#}4@@@G .S",0DDIIKK*>>CCEE(>-> (	SM8      #M&&'9::>>@@M&&77;;==M&&'788<<>>     #%**+=>>BBDD%**?;;??AA%**+;<<@@BB    *,<<J!##T        S: SM.q1	! A%oo%o@@G 222%k'*;*@*@AS*T*TUGG/11%k'*;*@*@*Q*QRGNr   )F)FF)__doc__r@   numpyr=   pandas.api.typesr   shapely.geometryr   r   r   	geopandasr   r   geopandas.arrayr   r	   r
   r   r   r   r/   rP    r   r   <module>rX      s    1 1          7 7 7 7 7 7 7 7 7 7 - - - - - - - -               *@ @ @ @F_ _ _ _ _ _r   