a
    1$eڸ                     @  sL  d dl mZ d dlZd dlZd dlmZmZmZmZ d dlZd dl	Z
d dlZd dlmZmZ d dlmZ d dlmZ d dlZd dlmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZ d dlZddl m!Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z. ej/rd dl0Z0dddddZ1dddZ2G dd deeZ3dS )    )annotationsN)OptionalAnyCallableDict)Series
MultiIndex)SingleBlockManager)CRS)BaseGeometry)GeometryCollection)GeoPandasBase_delegate_propertyplot_series_explore_geoseries   )_compat)doc)GeometryDtypefrom_shapelyfrom_wkbfrom_wktpoints_from_xyto_wkbto_wkt)is_geometry_typeOptional[Any]crsc                 K  sD   zt f | ||d|W S  ty>   tf | |d| Y S 0 dS )z
    A flexible constructor for GeoSeries._constructor, which needs to be able
    to fall back to a Series (if a certain operation does not produce
    geometries)
    )dataindexr    )r!   r"   N)	GeoSeries	TypeErrorr   )r!   r"   r    kwargs r&   O/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopandas/geoseries.py$_geoseries_constructor_with_fallback(   s    r(   c                 O  s   ddl m} tj| g|R i |}d }t| trF| jd urB| jnd}|jd dkr^|jd }|j	dk
 dkr|d u st|| s||}d |_n
||}|S )Nr   GeoDataFramer   geometry)	geopandasr*   pdZ	DataFrame
isinstancer#   nameshapecolumnsZdtypessumr   Z_geometry_column_nameZset_geometry)r!   argsr%   r*   dfZgeo_col_namer&   r&   r'   _geoseries_expanddim6   s    


r5   c                      s  e Zd ZdZdgZdqdd fddZd dd	d
Zed dddZeddddZ	eddddZ
eddddZedd dddZedrdd dddZedsdd dddZedtd dddZeduddd d d!d"Zed#dd$d%Zdvdd&d'd(d)d*Zed+d, Zed-d. Z fd/d0Zd1d2 Zeejd3d4 Zeejd5d6 Zeejd7d8 Zeejdwd:d; fd<d=Zdd fd>d?Zddd@dAZ dd fdBdCZ!dddDdEZ"dxd:dG fdHdIZ#d:ddJdKZ$ee%dLdM Z&ee'dNdO Z(dyd ddPdQZ)dzddRd:d:dSdTdUZ*d{ddRd dVdWdXZ+d|dZd[d\d]d^Z,dZdd_d`Z-d}d:ddadbdcZ.dddddeZ/dfdg Z0dhdi Z1djdk Z2dldm Z3d~d:d dndodpZ4  Z5S )r#   u  
    A Series object designed to store shapely geometry objects.

    Parameters
    ----------
    data : array-like, dict, scalar value
        The geometries to store in the GeoSeries.
    index : array-like or Index
        The index for the GeoSeries.
    crs : value (optional)
        Coordinate Reference System of the geometry objects. Can be anything accepted by
        :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
        such as an authority string (eg "EPSG:4326") or a WKT string.

    kwargs
        Additional arguments passed to the Series constructor,
         e.g. ``name``.

    Examples
    --------

    >>> from shapely.geometry import Point
    >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
    >>> s
    0    POINT (1.00000 1.00000)
    1    POINT (2.00000 2.00000)
    2    POINT (3.00000 3.00000)
    dtype: geometry

    >>> s = geopandas.GeoSeries(
    ...     [Point(1, 1), Point(2, 2), Point(3, 3)], crs="EPSG:3857"
    ... )
    >>> s.crs  # doctest: +SKIP
    <Projected CRS: EPSG:3857>
    Name: WGS 84 / Pseudo-Mercator
    Axis Info [cartesian]:
    - X[east]: Easting (metre)
    - Y[north]: Northing (metre)
    Area of Use:
    - name: World - 85°S to 85°N
    - bounds: (-180.0, -85.06, 180.0, 85.06)
    Coordinate Operation:
    - name: Popular Visualisation Pseudo-Mercator
    - method: Popular Visualisation Pseudo Mercator
    Datum: World Geodetic System 1984
    - Ellipsoid: WGS 84
    - Prime Meridian: Greenwich

    >>> s = geopandas.GeoSeries(
    ...    [Point(1, 1), Point(2, 2), Point(3, 3)], index=["a", "b", "c"], crs=4326
    ... )
    >>> s
    a    POINT (1.00000 1.00000)
    b    POINT (2.00000 2.00000)
    c    POINT (3.00000 3.00000)
    dtype: geometry

    >>> s.crs
    <Geographic 2D CRS: EPSG:4326>
    Name: WGS 84
    Axis Info [ellipsoidal]:
    - Lat[north]: Geodetic latitude (degree)
    - Lon[east]: Geodetic longitude (degree)
    Area of Use:
    - name: World.
    - bounds: (-180.0, -90.0, 180.0, 90.0)
    Datum: World Geodetic System 1984 ensemble
    - Ellipsoid: WGS 84
    - Prime Meridian: Greenwich

    See Also
    --------
    GeoDataFrame
    pandas.Series

    r/   Nr   r   c           	        s  t |dr0|r0|js| }n|j|ks0tdt|trdt|jd jtsdt	d|jd j dt|t
