
    Ch%                     z    S r SSKrSSKrSSKrSSKJrJrJ	r	  SSK
JrJr  SSKJrJrJrJrJr  S rS	S jrS
S jrg)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                     [         R                  R                  R                  U 5      =(       a*    [	        U [
        [        -  [        -  [        -  5      (       + $ )at  
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    gC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\geopandas/tools/clip.py_mask_is_list_like_rectangler      sF      ::((. zlY&0<?8 4     c                    [        U5      nU(       a	  [        U6 nOUnU R                  U R                  R	                  USUS9   nUR
                  S:g  nUR                  5       (       d  U$ [        U[        5      (       a  UR                  5       nU(       a?  UR                  R                  U   R                  " U6 UR                  XgR                  4'   OUR                  R                  U   R                  U5      UR                  XgR                  4'   OVUR                  5       nU(       a  UR                  U   R                  " U6 Xv'   O UR                  U   R                  U5      Xv'   U(       a  XwR                   )    nU$ )a+  
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#hh

-DQG
 &&'1N '<((,,.   ''7DDdK KK(E(EEF
   ''7DDTJ KK(E(EEF
 ,,. &-nn^&D&Q&QSW&XG#&-nn^&D&Q&QRV&WG#+++,Nr   c                 X   [        U [        [        -  5      (       d  [        S[	        U 5       35      e[        U5      n[        U[        [        -  [        -  [        -  5      (       d  U(       d  [        S[	        U5       35      eU(       a  [        U5      S:w  a  [        S5      e[        U[        [        -  5      (       a  [        X5      (       d
  [        XSS9  [        U[        [        -  5      (       a  UR                  nO;U(       a  UnO1UR                  (       d  UR                  O[        R                  4S-  nU R                  nUS   US   ::  a$  US   US   ::  a  US	   US   ::  a  US	   US   ::  d  U R                   S
S $ [        U[        [        -  5      (       a  UR"                  R%                  5       nOUn['        XUS9nU(       GaR  UR(                  S:H  R+                  5       n	U R(                  S:H  R+                  5       n
U	=(       a    U
(       + nU
(       a  [,        R.                  " SSS9  U$ [1        U R(                  R3                  [4        5      R+                  5       U R(                  R3                  [6        5      R+                  5       U R(                  R3                  [8        5      R+                  5       /5      n[1        UR(                  R3                  [4        5      R+                  5       UR(                  R3                  [6        5      R+                  5       UR(                  R3                  [8        5      R+                  5       /5      nX:  nUS	:  a  [,        R.                  " SSS9  U$ U(       d  U(       a  U R(                  R                   S   nU(       a  UR;                  SS9nU[4        ;   a.  UR<                  UR(                  R3                  [4        5         nU$ U[6        ;   a,  UR<                  UR(                  R3                  [6        5         nU$ )a	  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   sy   B c<)344I$s)UVV8>t\I5?,NOO%004T
|=
 	

 TaW
 	
 $y011#$$sQ7$y011$$	 '+mm4;;"&&QG
1+
#'!**CqkWQZ'gajHQK.Gxx|$y011//1!#4@G",,0DDIIK*>>CCE(>->MM8R NE  #MM&&'9:>>@MM&&7;;=MM&&'78<<>   #%%**+=>BBD%%**?;??A%%**+;<@@B  *<J!#T  N  :MM..q1	!%oo%o@G 22%kk'*;*;*@*@AS*TUG N /1%kk'*;*;*@*@*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      s6    1    7 7 - *@F_r   