r|d ur~t|nd}|g| }|dd }t|s|dd  t H d	}td
|t td
|t tj|f||d|}W d    n1 s0    Y  |jtkrX|jr0|jdks:|d u rF|t}nt	d|j dzt|j|}W n& t	y   t	d|j dY n0 |j}|j}t j|f||d| | js|| _d S )Nr    zCRS mismatch between CRS of the passed geometries and 'crs'. Use 'GeoSeries.set_crs(crs, allow_override=True)' to overwrite CRS or 'GeoSeries.to_crs(crs)' to reproject geometries. r   zKNon geometry data passed to GeoSeries constructor, received data of dtype ''r   r/   dtypez"The default dtype for empty Seriesignorer"   r/   float64)hasattrr    copy
ValueErrorr.   r	   blocksr7   r   r$   r   lenpopr   compatZignore_shapely2_warningswarningsfilterwarningsDeprecationWarningFutureWarningr-   r   objectemptyZastyper   valuesr"   r/   super__init__)	selfr!   r"   r    r%   nr/   Z	empty_msgs	__class__r&   r'   rJ      s\    







8
zGeoSeries.__init__)returnc                 O  s   | j dg|R i |S )Nappend_wrapped_pandas_methodrK   r3   r%   r&   r&   r'   rQ      s    zGeoSeries.appendc                 C  s   | S Nr&   rK   r&   r&   r'   r+      s    zGeoSeries.geometryr   c                 C  s
   t d| S )a  Return the x location of point geometries in a GeoSeries

        Returns
        -------
        pandas.Series

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s.x
        0    1.0
        1    2.0
        2    3.0
        dtype: float64

        See Also
        --------

        GeoSeries.y
        GeoSeries.z

        xr   rV   r&   r&   r'   rW      s    zGeoSeries.xc                 C  s
   t d| S )a  Return the y location of point geometries in a GeoSeries

        Returns
        -------
        pandas.Series

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s.y
        0    1.0
        1    2.0
        2    3.0
        dtype: float64

        See Also
        --------

        GeoSeries.x
        GeoSeries.z

        yrX   rV   r&   r&   r'   rY     s    zGeoSeries.yc                 C  s
   t d| S )a  Return the z location of point geometries in a GeoSeries

        Returns
        -------
        pandas.Series

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1, 1), Point(2, 2, 2), Point(3, 3, 3)])
        >>> s.z
        0    1.0
        1    2.0
        2    3.0
        dtype: float64

        See Also
        --------

        GeoSeries.x
        GeoSeries.y

        zrX   rV   r&   r&   r'   rZ      s    zGeoSeries.zzos.PathLike | typing.IO)filenamerP   c                 K  s.   ddl m} |j|fi |}t|j|jdS )a  Alternate constructor to create a ``GeoSeries`` from a file.

        Can load a ``GeoSeries`` from a file from any format recognized by
        `fiona`. See http://fiona.readthedocs.io/en/latest/manual.html for details.
        From a file with attributes loads only geometry column. Note that to do
        that, GeoPandas first loads the whole GeoDataFrame.

        Parameters
        ----------
        filename : str
            File path or file handle to read from. Depending on which kwargs
            are included, the content of filename may vary. See
            http://fiona.readthedocs.io/en/latest/README.html#usage for usage details.
        kwargs : key-word arguments
            These arguments are passed to fiona.open, and can be used to
            access multi-layer data, data stored within archives (zip files),
            etc.

        Examples
        --------
        >>> import geodatasets
        >>> path = geodatasets.get_path('nybb')
        >>> s = geopandas.GeoSeries.from_file(path)
        >>> s
        0    MULTIPOLYGON (((970217.022 145643.332, 970227....
        1    MULTIPOLYGON (((1029606.077 156073.814, 102957...
        2    MULTIPOLYGON (((1021176.479 151374.797, 102100...
        3    MULTIPOLYGON (((981219.056 188655.316, 980940....
        4    MULTIPOLYGON (((1012821.806 229228.265, 101278...
        Name: geometry, dtype: geometry

        See Also
        --------
        read_file : read file to GeoDataFrame
        r   r)   r   )r,   r*   	from_filer#   r+   r    )clsr[   r%   r*   r4   r&   r&   r'   r\   <  s    %zGeoSeries.from_file)r    rP   c                 K  s   | j t|f||d|S )a9  
        Alternate constructor to create a ``GeoSeries``
        from a list or array of WKB objects

        Parameters
        ----------
        data : array-like or Series
            Series, list or array of WKB objects
        index : array-like or Index
            The index for the GeoSeries.
        crs : value, optional
            Coordinate Reference System of the geometry objects. Can be anything
            accepted by
            :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        kwargs
            Additional arguments passed to the Series constructor,
            e.g. ``name``.

        Returns
        -------
        GeoSeries

        See Also
        --------
        GeoSeries.from_wkt

        r"   r    )_from_wkb_or_wkbr   r]   r!   r"   r    r%   r&   r&   r'   r   g  s     zGeoSeries.from_wkbc                 K  s   | j t|f||d|S )a  
        Alternate constructor to create a ``GeoSeries``
        from a list or array of WKT objects

        Parameters
        ----------
        data : array-like, Series
            Series, list, or array of WKT objects
        index : array-like or Index
            The index for the GeoSeries.
        crs : value, optional
            Coordinate Reference System of the geometry objects. Can be anything
            accepted by
            :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        kwargs
            Additional arguments passed to the Series constructor,
            e.g. ``name``.

        Returns
        -------
        GeoSeries

        See Also
        --------
        GeoSeries.from_wkb

        Examples
        --------

        >>> wkts = [
        ... 'POINT (1 1)',
        ... 'POINT (2 2)',
        ... 'POINT (3 3)',
        ... ]
        >>> s = geopandas.GeoSeries.from_wkt(wkts)
        >>> s
        0    POINT (1.00000 1.00000)
        1    POINT (2.00000 2.00000)
        2    POINT (3.00000 3.00000)
        dtype: geometry
        r^   )r_   r   r`   r&   r&   r'   r     s    .zGeoSeries.from_wktc                 K  sr   |du rPt |trPt |trP|j|jrP|du sJt |trP|j|jrP|j}| t||||df||d|S )ay  
        Alternate constructor to create a :class:`~geopandas.GeoSeries` of Point
        geometries from lists or arrays of x, y(, z) coordinates

        In case of geographic coordinates, it is assumed that longitude is captured
        by ``x`` coordinates and latitude by ``y``.

        Parameters
        ----------
        x, y, z : iterable
        index : array-like or Index, optional
            The index for the GeoSeries. If not given and all coordinate inputs
            are Series with an equal index, that index is used.
        crs : value, optional
            Coordinate Reference System of the geometry objects. Can be anything
            accepted by
            :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        **kwargs
            Additional arguments passed to the Series constructor,
            e.g. ``name``.

        Returns
        -------
        GeoSeries

        See Also
        --------
        GeoSeries.from_wkt
        points_from_xy

        Examples
        --------

        >>> x = [2.5, 5, -3.0]
        >>> y = [0.5, 1, 1.5]
        >>> s = geopandas.GeoSeries.from_xy(x, y, crs="EPSG:4326")
        >>> s
        0    POINT (2.50000 0.50000)
        1    POINT (5.00000 1.00000)
        2    POINT (-3.00000 1.50000)
        dtype: geometry
        Nr   r^   )r.   r   r"   equalsr   )r]   rW   rY   rZ   r"   r    r%   r&   r&   r'   from_xy  s    -zGeoSeries.from_xyr   )from_wkb_or_wkt_functionr    rP   c                 K  sF   t |tr*|dur||}n|j}|j}| |||dfd|i|S )z0Create a GeoSeries from either WKT or WKB valuesNr   r"   )r.   r   Zreindexr"   rH   )r]   rc   r!   r"   r    r%   r&   r&   r'   r_     s    

zGeoSeries._from_wkb_or_wkbr   c                 C  s   ddl m} |d| ijS )a  Returns a ``GeoSeries`` as a python feature collection.

        Implements the `geo_interface`. The returned python data structure
        represents the ``GeoSeries`` as a GeoJSON-like ``FeatureCollection``.
        Note that the features will have an empty ``properties`` dict as they
        don't have associated attributes (geometry only).

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s.__geo_interface__
        {'type': 'FeatureCollection', 'features': [{'id': '0', 'type': 'Feature', 'properties': {}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 1.0)}, 'bbox': (1.0, 1.0, 1.0, 1.0)}, {'id': '1', 'type': 'Feature', 'properties': {}, 'geometry': {'type': 'Point', 'coordinates': (2.0, 2.0)}, 'bbox': (2.0, 2.0, 2.0, 2.0)}, {'id': '2', 'type': 'Feature', 'properties': {}, 'geometry': {'type': 'Point', 'coordinates': (3.0, 3.0)}, 'bbox': (3.0, 3.0, 3.0, 3.0)}], 'bbox': (1.0, 1.0, 3.0, 3.0)}
        r   r)   r+   )r,   r*   __geo_interface__)rK   r*   r&   r&   r'   rd     s    zGeoSeries.__geo_interface__zOptional[str]zOptional[bool])r[   driverr"   c                 K  sB   ddl m} |d| i| jd}| j|_|j||fd|i| dS )aE  Write the ``GeoSeries`` to a file.

        By default, an ESRI shapefile is written, but any OGR data source
        supported by Fiona can be written.

        Parameters
        ----------
        filename : string
            File path or file handle to write to. The path may specify a
            GDAL VSI scheme.
        driver : string, default None
            The OGR format driver used to write the vector file.
            If not specified, it attempts to infer it from the file extension.
            If no extension is specified, it saves ESRI Shapefile to a folder.
        index : bool, default None
            If True, write index into one or more columns (for MultiIndex).
            Default None writes the index into one or more columns only if
            the index is named, is a MultiIndex, or has a non-integer data
            type. If False, no index is written.

            .. versionadded:: 0.7
                Previously the index was not written.
        mode : string, default 'w'
            The write mode, 'w' to overwrite the existing file and 'a' to append.
            Not all drivers support appending. The drivers that support appending
            are listed in fiona.supported_drivers or
            https://github.com/Toblerity/Fiona/blob/master/fiona/drvsupport.py
        crs : pyproj.CRS, default None
            If specified, the CRS is passed to Fiona to
            better control how the file is written. If None, GeoPandas
            will determine the crs based on crs df attribute.
            The value can be anything accepted
            by :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        engine : str, "fiona" or "pyogrio"
            The underlying library that is used to write the file. Currently, the
            supported options are "fiona" and "pyogrio". Defaults to "fiona" if
            installed, otherwise tries "pyogrio".
        **kwargs :
            Keyword args to be passed to the engine, and can be used to write
            to multi-layer data, store data within archives (zip files), etc.
            In case of the "fiona" engine, the keyword arguments are passed to
            fiona.open`. For more information on possible keywords, type:
            ``import fiona; help(fiona.open)``. In case of the "pyogrio" engine,
            the keyword arguments are passed to `pyogrio.write_dataframe`.

        See Also
        --------
        GeoDataFrame.to_file : write GeoDataFrame to file
        read_file : read file to GeoDataFrame

        Examples
        --------

        >>> s.to_file('series.shp')  # doctest: +SKIP

        >>> s.to_file('series.gpkg', driver='GPKG', layer='name1')  # doctest: +SKIP

        >>> s.to_file('series.geojson', driver='GeoJSON')  # doctest: +SKIP
        r   r)   r+   r"   r"   N)r,   r*   r"   r    to_file)rK   r[   re   r"   r%   r*   r!   r&   r&   r'   rg     s    CzGeoSeries.to_filec                 C  s   t S rU   )r(   rV   r&   r&   r'   _constructorj  s    zGeoSeries._constructorc                 C  s   t S rU   )r5   rV   r&   r&   r'   _constructor_expanddimn  s    z GeoSeries._constructor_expanddimc                   s4   t t ||i |}t|tkr0t|_| j|_|S )z=Wrap a generic pandas method to ensure it returns a GeoSeries)getattrrI   typer   r#   rO   r    )rK   Zmtdr3   r%   valrN   r&   r'   rS   r  s
    z GeoSeries._wrapped_pandas_methodc                 C  s   |  d|S )N__getitem__rR   )rK   keyr&   r&   r'   rm   z  s    zGeoSeries.__getitem__c                 O  s   | j dg|R i |S )N
sort_indexrR   rT   r&   r&   r'   ro   }  s    zGeoSeries.sort_indexc                 O  s   | j dg|R i |S )NtakerR   rT   r&   r&   r'   rp     s    zGeoSeries.takec                 O  s   | j dg|R i |S )NselectrR   rT   r&   r&   r'   rq     s    zGeoSeries.selectr&   bool)convert_dtypec                   s`   |d ur||d< nt js d|d< t j|fd|i|}t|tr\| jd ur\|j| jdd |S )Nrs   Tr3   inplace)rA   ZPANDAS_GE_21rI   applyr.   r#   r    set_crs)rK   funcrs   r3   r%   resultrN   r&   r'   rv     s    


zGeoSeries.applyc                   s
   t   S )a  
        Detect missing values.

        Historically, NA values in a GeoSeries could be represented by
        empty geometric objects, in addition to standard representations
        such as None and np.nan. This behaviour is changed in version 0.6.0,
        and now only actual missing values return True. To detect empty
        geometries, use ``GeoSeries.is_empty`` instead.

        Returns
        -------
        A boolean pandas Series of the same size as the GeoSeries,
        True where a value is NA.

        Examples
        --------

        >>> from shapely.geometry import Polygon
        >>> s = geopandas.GeoSeries(
        ...     [Polygon([(0, 0), (1, 1), (0, 1)]), None, Polygon([])]
        ... )
        >>> s
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1                                                 None
        2                                        POLYGON EMPTY
        dtype: geometry
        >>> s.isna()
        0    False
        1     True
        2    False
        dtype: bool

        See Also
        --------
        GeoSeries.notna : inverse of isna
        GeoSeries.is_empty : detect empty geometries
        )rI   isnarV   rN   r&   r'   rz     s    &zGeoSeries.isnac                 C  s   |   S )z4Alias for `isna` method. See `isna` for more detail.)rz   rV   r&   r&   r'   isnull  s    zGeoSeries.isnullc                   s$   | j  rtjdtdd t  S )a  
        Detect non-missing values.

        Historically, NA values in a GeoSeries could be represented by
        empty geometric objects, in addition to standard representations
        such as None and np.nan. This behaviour is changed in version 0.6.0,
        and now only actual missing values return False. To detect empty
        geometries, use ``~GeoSeries.is_empty`` instead.

        Returns
        -------
        A boolean pandas Series of the same size as the GeoSeries,
        False where a value is NA.

        Examples
        --------

        >>> from shapely.geometry import Polygon
        >>> s = geopandas.GeoSeries(
        ...     [Polygon([(0, 0), (1, 1), (0, 1)]), None, Polygon([])]
        ... )
        >>> s
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1                                                 None
        2                                        POLYGON EMPTY
        dtype: geometry
        >>> s.notna()
        0     True
        1    False
        2     True
        dtype: bool

        See Also
        --------
        GeoSeries.isna : inverse of notna
        GeoSeries.is_empty : detect empty geometries
        a  GeoSeries.notna() previously returned False for both missing (None) and empty geometries. Now, it only returns False for missing values. Since the calling GeoSeries contains empty geometries, the result has changed compared to previous versions of GeoPandas.
Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get back the old behaviour.

To further ignore this warning, you can do: 
import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)   
stacklevel)Zis_emptyanyrB   warnUserWarningrI   notnarV   rN   r&   r'   r     s    &
	zGeoSeries.notnac                 C  s   |   S )z6Alias for `notna` method. See `notna` for more detail.)r   rV   r&   r&   r'   notnull  s    zGeoSeries.notnullFrt   c                   s4   |du rt jrt nt }t jf |||d|S )a	  
        Fill NA values with geometry (or geometries).

        ``method`` is currently not implemented.

        Parameters
        ----------
        value : shapely geometry or GeoSeries, default None
            If None is passed, NA values will be filled with GEOMETRYCOLLECTION EMPTY.
            If a shapely geometry object is passed, it will be
            used to fill all missing values. If a ``GeoSeries`` or ``GeometryArray``
            are passed, missing values will be filled based on the corresponding index
            locations. If pd.NA or np.nan are passed, values will be filled with
            ``None`` (not GEOMETRYCOLLECTION EMPTY).

        Returns
        -------
        GeoSeries

        Examples
        --------
        >>> from shapely.geometry import Polygon
        >>> s = geopandas.GeoSeries(
        ...     [
        ...         Polygon([(0, 0), (1, 1), (0, 1)]),
        ...         None,
        ...         Polygon([(0, 0), (-1, 1), (0, -1)]),
        ...     ]
        ... )
        >>> s
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1                                                 None
        2    POLYGON ((0.00000 0.00000, -1.00000 1.00000, 0...
        dtype: geometry

        Filled with an empty polygon.

        >>> s.fillna()
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1                             GEOMETRYCOLLECTION EMPTY
        2    POLYGON ((0.00000 0.00000, -1.00000 1.00000, 0...
        dtype: geometry

        Filled with a specific polygon.

        >>> s.fillna(Polygon([(0, 1), (2, 1), (1, 2)]))
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1    POLYGON ((0.00000 1.00000, 2.00000 1.00000, 1....
        2    POLYGON ((0.00000 0.00000, -1.00000 1.00000, 0...
        dtype: geometry

        Filled with another GeoSeries.

        >>> from shapely.geometry import Point
        >>> s_fill = geopandas.GeoSeries(
        ...     [
        ...         Point(0, 0),
        ...         Point(1, 1),
        ...         Point(2, 2),
        ...     ]
        ... )
        >>> s.fillna(s_fill)
        0    POLYGON ((0.00000 0.00000, 1.00000 1.00000, 0....
        1                              POINT (1.00000 1.00000)
        2    POLYGON ((0.00000 0.00000, -1.00000 1.00000, 0...
        dtype: geometry

        See Also
        --------
        GeoSeries.isna : detect missing values
        N)valuemethodru   )rA   ZSHAPELY_GE_20r   r   rI   fillna)rK   r   r   ru   r%   rN   r&   r'   r      s    HzGeoSeries.fillnac                 C  s"   t |trt| |S dS dS )zAllow tests of the form "geom in s"

        Tests whether a GeoSeries contains a geometry.

        Note: This is not the same as the geometric method "contains".
        FN)r.   r   npr   Zgeom_equalsrK   otherr&   r&   r'   __contains__L  s    
zGeoSeries.__contains__c                 O  s   t | g|R i |S rU   r   rT   r&   r&   r'   plotX  s    zGeoSeries.plotc                 O  s   t | g|R i |S )z*Interactive map based on folium/leaflet.jsr   rT   r&   r&   r'   explore\  s    zGeoSeries.explorec                   s  ddl m} |du r,|s,tjdtdd d}tjs>tjrtjrtjr\t	j
| jjdd\}}nd	dl}|j
| jjdd\}}|| j|||d
}t||| jd| S g }g }| j D ]d\ }|jds|jdkr|j}	 fddtt|	D }
n|g}	 d	fg}
||
 ||	 q|r.tt|}nJ|rjt| jtrPdd |D }tj|| jjdg d}ndd |D }t||| jd| S )u  
        Explode multi-part geometries into multiple single geometries.

        Single rows can become multiple rows.
        This is analogous to PostGIS's ST_Dump(). The 'path' index is the
        second level of the returned MultiIndex

        Parameters
        ----------
        ignore_index : bool, default False
            If True, the resulting index will be labelled 0, 1, …, n - 1,
            ignoring `index_parts`.
        index_parts : boolean, default True
            If True, the resulting index will be a multi-index (original
            index with an additional level indicating the multiple
            geometries: a new zero-based index for each single part geometry
            per multi-part geometry).

        Returns
        -------
        A GeoSeries with a MultiIndex. The levels of the MultiIndex are the
        original index and a zero-based integer index that counts the
        number of single geometries within a multi-part geometry.

        Examples
        --------
        >>> from shapely.geometry import MultiPoint
        >>> s = geopandas.GeoSeries(
        ...     [MultiPoint([(0, 0), (1, 1)]), MultiPoint([(2, 2), (3, 3), (4, 4)])]
        ... )
        >>> s
        0        MULTIPOINT (0.00000 0.00000, 1.00000 1.00000)
        1    MULTIPOINT (2.00000 2.00000, 3.00000 3.00000, ...
        dtype: geometry

        >>> s.explode(index_parts=True)
        0  0    POINT (0.00000 0.00000)
           1    POINT (1.00000 1.00000)
        1  0    POINT (2.00000 2.00000)
           1    POINT (3.00000 3.00000)
           2    POINT (4.00000 4.00000)
        dtype: geometry

        See also
        --------
        GeoDataFrame.explode

        r   )_get_index_for_partsNzCurrently, index_parts defaults to True, but in the future, it will default to False to be consistent with Pandas. Use `index_parts=True` to keep the current behavior and True/False to silence the warning.r|   r}   T)Zreturn_indexr   )ignore_indexindex_partsr^   ZMultir   c                   s   g | ]} |fqS r&   r&   ).0iidxr&   r'   
<listcomp>      z%GeoSeries.explode.<locals>.<listcomp>c                 S  s   g | ]\}}t ||f qS r&   )tuple)r   outerinnerr&   r&   r'   r     r   )namesc                 S  s   g | ]\}}|qS r&   r&   )r   r   _r&   r&   r'   r     r   )baser   rB   r   rE   rA   ZUSE_SHAPELY_20Z
USE_PYGEOSZPYGEOS_GE_09shapely	get_partsrH   _datapygeosr"   r#   r    Z__finalize__r+   itemsZ	geom_type
startswithgeomsranger?   extendr.   r   from_tuplesr   )rK   r   r   r   Z
geometriesZ	outer_idxr   r"   rM   r   idxsr&   r   r'   explodea  sT    1


zGeoSeries.explodezOptional[int])r    epsgru   allow_overridec                 C  sl   |durt |}n|dur(t |}ntd|sP| jdurP| j|ksPtd|s^|  }n| }||_|S )u7	  
        Set the Coordinate Reference System (CRS) of a ``GeoSeries``.

        NOTE: The underlying geometries are not transformed to this CRS. To
        transform the geometries to a new CRS, use the ``to_crs`` method.

        Parameters
        ----------
        crs : pyproj.CRS, optional if `epsg` is specified
            The value can be anything accepted
            by :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        epsg : int, optional if `crs` is specified
            EPSG code specifying the projection.
        inplace : bool, default False
            If True, the CRS of the GeoSeries will be changed in place
            (while still returning the result) instead of making a copy of
            the GeoSeries.
        allow_override : bool, default False
            If the the GeoSeries already has a CRS, allow to replace the
            existing CRS, even when both are not equal.

        Returns
        -------
        GeoSeries

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s
        0    POINT (1.00000 1.00000)
        1    POINT (2.00000 2.00000)
        2    POINT (3.00000 3.00000)
        dtype: geometry

        Setting CRS to a GeoSeries without one:

        >>> s.crs is None
        True

        >>> s = s.set_crs('epsg:3857')
        >>> s.crs  # doctest: +SKIP
        <Projected CRS: EPSG:3857>
        Name: WGS 84 / Pseudo-Mercator
        Axis Info [cartesian]:
        - X[east]: Easting (metre)
        - Y[north]: Northing (metre)
        Area of Use:
        - name: World - 85°S to 85°N
        - bounds: (-180.0, -85.06, 180.0, 85.06)
        Coordinate Operation:
        - name: Popular Visualisation Pseudo-Mercator
        - method: Popular Visualisation Pseudo Mercator
        Datum: World Geodetic System 1984
        - Ellipsoid: WGS 84
        - Prime Meridian: Greenwich

        Overriding existing CRS:

        >>> s = s.set_crs(4326, allow_override=True)

        Without ``allow_override=True``, ``set_crs`` returns an error if you try to
        override CRS.

        See Also
        --------
        GeoSeries.to_crs : re-project to another CRS

        NzMust pass either crs or epsg.zThe GeoSeries already has a CRS which is not equal to the passed CRS. Specify 'allow_override=True' to allow replacing the existing CRS without doing any transformation. If you actually want to transform the geometries, use 'GeoSeries.to_crs' instead.)r
   Zfrom_user_inputZ	from_epsgr=   r    r<   )rK   r    r   ru   r   ry   r&   r&   r'   rw     s    M
zGeoSeries.set_crs)r    r   rP   c                 C  s   t | jj||d| j| jdS )u
  Returns a ``GeoSeries`` with all geometries transformed to a new
        coordinate reference system.

        Transform all geometries in a GeoSeries to a different coordinate
        reference system.  The ``crs`` attribute on the current GeoSeries must
        be set.  Either ``crs`` or ``epsg`` may be specified for output.

        This method will transform all points in all objects.  It has no notion
        of projecting entire geometries.  All segments joining points are
        assumed to be lines in the current projection, not geodesics.  Objects
        crossing the dateline (or other projection boundary) will have
        undesirable behavior.

        Parameters
        ----------
        crs : pyproj.CRS, optional if `epsg` is specified
            The value can be anything accepted
            by :meth:`pyproj.CRS.from_user_input() <pyproj.crs.CRS.from_user_input>`,
            such as an authority string (eg "EPSG:4326") or a WKT string.
        epsg : int, optional if `crs` is specified
            EPSG code specifying output projection.

        Returns
        -------
        GeoSeries

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)], crs=4326)
        >>> s
        0    POINT (1.00000 1.00000)
        1    POINT (2.00000 2.00000)
        2    POINT (3.00000 3.00000)
        dtype: geometry
        >>> s.crs  # doctest: +SKIP
        <Geographic 2D CRS: EPSG:4326>
        Name: WGS 84
        Axis Info [ellipsoidal]:
        - Lat[north]: Geodetic latitude (degree)
        - Lon[east]: Geodetic longitude (degree)
        Area of Use:
        - name: World
        - bounds: (-180.0, -90.0, 180.0, 90.0)
        Datum: World Geodetic System 1984
        - Ellipsoid: WGS 84
        - Prime Meridian: Greenwich

        >>> s = s.to_crs(3857)
        >>> s
        0    POINT (111319.491 111325.143)
        1    POINT (222638.982 222684.209)
        2    POINT (333958.472 334111.171)
        dtype: geometry
        >>> s.crs  # doctest: +SKIP
        <Projected CRS: EPSG:3857>
        Name: WGS 84 / Pseudo-Mercator
        Axis Info [cartesian]:
        - X[east]: Easting (metre)
        - Y[north]: Northing (metre)
        Area of Use:
        - name: World - 85°S to 85°N
        - bounds: (-180.0, -85.06, 180.0, 85.06)
        Coordinate Operation:
        - name: Popular Visualisation Pseudo-Mercator
        - method: Popular Visualisation Pseudo Mercator
        Datum: World Geodetic System 1984
        - Ellipsoid: WGS 84
        - Prime Meridian: Greenwich

        See Also
        --------
        GeoSeries.set_crs : assign CRS

        )r    r   r9   )r#   rH   to_crsr"   r/   )rK   r    r   r&   r&   r'   r   6  s    NzGeoSeries.to_crsWGS 84strr
   )
datum_namerP   c                 C  s   | j |S )uI  Returns the estimated UTM CRS based on the bounds of the dataset.

        .. versionadded:: 0.9

        Parameters
        ----------
        datum_name : str, optional
            The name of the datum to use in the query. Default is WGS 84.

        Returns
        -------
        pyproj.CRS

        Examples
        --------
        >>> import geodatasets
        >>> df = geopandas.read_file(
        ...     geodatasets.get_path("geoda.chicago_health")
        ... )
        >>> df.geometry.estimate_utm_crs()  # doctest: +SKIP
        <Derived Projected CRS: EPSG:32616>
        Name: WGS 84 / UTM zone 16N
        Axis Info [cartesian]:
        - E[east]: Easting (metre)
        - N[north]: Northing (metre)
        Area of Use:
        - name: Between 90°W and 84°W, northern hemisphere between equator and 84°N, ...
        - bounds: (-90.0, 0.0, -84.0, 84.0)
        Coordinate Operation:
        - name: UTM zone 16N
        - method: Transverse Mercator
        Datum: World Geodetic System 1984 ensemble
        - Ellipsoid: WGS 84
        - Prime Meridian: Greenwich
        )rH   estimate_utm_crs)rK   r   r&   r&   r'   r     s    $zGeoSeries.estimate_utm_crsc                 K  s   t j| jfi |S )as  
        Returns a GeoJSON string representation of the GeoSeries.

        Parameters
        ----------
        *kwargs* that will be passed to json.dumps().

        Returns
        -------
        JSON string

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s
        0    POINT (1.00000 1.00000)
        1    POINT (2.00000 2.00000)
        2    POINT (3.00000 3.00000)
        dtype: geometry

        >>> s.to_json()
        '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [1.0, 1.0]}, "bbox": [1.0, 1.0, 1.0, 1.0]}, {"id": "1", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [2.0, 2.0]}, "bbox": [2.0, 2.0, 2.0, 2.0]}, {"id": "2", "type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [3.0, 3.0]}, "bbox": [3.0, 3.0, 3.0, 3.0]}], "bbox": [1.0, 1.0, 3.0, 3.0]}'

        See Also
        --------
        GeoSeries.to_file : write GeoSeries to file
        )jsondumpsrd   rK   r%   r&   r&   r'   to_json  s    "zGeoSeries.to_json)hexrP   c                 K  s    t t| jfd|i|| jdS )aH  
        Convert GeoSeries geometries to WKB

        Parameters
        ----------
        hex : bool
            If true, export the WKB as a hexadecimal string.
            The default is to return a binary bytes object.
        kwargs
            Additional keyword args will be passed to
            :func:`shapely.to_wkb` if shapely >= 2 is installed or
            :func:`pygeos.to_wkb` if pygeos is installed.

        Returns
        -------
        Series
            WKB representations of the geometries

        See also
        --------
        GeoSeries.to_wkt
        r   rf   )r   r   arrayr"   )rK   r   r%   r&   r&   r'   r     s    zGeoSeries.to_wkbc                 K  s   t t| jfi || jdS )a  
        Convert GeoSeries geometries to WKT

        Parameters
        ----------
        kwargs
            Keyword args will be passed to :func:`pygeos.to_wkt`
            if pygeos is installed.

        Returns
        -------
        Series
            WKT representations of the geometries

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
        >>> s
        0    POINT (1.00000 1.00000)
        1    POINT (2.00000 2.00000)
        2    POINT (3.00000 3.00000)
        dtype: geometry

        >>> s.to_wkt()
        0    POINT (1 1)
        1    POINT (2 2)
        2    POINT (3 3)
        dtype: object

        See also
        --------
        GeoSeries.to_wkb
        rf   )r   r   r   r"   r   r&   r&   r'   r     s    #zGeoSeries.to_wktc                 C  s   t jdtdd | |S )z,Implement ^ operator as for builtin set typezO'^' operator will be deprecated. Use the 'symmetric_difference' method instead.r|   r}   )rB   r   rE   symmetric_differencer   r&   r&   r'   __xor__  s    zGeoSeries.__xor__c                 C  s   t jdtdd | |S )z,Implement | operator as for builtin set typez@'|' operator will be deprecated. Use the 'union' method instead.r|   r}   )rB   r   rE   unionr   r&   r&   r'   __or__  s    zGeoSeries.__or__c                 C  s   t jdtdd | |S )z,Implement & operator as for builtin set typezG'&' operator will be deprecated. Use the 'intersection' method instead.r|   r}   )rB   r   rE   intersectionr   r&   r&   r'   __and__'  s    zGeoSeries.__and__c                 C  s   t jdtdd | |S )z,Implement - operator as for builtin set typezE'-' operator will be deprecated. Use the 'difference' method instead.r|   r}   )rB   r   rE   
differencer   r&   r&   r'   __sub__0  s    zGeoSeries.__sub__)keep_geom_typerP   c                 C  s   t j| ||dS )a  Clip points, lines, or polygon geometries to the mask extent.

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

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

        Parameters
        ----------
        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 GeoSeries.
            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).

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

        See also
        --------
        clip : top-level function for clip

        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 = groceries.geometry.clip(near_west_side)
        >>> nws_groceries.shape
        (7,)
        )maskr   )r,   clip)rK   r   r   r&   r&   r'   r   9  s    5zGeoSeries.clip)NNN)NN)NN)NNN)NN)NN)Nr&   )NNF)FN)NNFF)NN)r   )F)F)6__name__
__module____qualname____doc__	_metadatarJ   rQ   propertyr+   rW   rY   rZ   classmethodr\   r   r   rb   r_   rd   rg   rh   ri   rS   rm   r   r-   r   ro   rp   rq   rv   rz   r{   r   r   r   r   r   r   r   r   r   rw   r   r   r   r   r   r   r   r   r   r   __classcell__r&   r&   rN   r'   r#   M   s   MD* ! /6    M




(6L

u    c R&$)
			r#   )NNN)N)4
__future__r   r   typingr   r   r   r   rB   numpyr   Zpandasr-   r   r   Zpandas.core.internalsr	   Zpyprojr
   r   Zshapely.geometry.baser   Zshapely.geometryr   Zgeopandas.baser   r   Zgeopandas.plottingr   Zgeopandas.explorer   r,    r   rA   Z
_decoratorr   r   r   r   r   r   r   r   r   r   r   TYPE_CHECKINGosr(   r5   r#   r&   r&   r&   r'   <module>   s4   $	 
