a
    1$ew                    @   s  d dl Z d dl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mZ d dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZ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& dd Z'dddZ(dZ)G dd deeZ*dddZ+e+e_,dS )    N)	DataFrameSeries)CachedAccessor)mappingshape)BaseGeometry)CRS)GeometryArrayGeometryDtypefrom_shapelyto_wkbto_wkt)GeoPandasBaseis_geometry_type)	GeoSeries_explore   )_compat)docc                  O   s>   t | i |}|jdk}t|dks0| dkr:t|}|S )z
    A flexible constructor for GeoDataFrame._constructor, which falls back
    to returning a DataFrame (if a certain operation does not preserve the
    geometry column)
    geometryr   )GeoDataFramedtypeslensumpdr   )argskwargsdfZgeometry_cols_mask r   R/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopandas/geodataframe.py'_geodataframe_constructor_with_fallback   s
    

r!   c                 C   s   t | r>t| trt| } | jdu r:|dur:|  } || _| S t| trltt| |d}t|| j	| j
dS t| |d}|S dS )z
    Ensure the data is of geometry dtype or converted to it.

    If input is a (Geo)Series, output is a GeoSeries, otherwise output
    is GeometryArray.

    If the input is a GeometryDtype with a set CRS, `crs` is ignored.
    Ncrs)indexname)r   
isinstancer   r   r#   copyr   npZasarrayr$   r%   )datar#   outr   r   r    _ensure_geometry&   s    	

r+   zCRS mismatch between CRS of the passed geometries and 'crs'. Use 'GeoDataFrame.set_crs(crs, allow_override=True)' to overwrite CRS or 'GeoDataFrame.to_crs(crs)' to reproject geometries. c                       sv  e Zd ZdZdgZejdg ZeeZdZ	dwddd fddZ
 fdd	Zd
d Zdd ZeeeddZdxddZdyddZedd Zejdd Z fddZedzddZedd Zed{ddZed|d"d#Zd}d%d&Zed'd( Zd~d)d*Zd+d, Zdd-d.Zd/d0 Zdd2d3Z dd4d5Z!dd6d7Z"dd8d9Z#dd:d;Z$dd=d>Z% fd?d@Z&dAdB Z' fdCdDZ(e)e*jd fdEdF	Z+dGdH Z,e)e*jd fdKdL	Z-edMdN Z.edOdP Z/d fdQdR	Z0ddTdUZ1d fdVdW	Z2d fdYdZ	Z3 fd[d\Z4dd^d_Z5d`da Z6dbdc Z7ddde Z8dfdg Z9e:dhe;j<j=Z>e)e?didj Z@dkdl ZAddpdqZBddrdsZCddudvZD  ZES )r   a  
    A GeoDataFrame object is a pandas.DataFrame that has a column
    with geometry. In addition to the standard DataFrame constructor arguments,
    GeoDataFrame also accepts the following keyword arguments:

    Parameters
    ----------
    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.
    geometry : str or array (optional)
        If str, column to use as geometry. If array, will be set as 'geometry'
        column on GeoDataFrame.

    Examples
    --------
    Constructing GeoDataFrame from a dictionary.

    >>> from shapely.geometry import Point
    >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
    >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326")
    >>> gdf
        col1                 geometry
    0  name1  POINT (1.00000 2.00000)
    1  name2  POINT (2.00000 1.00000)

    Notice that the inferred dtype of 'geometry' columns is geometry.

    >>> gdf.dtypes
    col1          object
    geometry    geometry
    dtype: object

    Constructing GeoDataFrame from a pandas DataFrame with a column of WKT geometries:

    >>> import pandas as pd
    >>> d = {'col1': ['name1', 'name2'], 'wkt': ['POINT (1 2)', 'POINT (2 1)']}
    >>> df = pd.DataFrame(d)
    >>> gs = geopandas.GeoSeries.from_wkt(df['wkt'])
    >>> gdf = geopandas.GeoDataFrame(df, geometry=gs, crs="EPSG:4326")
    >>> gdf
        col1          wkt                 geometry
    0  name1  POINT (1 2)  POINT (1.00000 2.00000)
    1  name2  POINT (2 1)  POINT (2.00000 1.00000)

    See also
    --------
    GeoSeries : Series object designed to store shapely geometry objects
    _geometry_column_namer   Nr   r#   c                   s  t  X |dd u r8t|tr8t|ts8|jdd t j|g|R i | W d    n1 sf0    Y  |d u rt|tr|j	| _	|d ur|j
|krtt|d u rT| jjdkrTd| jv rT| jdk dkrtdzXt| d jdr$| d jj
r$|r$| d jj
|ks$ttt| d j|| d< W n tyN   Y n0 d}|d urt|dr|j
r|r|j
|kstt| j|d|d |d u r|rtd	d S )
Nr'   Tr'   r   r   zYGeoDataFrame does not support multiple columns using the geometry column name 'geometry'.r#   )inplacer#   zAssigning CRS to a GeoDataFrame without a geometry column is not supported. Supply geometry using the 'geometry=' keyword argument, or by providing a DataFrame with column name 'geometry')compatZignore_shapely2_warningsgetr&   r   r   updatesuper__init__r,   r#   
ValueErrorcrs_mismatch_errorcolumnsnlevelsr   hasattrvaluesr+   	TypeErrorset_geometry)selfr)   r   r#   r   r   	__class__r   r    r4      sh    
8



zGeoDataFrame.__init__c                    s*   |dkrt | || nt || d S )Nr   )object__setattr__r3   )r=   attrvalr>   r   r    rA      s    zGeoDataFrame.__setattr__c                 C   st   | j | vrj| j d u rd}nd| j  d}t| j| jdk }t|dkrZ|d| d7 }n|d7 }t|| | j  S )	NzqYou are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set. zZYou are calling a geospatial method on the GeoDataFrame, but the active geometry column ('z') is not present. r   r   z,
There are columns with geometry data type (z), and you can either set one as the active geometry with df.set_geometry("name") or access the column as a GeoSeries (df["name"]) and call the method directly on it.z
There are no existing columns with geometry data type. You can add a geometry column as the active geometry column with df.set_geometry. )r,   listr7   r   r   AttributeError)r=   msgZgeo_colsr   r   r    _get_geometry   s$    


zGeoDataFrame._get_geometryc                 C   s0   t jj|std|   | j|dd d S )Nz1Must use a list-like to set the geometry propertyTr/   )r   apitypesis_list_liker5   %_persist_old_default_geometry_colnamer<   )r=   colr   r   r    _set_geometry   s    zGeoDataFrame._set_geometryzGeometry data for GeoDataFrame)fgetfsetr   Fc           	      C   s&  |r
| }n|   }d}| j}|du r(d}t|tttjtfrB|}n|t|dr`|j	dkr`t
dn^z|| }W n0 ty   t
d| Y n ty    Y n0 t|trt
d|r|}n|}|r||= |st|dd}t|ttfr|j|kr|  }||_t||d	}||_|||< |s"|S dS )
a  
        Set the GeoDataFrame geometry using either an existing column or
        the specified input. By default yields a new object.

        The original geometry column is replaced with the input.

        Parameters
        ----------
        col : column label or array
        drop : boolean, default False
            Delete column to be used as the new geometry
        inplace : boolean, default False
            Modify the GeoDataFrame in place (do not create a new object)
        crs : pyproj.CRS, optional
            Coordinate system to use. 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.
            If passed, overrides both DataFrame and col's crs.
            Otherwise, tries to get crs from passed col values or DataFrame.

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326")
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)

        Passing an array:

        >>> df1 = gdf.set_geometry([Point(0,0), Point(1,1)])
        >>> df1
            col1                 geometry
        0  name1  POINT (0.00000 0.00000)
        1  name2  POINT (1.00000 1.00000)

        Using existing column:

        >>> gdf["buffered"] = gdf.buffer(2)
        >>> df2 = gdf.set_geometry("buffered")
        >>> df2.geometry
        0    POLYGON ((3.00000 2.00000, 2.99037 1.80397, 2....
        1    POLYGON ((4.00000 1.00000, 3.99037 0.80397, 3....
        Name: buffered, dtype: geometry

        Returns
        -------
        GeoDataFrame

        See also
        --------
        GeoDataFrame.rename_geometry : rename an active geometry column
        Nr   ndimr   z(Must pass array with one dimension only.zUnknown column %sznGeoDataFrame does not support setting the geometry column where the column name is shared by multiple columns.r#   r"   )r'   r,   r&   r   rD   r(   Zndarrayr	   r9   rQ   r5   KeyError	Exceptionr   getattrr   r#   r+   )	r=   rM   dropr/   r#   frame	to_removeZgeo_column_namelevelr   r   r    r<      sH    9

zGeoDataFrame.set_geometryc                 C   sd   | j j}|| jv r$td| dn<|s@| j||id||S | j||i|d | j||d dS )a  
        Renames the GeoDataFrame geometry column to
        the specified name. By default yields a new object.

        The original geometry column is replaced with the input.

        Parameters
        ----------
        col : new geometry column label
        inplace : boolean, default False
            Modify the GeoDataFrame in place (do not create a new object)

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> df = geopandas.GeoDataFrame(d, crs="EPSG:4326")
        >>> df1 = df.rename_geometry('geom1')
        >>> df1.geometry.name
        'geom1'
        >>> df.rename_geometry('geom1', inplace=True)
        >>> df.geometry.name
        'geom1'

        Returns
        -------
        geodataframe : GeoDataFrame

        See also
        --------
        GeoDataFrame.set_geometry : set the active geometry
        zColumn named z already exists)r7   )r7   r/   rH   N)r   r%   r7   r5   renamer<   )r=   rM   r/   Zgeometry_colr   r   r    rename_geometryf  s    !
zGeoDataFrame.rename_geometryc                 C   s*   z
| j jW S  ty$   tdY n0 dS )a  
        The Coordinate Reference System (CRS) represented as a ``pyproj.CRS``
        object.

        Returns None if the CRS is not set, and to set the value it
        :getter: Returns a ``pyproj.CRS`` or None. When setting, 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.

        Examples
        --------

        >>> gdf.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

        See also
        --------
        GeoDataFrame.set_crs : assign CRS
        GeoDataFrame.to_crs : re-project to another CRS

        zThe CRS attribute of a GeoDataFrame without an active geometry column is not defined. Use GeoDataFrame.set_geometry to set the active geometry column.N)r   r#   rE   r=   r   r   r    r#     s    "
zGeoDataFrame.crsc                 C   s8   | j du rtdt| jjdr,|| jj_ntddS )zSets the value of the crsNzAssigning CRS to a GeoDataFrame without a geometry column is not supported. Use GeoDataFrame.set_geometry to set the active geometry column.r#   zAssigning CRS to a GeoDataFrame without an active geometry column is not supported. Use GeoDataFrame.set_geometry to set the active geometry column.)r,   r5   r9   r   r:   r#   )r=   valuer   r   r    r#     s    
c                    s   d }t |trNd|v r,d|vr,|dd }n|dd }|d urJt|n|}t | z |d urx| jjj	d u rx|| _	W n t
y   Y n0 d S )Nr#   _crs)r&   dictpopr   Zfrom_user_inputr3   __setstate__r   r:   r#   rS   )r=   stater#   r>   r   r    r`     s    

zGeoDataFrame.__setstate__c                 K   s    t j|fi |}| |||dS )a  
        Construct GeoDataFrame from dict of array-like or dicts by
        overriding DataFrame.from_dict method with geometry and crs

        Parameters
        ----------
        data : dict
            Of the form {field : array-like} or {field : dict}.
        geometry : str or array (optional)
            If str, column to use as geometry. If array, will be set as 'geometry'
            column on GeoDataFrame.
        crs : str or dict (optional)
            Coordinate reference system to set on the resulting frame.
        kwargs : key-word arguments
            These arguments are passed to DataFrame.from_dict

        Returns
        -------
        GeoDataFrame

        r-   )r   	from_dict)clsr)   r   r#   r   Z	dataframer   r   r    rb     s    zGeoDataFrame.from_dictc                 K   s   t jjj|fi |S )a  Alternate constructor to create a ``GeoDataFrame`` from a file.

        It is recommended to use :func:`geopandas.read_file` instead.

        Can load a ``GeoDataFrame`` from a file in any format recognized by
        `fiona`. See http://fiona.readthedocs.io/en/latest/manual.html for details.

        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')
        >>> gdf = geopandas.GeoDataFrame.from_file(path)
        >>> gdf  # doctest: +SKIP
           BoroCode       BoroName     Shape_Leng    Shape_Area                                           geometry
        0         5  Staten Island  330470.010332  1.623820e+09  MULTIPOLYGON (((970217.022 145643.332, 970227....
        1         4         Queens  896344.047763  3.045213e+09  MULTIPOLYGON (((1029606.077 156073.814, 102957...
        2         3       Brooklyn  741080.523166  1.937479e+09  MULTIPOLYGON (((1021176.479 151374.797, 102100...
        3         1      Manhattan  359299.096471  6.364715e+08  MULTIPOLYGON (((981219.056 188655.316, 980940....
        4         2          Bronx  464392.991824  1.186925e+09  MULTIPOLYGON (((1012821.806 229228.265, 101278...

        The recommended method of reading files is :func:`geopandas.read_file`:

        >>> gdf = geopandas.read_file(path)

        See also
        --------
        read_file : read file to GeoDataFame
        GeoDataFrame.to_file : write GeoDataFrame to file

        )	geopandasiofileZ
_read_file)rc   filenamer   r   r   r    	from_file  s    1zGeoDataFrame.from_filec           
      C   s   t |dr|j}n|}t|tr8|ddkr8|d }n|}g }|D ]X}t |drX|j}d|d rnt|d ndi}|d }	|	du ri }	||	 || qD| |||dS )	ac  
        Alternate constructor to create GeoDataFrame from an iterable of
        features or a feature collection.

        Parameters
        ----------
        features
            - Iterable of features, where each element must be a feature
              dictionary or implement the __geo_interface__.
            - Feature collection, where the 'features' key contains an
              iterable of features.
            - Object holding a feature collection that implements the
              ``__geo_interface__``.
        crs : str or dict (optional)
            Coordinate reference system to set on the resulting frame.
        columns : list of column names, optional
            Optionally specify the column names to include in the output frame.
            This does not overwrite the property names of the input, but can
            ensure a consistent output format.

        Returns
        -------
        GeoDataFrame

        Notes
        -----
        For more information about the ``__geo_interface__``, see
        https://gist.github.com/sgillies/2217756

        Examples
        --------
        >>> feature_coll = {
        ...     "type": "FeatureCollection",
        ...     "features": [
        ...         {
        ...             "id": "0",
        ...             "type": "Feature",
        ...             "properties": {"col1": "name1"},
        ...             "geometry": {"type": "Point", "coordinates": (1.0, 2.0)},
        ...             "bbox": (1.0, 2.0, 1.0, 2.0),
        ...         },
        ...         {
        ...             "id": "1",
        ...             "type": "Feature",
        ...             "properties": {"col1": "name2"},
        ...             "geometry": {"type": "Point", "coordinates": (2.0, 1.0)},
        ...             "bbox": (2.0, 1.0, 2.0, 1.0),
        ...         },
        ...     ],
        ...     "bbox": (1.0, 1.0, 2.0, 2.0),
        ... }
        >>> df = geopandas.GeoDataFrame.from_features(feature_coll)
        >>> df
                          geometry   col1
        0  POINT (1.00000 2.00000)  name1
        1  POINT (2.00000 1.00000)  name2

        __geo_interface__typeFeatureCollectionfeaturesr   N
properties)r7   r#   )r9   ri   r&   r^   r1   r   r2   append)
rc   rl   r#   r7   fsZfeatures_lstrowsfeaturerowrm   r   r   r    from_features4  s$    =



zGeoDataFrame.from_featuresgeomTc
                 C   s$   t jjj|||||||||	d	}
|
S )a	  
        Alternate constructor to create a ``GeoDataFrame`` from a sql query
        containing a geometry column in WKB representation.

        Parameters
        ----------
        sql : string
        con : sqlalchemy.engine.Connection or sqlalchemy.engine.Engine
        geom_col : string, default 'geom'
            column name to convert to shapely geometries
        crs : optional
            Coordinate reference system to use for the returned GeoDataFrame
        index_col : string or list of strings, optional, default: None
            Column(s) to set as index(MultiIndex)
        coerce_float : boolean, default True
            Attempt to convert values of non-string, non-numeric objects (like
            decimal.Decimal) to floating point, useful for SQL result sets
        parse_dates : list or dict, default None
            - List of column names to parse as dates.
            - Dict of ``{column_name: format string}`` where format string is
              strftime compatible in case of parsing string times, or is one of
              (D, s, ns, ms, us) in case of parsing integer timestamps.
            - Dict of ``{column_name: arg dict}``, where the arg dict
              corresponds to the keyword arguments of
              :func:`pandas.to_datetime`. Especially useful with databases
              without native Datetime support, such as SQLite.
        params : list, tuple or dict, optional, default None
            List of parameters to pass to execute method.
        chunksize : int, default None
            If specified, return an iterator where chunksize is the number
            of rows to include in each chunk.

        Examples
        --------
        PostGIS

        >>> from sqlalchemy import create_engine  # doctest: +SKIP
        >>> db_connection_url = "postgresql://myusername:mypassword@myhost:5432/mydb"
        >>> con = create_engine(db_connection_url)  # doctest: +SKIP
        >>> sql = "SELECT geom, highway FROM roads"
        >>> df = geopandas.GeoDataFrame.from_postgis(sql, con)  # doctest: +SKIP

        SpatiaLite

        >>> sql = "SELECT ST_Binary(geom) AS geom, highway FROM roads"
        >>> df = geopandas.GeoDataFrame.from_postgis(sql, con)  # doctest: +SKIP

        The recommended method of reading from PostGIS is
        :func:`geopandas.read_postgis`:

        >>> df = geopandas.read_postgis(sql, con)  # doctest: +SKIP

        See also
        --------
        geopandas.read_postgis : read PostGIS database to GeoDataFrame
        )geom_colr#   	index_colcoerce_floatparse_datesparams	chunksize)rd   re   sqlZ_read_postgis)rc   r{   conru   r#   rv   rw   rx   ry   rz   r   r   r   r    from_postgis  s    FzGeoDataFrame.from_postgisnullc                 K   s   |r"| j r| jdd}q&tdn| }|j|||d}|j dur|j ds| j  }g d}	|du sr|d |	vrtjd	d
d n*|\}
}d|
 d| }dd|id|d< tj	|fi |S )as
  
        Returns a GeoJSON representation of the ``GeoDataFrame`` as a string.

        Parameters
        ----------
        na : {'null', 'drop', 'keep'}, default 'null'
            Indicates how to output missing (NaN) values in the GeoDataFrame.
            See below.
        show_bbox : bool, optional, default: False
            Include bbox (bounds) in the geojson
        drop_id : bool, default: False
            Whether to retain the index of the GeoDataFrame as the id property
            in the generated GeoJSON. Default is False, but may want True
            if the index is just arbitrary row numbers.
        to_wgs84: bool, optional, default: False
            If the CRS is set on the active geometry column it is exported as
            WGS84 (EPSG:4326) to meet the `2016 GeoJSON specification
            <https://tools.ietf.org/html/rfc7946>`_.
            Set to True to force re-projection and set to False to ignore CRS. False by
            default.

        Notes
        -----
        The remaining *kwargs* are passed to json.dumps().

        Missing (NaN) values in the GeoDataFrame can be represented as follows:

        - ``null``: output the missing entries as JSON null.
        - ``drop``: remove the property from the feature. This applies to each
          feature individually so that features may have different properties.
        - ``keep``: output the missing entries as NaN.

        If the GeoDataFrame has a defined CRS, its definition will be included
        in the output unless it is equal to WGS84 (default GeoJSON CRS) or not
        possible to represent in the URN OGC format, or unless ``to_wgs84=True``
        is specified.

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:3857")
        >>> gdf
            col1             geometry
        0  name1  POINT (1.000 2.000)
        1  name2  POINT (2.000 1.000)

        >>> gdf.to_json()
        '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"col1": "name1"}, "geometry": {"type": "Point", "coordinates": [1.0, 2.0]}}, {"id": "1", "type": "Feature", "properties": {"col1": "name2"}, "geometry": {"type": "Point", "coordinates": [2.0, 1.0]}}], "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3857"}}}'

        Alternatively, you can write GeoJSON to file:

        >>> gdf.to_file(path, driver="GeoJSON")  # doctest: +SKIP

        See also
        --------
        GeoDataFrame.to_file : write GeoDataFrame to file

        i  )epsgz7CRS is not set. Cannot re-project to WGS84 (EPSG:4326).na	show_bboxdrop_idNz	epsg:4326)ZEDCSZEPSGZOGCZSIZUCUMr   zjGeoDataFrame's CRS is not representable in URN OGC format. Resulting JSON will contain no CRS information.   
stacklevelzurn:ogc:def:crs:z::r%   )rj   rm   r#   )
r#   to_crsr5   _to_geoequalsZto_authoritywarningswarnjsondumps)r=   r   r   r   Zto_wgs84r   r   geoZauth_crsdefZallowed_authorities	authoritycodeZogc_crsr   r   r    to_json  s(    C
zGeoDataFrame.to_jsonc                 C   s   | j ddddS )a  Returns a ``GeoDataFrame`` as a python feature collection.

        Implements the `geo_interface`. The returned python data structure
        represents the ``GeoDataFrame`` as a GeoJSON-like
        ``FeatureCollection``.

        This differs from `_to_geo()` only in that it is a property with
        default args instead of a method.

        CRS of the dataframe is not passed on to the output, unlike
        :meth:`~GeoDataFrame.to_json()`.

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326")
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)

        >>> gdf.__geo_interface__
        {'type': 'FeatureCollection', 'features': [{'id': '0', 'type': 'Feature', 'properties': {'col1': 'name1'}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 2.0)}, 'bbox': (1.0, 2.0, 1.0, 2.0)}, {'id': '1', 'type': 'Feature', 'properties': {'col1': 'name2'}, 'geometry': {'type': 'Point', 'coordinates': (2.0, 1.0)}, 'bbox': (2.0, 1.0, 2.0, 1.0)}], 'bbox': (1.0, 1.0, 2.0, 2.0)}
        r~   TFr   )r   r[   r   r   r    ri   @  s     zGeoDataFrame.__geo_interface__c                 c   s  |dvrt d|| j| vr.td| j tj| jdd}tj| | j dd}| jjsbt d| j	| j}t
|dkrb| | }|t}t|j}|dkrd	||< t|jD ]\}	}
||	 }|d
kr||	 }dd t||
|D }ntt||
}|ri }ndt||	 i}d|d< ||d< |r6t|nd	|d< |rX|rP|jnd	|d< |V  qntt||D ]h\}}|ri }ndt|i}d|d< i |d< |rt|nd	|d< |r|r|jnd	|d< |V  qld	S )a  
        Returns an iterator that yields feature dictionaries that comply with
        __geo_interface__

        Parameters
        ----------
        na : str, optional
            Options are {'null', 'drop', 'keep'}, default 'null'.
            Indicates how to output missing (NaN) values in the GeoDataFrame

            - null: output the missing entries as JSON null
            - drop: remove the property from the feature. This applies to each feature individually so that features may have different properties
            - keep: output the missing entries as NaN

        show_bbox : bool, optional
            Include bbox (bounds) in the geojson. Default False.
        drop_id : bool, default: False
            Whether to retain the index of the GeoDataFrame as the id property
            in the generated GeoJSON. Default is False, but may want True
            if the index is just arbitrary row numbers.

        Examples
        --------

        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d, crs="EPSG:4326")
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)

        >>> feature = next(gdf.iterfeatures())
        >>> feature
        {'id': '0', 'type': 'Feature', 'properties': {'col1': 'name1'}, 'geometry': {'type': 'Point', 'coordinates': (1.0, 2.0)}}
        )r~   rU   ZkeepzUnknown na method {0}z/No geometry data set (expected in column '%s').Fr.   z4GeoDataFrame cannot contain duplicated column names.r   r~   NrU   c                 S   s   i | ]\}}}|s||qS r   r   ).0kvr   r   r   r    
<dictcomp>  s   z-GeoDataFrame.iterfeatures.<locals>.<dictcomp>idZFeaturerj   rm   r   bbox)r5   formatr,   rE   r(   arrayr$   r7   Z	is_uniquerU   r   astyper@   r   isnar:   	enumeratezipr^   strr   Zbounds)r=   r   r   r   ZidsZ
geometriesZproperties_colsrm   Zna_maskirr   rt   Zna_mask_rowZproperties_itemsrq   Zfidr   r   r    iterfeaturesb  s\    '



zGeoDataFrame.iterfeaturesc                 K   s8   dt | jf i |d}|ddr4t| j|d< |S )zz
        Returns a python feature collection (i.e. the geointerface)
        representation of the GeoDataFrame.

        rk   )rj   rl   r   Fr   )rD   r   r1   tupleZtotal_bounds)r=   r   r   r   r   r    r     s    zGeoDataFrame._to_geoc                 K   sD   t |  }|j|jdk D ]"}t|| jfd|i|||< q|S )a!  
        Encode all geometry columns in the GeoDataFrame 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
        -------
        DataFrame
            geometry columns are encoded to WKB
        r   hex)r   r'   r7   r   r   r:   )r=   r   r   r   rM   r   r   r    r     s     zGeoDataFrame.to_wkbc                 K   s@   t |  }|j|jdk D ]}t|| jfi |||< q|S )aG  
        Encode all geometry columns in the GeoDataFrame to WKT.

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

        Returns
        -------
        DataFrame
            geometry columns are encoded to WKT
        r   )r   r'   r7   r   r   r:   )r=   r   r   rM   r   r   r    r     s    zGeoDataFrame.to_wktsnappyc                 K   sN   | dd}|dvr$td|dddlm} || |f|||d| d	S )
a
  Write a GeoDataFrame to the Parquet format.

        Any geometry columns present are serialized to WKB format in the file.

        Requires 'pyarrow'.

        WARNING: this is an early implementation of Parquet file support and
        associated metadata, the specification for which continues to evolve.
        This is tracking version 0.4.0 of the GeoParquet specification at:
        https://github.com/opengeospatial/geoparquet

        This metadata specification does not yet make stability promises.  As such,
        we do not yet recommend using this in a production setting unless you are
        able to rewrite your Parquet files.

        .. versionadded:: 0.8

        Parameters
        ----------
        path : str, path object
        index : bool, default None
            If ``True``, always include the dataframe's index(es) as columns
            in the file output.
            If ``False``, the index(es) will not be written to the file.
            If ``None``, the index(ex) will be included as columns in the file
            output except `RangeIndex` which is stored as metadata only.
        compression : {'snappy', 'gzip', 'brotli', None}, default 'snappy'
            Name of the compression to use. Use ``None`` for no compression.
        schema_version : {'0.1.0', '0.4.0', None}
            GeoParquet specification version; if not provided will default to
            latest supported version.
        kwargs
            Additional keyword arguments passed to :func:`pyarrow.parquet.write_table`.

        Examples
        --------

        >>> gdf.to_parquet('data.parquet')  # doctest: +SKIP

        See also
        --------
        GeoDataFrame.to_feather : write GeoDataFrame to feather
        GeoDataFrame.to_file : write GeoDataFrame to file
        engineauto)r   ZpyarrowzDGeoPandas only supports using pyarrow as the engine for to_parquet: z passed instead.r   )_to_parquet)compressionr$   schema_versionN)r_   r5   geopandas.io.arrowr   )r=   pathr$   r   r   r   r   r   r   r   r    
to_parquet  s$    3zGeoDataFrame.to_parquetc                 K   s*   ddl m} || |f|||d| dS )ah  Write a GeoDataFrame to the Feather format.

        Any geometry columns present are serialized to WKB format in the file.

        Requires 'pyarrow' >= 0.17.

        WARNING: this is an early implementation of Parquet file support and
        associated metadata, the specification for which continues to evolve.
        This is tracking version 0.4.0 of the GeoParquet specification at:
        https://github.com/opengeospatial/geoparquet

        This metadata specification does not yet make stability promises.  As such,
        we do not yet recommend using this in a production setting unless you are
        able to rewrite your Feather files.

        .. versionadded:: 0.8

        Parameters
        ----------
        path : str, path object
        index : bool, default None
            If ``True``, always include the dataframe's index(es) as columns
            in the file output.
            If ``False``, the index(es) will not be written to the file.
            If ``None``, the index(ex) will be included as columns in the file
            output except `RangeIndex` which is stored as metadata only.
        compression : {'zstd', 'lz4', 'uncompressed'}, optional
            Name of the compression to use. Use ``"uncompressed"`` for no
            compression. By default uses LZ4 if available, otherwise uncompressed.
        schema_version : {'0.1.0', '0.4.0', None}
            GeoParquet specification version; if not provided will default to
            latest supported version.
        kwargs
            Additional keyword arguments passed to to
            :func:`pyarrow.feather.write_feather`.

        Examples
        --------

        >>> gdf.to_feather('data.feather')  # doctest: +SKIP

        See also
        --------
        GeoDataFrame.to_parquet : write GeoDataFrame to parquet
        GeoDataFrame.to_file : write GeoDataFrame to file
        r   )_to_feather)r$   r   r   N)r   r   )r=   r   r$   r   r   r   r   r   r   r    
to_featherW  s    2zGeoDataFrame.to_featherc                 K   s(   ddl m} || ||||fi | dS )a?  Write the ``GeoDataFrame`` to a file.

        By default, an ESRI shapefile is written, but any OGR data source
        supported by Fiona can be written. A dictionary of supported OGR
        providers is available via:

        >>> import fiona
        >>> fiona.supported_drivers  # doctest: +SKIP

        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.
        schema : dict, default None
            If specified, the schema dictionary is passed to Fiona to
            better control how the file is written. If None, GeoPandas
            will determine the schema based on each column's dtype.
            Not supported for the "pyogrio" engine.
        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`.

        Notes
        -----
        The format drivers will attempt to detect the encoding of your data, but
        may fail. In this case, the proper encoding can be specified explicitly
        by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.

        See Also
        --------
        GeoSeries.to_file
        GeoDataFrame.to_postgis : write GeoDataFrame to PostGIS database
        GeoDataFrame.to_parquet : write GeoDataFrame to parquet
        GeoDataFrame.to_feather : write GeoDataFrame to feather

        Examples
        --------

        >>> gdf.to_file('dataframe.shp')  # doctest: +SKIP

        >>> gdf.to_file('dataframe.gpkg', driver='GPKG', layer='name')  # doctest: +SKIP

        >>> gdf.to_file('dataframe.geojson', driver='GeoJSON')  # doctest: +SKIP

        With selected drivers you can also append to a file with `mode="a"`:

        >>> gdf.to_file('dataframe.shp', mode="a")  # doctest: +SKIP

        Using the engine-specific keyword arguments it is possible to e.g. create a
        spatialite file with a custom layer name:

        >>> gdf.to_file(
        ...     'dataframe.sqlite', driver='SQLite', spatialite=True, layer='test'
        ... )  # doctest: +SKIP

        r   )_to_fileN)Zgeopandas.io.filer   )r=   rg   Zdriverschemar$   r   r   r   r   r    to_file  s    ZzGeoDataFrame.to_filec                 C   s,   |s|   }n| }|jj|||dd|_|S )u	  
        Set the Coordinate Reference System (CRS) of the ``GeoDataFrame``.

        If there are multiple geometry columns within the GeoDataFrame, only
        the CRS of the active geometry column is set.

        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 GeoDataFrame will be changed in place
            (while still returning the result) instead of making a copy of
            the GeoDataFrame.
        allow_override : bool, default False
            If the the GeoDataFrame already has a CRS, allow to replace the
            existing CRS, even when both are not equal.

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d)
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)

        Setting CRS to a GeoDataFrame without one:

        >>> gdf.crs is None
        True

        >>> gdf = gdf.set_crs('epsg:3857')
        >>> gdf.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:

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

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

        See also
        --------
        GeoDataFrame.to_crs : re-project to another CRS

        T)r#   r   allow_overrider/   )r'   r   set_crs)r=   r#   r   r/   r   r   r   r   r    r     s    F
zGeoDataFrame.set_crsc                 C   s4   |r
| }n|   }|jj||d}||_|s0|S dS )uT  Transform geometries to a new coordinate reference system.

        Transform all geometries in an active geometry column 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.
        inplace : bool, optional, default: False
            Whether to return a new GeoDataFrame or do the transformation in
            place.

        Returns
        -------
        GeoDataFrame

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> d = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
        >>> gdf = geopandas.GeoDataFrame(d, crs=4326)
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)
        >>> gdf.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

        >>> gdf = gdf.to_crs(3857)
        >>> gdf
            col1                       geometry
        0  name1  POINT (111319.491 222684.209)
        1  name2  POINT (222638.982 111325.143)
        >>> gdf.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
        --------
        GeoDataFrame.set_crs : assign CRS without re-projection
        )r#   r   N)r'   r   r   )r=   r#   r   r/   r   rt   r   r   r    r   A  s    LzGeoDataFrame.to_crsWGS 84c                 C   s   | j j|dS )u>  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.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
        )
datum_name)r   estimate_utm_crs)r=   r   r   r   r    r     s    $zGeoDataFrame.estimate_utm_crsc                    s   t  |}tjj|rh|dkrht| jtjrht|t	rht
|sh| j|}| jdd|f jdd}| j}t|t	rt|jtrt|_n8t|tr|jdk dkrt|_||v r||_nt|_|S )z
        If the result is a column containing only 'geometry', return a
        GeoSeries. If it's a DataFrame with any columns of GeometryDtype,
        return a GeoDataFrame.
         Nr7   axisr   r   )r3   __getitem__r   rI   rJ   	is_scalarr&   r7   Z
MultiIndexr   r   Zget_locZilocZsqueezer,   dtyper
   r   r?   r   r   r   r   )r=   keyresultlocgeo_colr>   r   r    r     s.    
zGeoDataFrame.__getitem__c                 C   s2   | j du r.d| jvr.d}tj|tdd d| _ dS )zxInternal util to temporarily persist the default geometry column
        name of 'geometry' for backwards compatibility.Nr   a  You are adding a column named 'geometry' to a GeoDataFrame constructed without an active geometry column. Currently, this automatically sets the active geometry column to 'geometry' but in the future that will no longer happen. Instead, either provide geometry to the GeoDataFrame constructor (GeoDataFrame(... geometry=GeoSeries()) or use `set_geometry('geometry')` to explicitly set the active geometry column.   )categoryr   )r,   r7   r   r   FutureWarning)r=   rF   r   r   r    rL     s
    
z2GeoDataFrame._persist_old_default_geometry_colnamec                    s   t jj|s|| jks*|dkr| jdu rt jj|sBt|trR|g| jd  }z<| jdurlt	| dd}nd}t
||d}|dkr|   W n  ty   tjddd Y n0 t || dS )	z
        Overwritten to preserve CRS of GeometryArray in cases like
        df['geometry'] = [geom... for geom in df.geometry]
        r   Nr   r#   r"   z*Geometry column does not contain geometry.r   r   )r   rI   rJ   rK   r,   r   r&   r   r   rT   r+   rL   r;   r   r   r3   __setitem__)r=   r   r\   r#   r>   r   r    r     s,    
zGeoDataFrame.__setitem__c                    s.   t  j|d}t|tju r*t|_| j|_|S )N)deep)r3   r'   rj   r   r   r   r?   r,   )r=   r   copiedr>   r   r    r'     s
    zGeoDataFrame.copyc                 O   sb   t j| g|R i |}| j}t|t rF||v rFt|_| j|_||_nt|t r^||vr^t |_|S )a  Merge two ``GeoDataFrame`` objects with a database-style join.

        Returns a ``GeoDataFrame`` if a geometry column is present; otherwise,
        returns a pandas ``DataFrame``.

        Returns
        -------
        GeoDataFrame or DataFrame

        Notes
        -----
        The extra arguments ``*args`` and keyword arguments ``**kwargs`` are
        passed to DataFrame.merge.
        See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas\
.DataFrame.merge.html
        for more details.
        )r   merger,   r&   r   r?   r#   )r=   r   r   r   r   r   r   r    r     s    zGeoDataFrame.merger   r   c              	      s   t  j|f||||d|}tjs@t|tr@|jd u r@| j|_t|tr| j|jv rz|	| j}W n t
yx   Y q0 | jd ur|jd u r|j| jdd nHt|tr|jdkr|  szt|}W n t
tjjfy   Y n0 |S )N)r   rawresult_typer   TrH   r@   )r3   applyr0   ZPANDAS_GE_14r&   r   r,   r   r7   r<   r;   r#   r   r   r   r   allr+   shapelyerrorsZGeometryTypeError)r=   funcr   r   r   r   r   r   r>   r   r    r   0  s>    
zGeoDataFrame.applyc                 C   s   t S N)r!   r[   r   r   r    _constructorW  s    zGeoDataFrame._constructorc                    s    fdd}|S )Nc                     s4   t j| i |}|j ju }t|r0|s0t|}|S )a  
            A specialized (Geo)Series constructor which can fall back to a
            Series if a certain operation does not produce geometries:

            - We only return a GeoSeries if the data is actually of geometry
              dtype (and so we don't try to convert geometry objects such as
              the normal GeoSeries(..) constructor does with `_ensure_geometry`).
            - When we get here from obtaining a row or column from a
              GeoDataFrame, the goal is to only return a GeoSeries for a
              geometry column, and not return a GeoSeries for a row that happened
              to come from a DataFrame with only geometry dtype columns (and
              thus could have a geometry dtype). Therefore, we don't return a
              GeoSeries if we are sure we are in a row selection case (by
              checking the identity of the index)
            )r   r   r$   r7   r   r   )r   r   ZsrsZis_row_proxyr[   r   r     _geodataframe_constructor_sliced]  s
    zJGeoDataFrame._constructor_sliced.<locals>._geodataframe_constructor_slicedr   )r=   r   r   r[   r    _constructor_sliced[  s    z GeoDataFrame._constructor_slicedc              	      s   t  j|fd|i|} |dkrF| jD ]}t| |t|j|d q&nl|dkr| jD ] }t| |t|jd |d qT| j| j	k
 dkrtd| j	 dn|d	krd| _	d| _| S )
z%propagate metadata from other to selfmethodr   Nconcatr   r   zRConcat operation has resulted in multiple columns using the geometry column name 'zF'.
Please ensure this column from the first DataFrame is not repeated.Zunstack)r3   __finalize__	_metadatar@   rA   rT   leftZobjsr7   r,   r   r5   r]   )r=   otherr   r   r%   r>   r   r    r   u  s"    

zGeoDataFrame.__finalize__firstc              	   K   sL  |du r"|du r"t jt| dd}|||||d}	| j| jjdd}
tjdd.}|
jf i |	j	|fi |}W d   n1 s0    Y  |D ]R}t
|jd	rd
| d}tj|tdd qt|j|j|j|j|j|j q|j |_dd }| jf ddi|	| jj 	|}t|| jj| jd}||}|sH| }|S )a	  
        Dissolve geometries within `groupby` into single observation.
        This is accomplished by applying the `unary_union` method
        to all geometries within a groupself.

        Observations associated with each `groupby` group will be aggregated
        using the `aggfunc`.

        Parameters
        ----------
        by : str or list-like, default None
            Column(s) whose values define the groups to be dissolved. If None,
            the entire GeoDataFrame is considered as a single group. If a list-like
            object is provided, the values in the list are treated as categorical
            labels, and polygons will be combined based on the equality of
            these categorical labels.
        aggfunc : function or string, default "first"
            Aggregation function for manipulation of data associated
            with each group. Passed to pandas `groupby.agg` method.
            Accepted combinations are:

            - function
            - string function name
            - list of functions and/or function names, e.g. [np.sum, 'mean']
            - dict of axis labels -> functions, function names or list of such.
        as_index : boolean, default True
            If true, groupby columns become index of result.
        level : int or str or sequence of int or sequence of str, default None
            If the axis is a MultiIndex (hierarchical), group by a
            particular level or levels.

            .. versionadded:: 0.9.0
        sort : bool, default True
            Sort group keys. Get better performance by turning this off.
            Note this does not influence the order of observations within
            each group. Groupby preserves the order of rows within each group.

            .. versionadded:: 0.9.0
        observed : bool, default False
            This only applies if any of the groupers are Categoricals.
            If True: only show observed values for categorical groupers.
            If False: show all values for categorical groupers.

            .. versionadded:: 0.9.0
        dropna : bool, default True
            If True, and if group keys contain NA values, NA values
            together with row/column will be dropped. If False, NA
            values will also be treated as the key in groups.

            .. versionadded:: 0.9.0
        **kwargs :
            Keyword arguments to be passed to the pandas `DataFrameGroupby.agg` method
            which is used by `dissolve`. In particular, `numeric_only` may be
            supplied, which will be required in pandas 2.0 for certain aggfuncs.

            .. versionadded:: 0.13.0
        Returns
        -------
        GeoDataFrame

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> d = {
        ...     "col1": ["name1", "name2", "name1"],
        ...     "geometry": [Point(1, 2), Point(2, 1), Point(0, 1)],
        ... }
        >>> gdf = geopandas.GeoDataFrame(d, crs=4326)
        >>> gdf
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name2  POINT (2.00000 1.00000)
        2  name1  POINT (0.00000 1.00000)

        >>> dissolved = gdf.dissolve('col1')
        >>> dissolved  # doctest: +SKIP
                                                    geometry
        col1
        name1  MULTIPOINT (0.00000 1.00000, 1.00000 2.00000)
        name2                        POINT (2.00000 1.00000)

        See also
        --------
        GeoDataFrame.explode : explode multi-part geometries into single geometries

        Nint64)r   )byrX   sortobserveddropnar   )labelsr   T)recordz!The default value of numeric_onlyz.The default value of numeric_only in aggfunc='z' within pandas.DataFrameGroupBy.agg used in dissolve is deprecated. In pandas 2.0, numeric_only will default to False. Either specify numeric_only as additional argument in dissolve() or select only columns which should be valid for the function.r   r   c                 S   s
   | j }|S r   )Zunary_union)blockZmerged_geomr   r   r    merge_geometries  s    z/GeoDataFrame.dissolve.<locals>.merge_geometriesZ
group_keysFr-   )r(   Zzerosr   rU   r   r%   r   catch_warningsgroupbyZaggr   message
startswithr   r   showwarningr   rg   linenorf   liner7   Zto_flat_indexr   r#   joinreset_index)r=   r   ZaggfuncZas_indexrX   r   r   r   r   Zgroupby_kwargsr)   r   Zaggregated_datawrF   r   gZaggregated_geometryZ
aggregatedr   r   r    dissolve  s:    b	<

zGeoDataFrame.dissolvec                    s   |du r| j j}t| | jts8t j|fd|i|S |du rX|sTtjdt	dd d}| j j
ddjdd}| j| jd	d
|jd}|j||j< || j| }|r|j
ddd n*|r|j|jtt|jjd	 dd}|S )u
  
        Explode multi-part geometries into multiple single geometries.

        Each row containing a multi-part geometry will be split into
        multiple rows with single geometries, thereby increasing the vertical
        size of the GeoDataFrame.

        Parameters
        ----------
        column : string, default None
            Column to explode. In the case of a geometry column, multi-part
            geometries are converted to single-part.
            If None, the active geometry column is used.
        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
        -------
        GeoDataFrame
            Exploded geodataframe with each single geometry
            as a separate entry in the geodataframe.

        Examples
        --------

        >>> from shapely.geometry import MultiPoint
        >>> d = {
        ...     "col1": ["name1", "name2"],
        ...     "geometry": [
        ...         MultiPoint([(1, 2), (3, 4)]),
        ...         MultiPoint([(2, 1), (0, 0)]),
        ...     ],
        ... }
        >>> gdf = geopandas.GeoDataFrame(d, crs=4326)
        >>> gdf
            col1                                       geometry
        0  name1  MULTIPOINT (1.00000 2.00000, 3.00000 4.00000)
        1  name2  MULTIPOINT (2.00000 1.00000, 0.00000 0.00000)

        >>> exploded = gdf.explode(index_parts=True)
        >>> exploded
              col1                 geometry
        0 0  name1  POINT (1.00000 2.00000)
          1  name1  POINT (3.00000 4.00000)
        1 0  name2  POINT (2.00000 1.00000)
          1  name2  POINT (0.00000 0.00000)

        >>> exploded = gdf.explode(index_parts=False)
        >>> exploded
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        0  name1  POINT (3.00000 4.00000)
        1  name2  POINT (2.00000 1.00000)
        1  name2  POINT (0.00000 0.00000)

        >>> exploded = gdf.explode(ignore_index=True)
        >>> exploded
            col1                 geometry
        0  name1  POINT (1.00000 2.00000)
        1  name1  POINT (3.00000 4.00000)
        2  name2  POINT (2.00000 1.00000)
        3  name2  POINT (0.00000 0.00000)

        See also
        --------
        GeoDataFrame.dissolve : dissolve geometries into a single observation.

        Nignore_indexzCurrently, 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)rU   )index_partsr   r   )r/   rU   )rn   )r   r%   r&   r   r
   r3   exploder   r   r   r   rU   r,   taker$   Z	droplevelr:   r<   r   Z	set_indexrD   ranger8   )r=   columnr   r   r   Zexploded_geomr   r>   r   r    r   *  s8    M
zGeoDataFrame.exploderaisec                    s`   t  j|f||d|}z(|| j }t|r@tj|| jdW S W n tyT   Y n0 t|S )aL  
        Cast a pandas object to a specified dtype ``dtype``.

        Returns a GeoDataFrame when the geometry column is kept as geometries,
        otherwise returns a pandas DataFrame.

        See the pandas.DataFrame.astype docstring for more details.

        Returns
        -------
        GeoDataFrame or DataFrame
        )r'   r   )r   )	r3   r   r,   r   rd   r   rR   r   r   )r=   r   r'   r   r   r   Zgeomsr>   r   r    r     s    
zGeoDataFrame.astypec                    s"   t t j|i || jj| jdS )aE  
        Convert columns to best possible dtypes using dtypes supporting ``pd.NA``.

        Always returns a GeoDataFrame as no conversions are applied to the
        geometry column.

        See the pandas.DataFrame.convert_dtypes docstring for more details.

        Returns
        -------
        GeoDataFrame

        r-   )r   r3   convert_dtypesr   r%   r#   r=   r   r   r>   r   r    r     s
    zGeoDataFrame.convert_dtypesfailc	           	      C   s"   t jj| ||||||||	 dS )a`  
        Upload GeoDataFrame into PostGIS database.

        This method requires SQLAlchemy and GeoAlchemy2, and a PostgreSQL
        Python driver (e.g. psycopg2) to be installed.

        It is also possible to use :meth:`~GeoDataFrame.to_file` to write to a database.
        Especially for file geodatabases like GeoPackage or SpatiaLite this can be
        easier.

        Parameters
        ----------
        name : str
            Name of the target table.
        con : sqlalchemy.engine.Connection or sqlalchemy.engine.Engine
            Active connection to the PostGIS database.
        if_exists : {'fail', 'replace', 'append'}, default 'fail'
            How to behave if the table already exists:

            - fail: Raise a ValueError.
            - replace: Drop the table before inserting new values.
            - append: Insert new values to the existing table.
        schema : string, optional
            Specify the schema. If None, use default schema: 'public'.
        index : bool, default False
            Write DataFrame index as a column.
            Uses *index_label* as the column name in the table.
        index_label : string or sequence, default None
            Column label for index column(s).
            If None is given (default) and index is True,
            then the index names are used.
        chunksize : int, optional
            Rows will be written in batches of this size at a time.
            By default, all rows will be written at once.
        dtype : dict of column name to SQL type, default None
            Specifying the datatype for columns.
            The keys should be the column names and the values
            should be the SQLAlchemy types.

        Examples
        --------

        >>> from sqlalchemy import create_engine
        >>> engine = create_engine("postgresql://myusername:mypassword@myhost:5432/mydatabase")  # doctest: +SKIP
        >>> gdf.to_postgis("my_table", engine)  # doctest: +SKIP

        See also
        --------
        GeoDataFrame.to_file : write GeoDataFrame to file
        read_postgis : read PostGIS database to GeoDataFrame

        N)rd   re   r{   Z_write_postgis)	r=   r%   r|   r   Z	if_existsr$   Zindex_labelrz   r   r   r   r    
to_postgis  s    @zGeoDataFrame.to_postgisc                 C   s   t jdtdd | j|S )z,Implement ^ operator as for builtin set typezO'^' operator will be deprecated. Use the 'symmetric_difference' method instead.r   r   )r   r   r   r   symmetric_differencer=   r   r   r   r    __xor__  s    zGeoDataFrame.__xor__c                 C   s   t jdtdd | j|S )z,Implement | operator as for builtin set typez@'|' operator will be deprecated. Use the 'union' method instead.r   r   )r   r   r   r   unionr   r   r   r    __or__"  s    zGeoDataFrame.__or__c                 C   s   t jdtdd | j|S )z,Implement & operator as for builtin set typezG'&' operator will be deprecated. Use the 'intersection' method instead.r   r   )r   r   r   r   intersectionr   r   r   r    __and__+  s    zGeoDataFrame.__and__c                 C   s   t jdtdd | j|S )z,Implement - operator as for builtin set typezE'-' operator will be deprecated. Use the 'difference' method instead.r   r   )r   r   r   r   
differencer   r   r   r    __sub__4  s    zGeoDataFrame.__sub__plotc                 O   s   t | g|R i |S r   r   r   r   r   r    explore?  s    zGeoDataFrame.explorec                 O   s   t j|| |d|S )a1  Spatial join of two GeoDataFrames.

        See the User Guide page :doc:`../../user_guide/mergingdata` for details.

        Parameters
        ----------
        df : GeoDataFrame
        how : string, default 'inner'
            The type of join:

            * 'left': use keys from left_df; retain only left_df geometry column
            * 'right': use keys from right_df; retain only right_df geometry column
            * 'inner': use intersection of keys from both dfs; retain only
              left_df geometry column

        predicate : string, default 'intersects'
            Binary predicate. Valid values are determined by the spatial index used.
            You can check the valid values in left_df or right_df as
            ``left_df.sindex.valid_query_predicates`` or
            ``right_df.sindex.valid_query_predicates``
        lsuffix : string, default 'left'
            Suffix to apply to overlapping column names (left GeoDataFrame).
        rsuffix : string, default 'right'
            Suffix to apply to overlapping column names (right GeoDataFrame).

        Examples
        --------
        >>> import geodatasets
        >>> chicago = geopandas.read_file(
        ...     geodatasets.get_path("geoda.chicago_commpop")
        ... )
        >>> groceries = geopandas.read_file(
        ...     geodatasets.get_path("geoda.groceries")
        ... ).to_crs(chicago.crs)

        >>> chicago.head()  # doctest: +SKIP
                 community  ...                                           geometry
        0          DOUGLAS  ...  MULTIPOLYGON (((-87.60914 41.84469, -87.60915 ...
        1          OAKLAND  ...  MULTIPOLYGON (((-87.59215 41.81693, -87.59231 ...
        2      FULLER PARK  ...  MULTIPOLYGON (((-87.62880 41.80189, -87.62879 ...
        3  GRAND BOULEVARD  ...  MULTIPOLYGON (((-87.60671 41.81681, -87.60670 ...
        4          KENWOOD  ...  MULTIPOLYGON (((-87.59215 41.81693, -87.59215 ...

        [5 rows x 9 columns]

        >>> groceries.head()  # doctest: +SKIP
           OBJECTID     Ycoord  ...  Category                         geometry
        0        16  41.973266  ...       NaN  MULTIPOINT (-87.65661 41.97321)
        1        18  41.696367  ...       NaN  MULTIPOINT (-87.68136 41.69713)
        2        22  41.868634  ...       NaN  MULTIPOINT (-87.63918 41.86847)
        3        23  41.877590  ...       new  MULTIPOINT (-87.65495 41.87783)
        4        27  41.737696  ...       NaN  MULTIPOINT (-87.62715 41.73623)
        [5 rows x 8 columns]

        >>> groceries_w_communities = groceries.sjoin(chicago)
        >>> groceries_w_communities[["OBJECTID", "community", "geometry"]].head()
             OBJECTID    community                         geometry
        0          16       UPTOWN  MULTIPOINT (-87.65661 41.97321)
        87        365       UPTOWN  MULTIPOINT (-87.65465 41.96138)
        90        373       UPTOWN  MULTIPOINT (-87.65598 41.96297)
        140       582       UPTOWN  MULTIPOINT (-87.67417 41.96977)
        1          18  MORGAN PARK  MULTIPOINT (-87.68136 41.69713)

        Notes
        -----
        Every operation in GeoPandas is planar, i.e. the potential third
        dimension is not taken into account.

        See also
        --------
        GeoDataFrame.sjoin_nearest : nearest neighbor join
        sjoin : equivalent top-level function
        )Zleft_dfZright_df)rd   sjoin)r=   r   r   r   r   r   r    r  C  s    JzGeoDataFrame.sjoininnerr   rightc              
   C   s   t j| |||||||dS )a  
        Spatial join of two GeoDataFrames based on the distance between their
        geometries.

        Results will include multiple output records for a single input record
        where there are multiple equidistant nearest or intersected neighbors.

        See the User Guide page
        https://geopandas.readthedocs.io/en/latest/docs/user_guide/mergingdata.html
        for more details.


        Parameters
        ----------
        right : GeoDataFrame
        how : string, default 'inner'
            The type of join:

            * 'left': use keys from left_df; retain only left_df geometry column
            * 'right': use keys from right_df; retain only right_df geometry column
            * 'inner': use intersection of keys from both dfs; retain only
              left_df geometry column

        max_distance : float, default None
            Maximum distance within which to query for nearest geometry.
            Must be greater than 0.
            The max_distance used to search for nearest items in the tree may have a
            significant impact on performance by reducing the number of input
            geometries that are evaluated for nearest items in the tree.
        lsuffix : string, default 'left'
            Suffix to apply to overlapping column names (left GeoDataFrame).
        rsuffix : string, default 'right'
            Suffix to apply to overlapping column names (right GeoDataFrame).
        distance_col : string, default None
            If set, save the distances computed between matching geometries under a
            column of this name in the joined GeoDataFrame.
        exclusive : bool, optional, default False
            If True, the nearest geometries that are equal to the input geometry
            will not be returned, default False.
            Requires Shapely >= 2.0

        Examples
        --------
        >>> import geodatasets
        >>> groceries = geopandas.read_file(
        ...     geodatasets.get_path("geoda.groceries")
        ... )
        >>> chicago = geopandas.read_file(
        ...     geodatasets.get_path("geoda.chicago_health")
        ... ).to_crs(groceries.crs)

        >>> chicago.head()  # doctest: +SKIP
            ComAreaID  ...                                           geometry
        0         35  ...  POLYGON ((-87.60914 41.84469, -87.60915 41.844...
        1         36  ...  POLYGON ((-87.59215 41.81693, -87.59231 41.816...
        2         37  ...  POLYGON ((-87.62880 41.80189, -87.62879 41.801...
        3         38  ...  POLYGON ((-87.60671 41.81681, -87.60670 41.816...
        4         39  ...  POLYGON ((-87.59215 41.81693, -87.59215 41.816...
        [5 rows x 87 columns]

        >>> groceries.head()  # doctest: +SKIP
            OBJECTID     Ycoord  ...  Category                         geometry
        0        16  41.973266  ...       NaN  MULTIPOINT (-87.65661 41.97321)
        1        18  41.696367  ...       NaN  MULTIPOINT (-87.68136 41.69713)
        2        22  41.868634  ...       NaN  MULTIPOINT (-87.63918 41.86847)
        3        23  41.877590  ...       new  MULTIPOINT (-87.65495 41.87783)
        4        27  41.737696  ...       NaN  MULTIPOINT (-87.62715 41.73623)
        [5 rows x 8 columns]

        >>> groceries_w_communities = groceries.sjoin_nearest(chicago)
        >>> groceries_w_communities[["Chain", "community", "geometry"]].head(2)
                     Chain community                              geometry
        0   VIET HOA PLAZA    UPTOWN  MULTIPOINT (1168268.672 1933554.350)
        87      JEWEL OSCO    UPTOWN  MULTIPOINT (1168837.980 1929246.962)


        To include the distances:

        >>> groceries_w_communities = groceries.sjoin_nearest(chicago, distance_col="distances")
        >>> groceries_w_communities[["Chain", "community", "distances"]].head(2)  # doctest: +SKIP
                     Chain community  distances
        0   VIET HOA PLAZA    UPTOWN        0.0
        87      JEWEL OSCO    UPTOWN        0.0

        In the following example, we get multiple groceries for Uptown because all
        results are equidistant (in this case zero because they intersect).
        In fact, we get 4 results in total:

        >>> chicago_w_groceries = groceries.sjoin_nearest(chicago, distance_col="distances", how="right")
        >>> uptown_results = chicago_w_groceries[chicago_w_groceries["community"] == "UPTOWN"]
        >>> uptown_results[["Chain", "community"]]  # doctest: +SKIP
                    Chain community
        30  VIET HOA PLAZA    UPTOWN
        30      JEWEL OSCO    UPTOWN
        30          TARGET    UPTOWN
        30       Mariano's    UPTOWN

        See also
        --------
        GeoDataFrame.sjoin : binary predicate joins
        sjoin_nearest : equivalent top-level function

        Notes
        -----
        Since this join relies on distances, results will be inaccurate
        if your geometries are in a geographic CRS.

        Every operation in GeoPandas is planar, i.e. the potential third
        dimension is not taken into account.
        )howmax_distancelsuffixrsuffixdistance_col	exclusive)rd   sjoin_nearest)r=   r  r  r	  r
  r  r  r  r   r   r    r    s    |zGeoDataFrame.sjoin_nearestc                 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 GeoDataFrame will be clipped to the full extent of the ``mask`` object.

        If there are multiple polygons in mask, data from the GeoDataFrame 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 the GeoDataFrame.
            The mask's geometry is dissolved into one geometric feature
            and intersected with GeoDataFrame.
            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
        -------
        GeoDataFrame
            Vector data (points, lines, polygons) from the GeoDataFrame clipped to
            polygon boundary from mask.

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

        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.clip(near_west_side)
        >>> nws_groceries.shape
        (7, 8)
        )maskkeep_geom_type)rd   clip)r=   r  r  r   r   r    r  	  s    5zGeoDataFrame.clipr   c                 C   s   t j| ||||dS )a  Perform spatial overlay between GeoDataFrames.

        Currently only supports data GeoDataFrames with uniform geometry types,
        i.e. containing only (Multi)Polygons, or only (Multi)Points, or a
        combination of (Multi)LineString and LinearRing shapes.
        Implements several methods that are all effectively subsets of the union.

        See the User Guide page :doc:`../../user_guide/set_operations` for details.

        Parameters
        ----------
        right : GeoDataFrame
        how : string
            Method of spatial overlay: 'intersection', 'union',
            'identity', 'symmetric_difference' or 'difference'.
        keep_geom_type : bool
            If True, return only geometries of the same geometry type the GeoDataFrame
            has, if False, return all resulting geometries. Default is None,
            which will set keep_geom_type to True but warn upon dropping
            geometries.
        make_valid : bool, default True
            If True, any invalid input geometries are corrected with a call to
            `buffer(0)`, if False, a `ValueError` is raised if any input geometries
            are invalid.

        Returns
        -------
        df : GeoDataFrame
            GeoDataFrame with new set of polygons and attributes
            resulting from the overlay

        Examples
        --------
        >>> from shapely.geometry import Polygon
        >>> polys1 = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,2), (0,2)]),
        ...                               Polygon([(2,2), (4,2), (4,4), (2,4)])])
        >>> polys2 = geopandas.GeoSeries([Polygon([(1,1), (3,1), (3,3), (1,3)]),
        ...                               Polygon([(3,3), (5,3), (5,5), (3,5)])])
        >>> df1 = geopandas.GeoDataFrame({'geometry': polys1, 'df1_data':[1,2]})
        >>> df2 = geopandas.GeoDataFrame({'geometry': polys2, 'df2_data':[1,2]})

        >>> df1.overlay(df2, how='union')
        df1_data  df2_data                                           geometry
        0       1.0       1.0  POLYGON ((2.00000 2.00000, 2.00000 1.00000, 1....
        1       2.0       1.0  POLYGON ((2.00000 2.00000, 2.00000 3.00000, 3....
        2       2.0       2.0  POLYGON ((4.00000 4.00000, 4.00000 3.00000, 3....
        3       1.0       NaN  POLYGON ((2.00000 0.00000, 0.00000 0.00000, 0....
        4       2.0       NaN  MULTIPOLYGON (((3.00000 4.00000, 3.00000 3.000...
        5       NaN       1.0  MULTIPOLYGON (((2.00000 3.00000, 2.00000 2.000...
        6       NaN       2.0  POLYGON ((3.00000 5.00000, 5.00000 5.00000, 5....

        >>> df1.overlay(df2, how='intersection')
        df1_data  df2_data                                           geometry
        0         1         1  POLYGON ((2.00000 2.00000, 2.00000 1.00000, 1....
        1         2         1  POLYGON ((2.00000 2.00000, 2.00000 3.00000, 3....
        2         2         2  POLYGON ((4.00000 4.00000, 4.00000 3.00000, 3....

        >>> df1.overlay(df2, how='symmetric_difference')
        df1_data  df2_data                                           geometry
        0       1.0       NaN  POLYGON ((2.00000 0.00000, 0.00000 0.00000, 0....
        1       2.0       NaN  MULTIPOLYGON (((3.00000 4.00000, 3.00000 3.000...
        2       NaN       1.0  MULTIPOLYGON (((2.00000 3.00000, 2.00000 2.000...
        3       NaN       2.0  POLYGON ((3.00000 5.00000, 5.00000 5.00000, 5....

        >>> df1.overlay(df2, how='difference')
                                                geometry  df1_data
        0  POLYGON ((2.00000 0.00000, 0.00000 0.00000, 0....         1
        1  MULTIPOLYGON (((3.00000 4.00000, 3.00000 3.000...         2

        >>> df1.overlay(df2, how='identity')
        df1_data  df2_data                                           geometry
        0       1.0       1.0  POLYGON ((2.00000 2.00000, 2.00000 1.00000, 1....
        1       2.0       1.0  POLYGON ((2.00000 2.00000, 2.00000 3.00000, 3....
        2       2.0       2.0  POLYGON ((4.00000 4.00000, 4.00000 3.00000, 3....
        3       1.0       NaN  POLYGON ((2.00000 0.00000, 0.00000 0.00000, 0....
        4       2.0       NaN  MULTIPOLYGON (((3.00000 4.00000, 3.00000 3.000...

        See also
        --------
        GeoDataFrame.sjoin : spatial join
        overlay : equivalent top-level function

        Notes
        -----
        Every operation in GeoPandas is planar, i.e. the potential third
        dimension is not taken into account.
        )r  r  
make_valid)rd   overlay)r=   r  r  r  r  r   r   r    r  M	  s    X
zGeoDataFrame.overlay)N)FFN)F)NN)NN)rt   NNTNNN)r~   FFF)r~   FF)F)Nr   N)NNN)NNN)NNFF)NNF)r   )T)r   FNr   )N)Nr   TNTFT)NFN)Tr   )Nr   FNNN)r  Nr   r  NF)F)r   NT)F__name__
__module____qualname____doc__r   r   Z_internal_namessetZ_internal_names_setr,   r4   rA   rG   rN   propertyr   r<   rZ   r#   setterr`   classmethodrb   rh   rs   r}   r   ri   r   r   r   r   r   r   r   r   r   r   r   rL   r   r   r   r'   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   rd   ZplottingZGeoplotAccessorr  r   r  r  r  r  r  __classcell__r   r   r>   r    r   H   s   3F
m
,
*

2V       T 
a
!
l
 
F 
=
^
O
U
&&

       
 v      
H
			
O      
 
7r   Fc                 C   s&   |rt dt| }|j||d|dS )NzGCan't do inplace setting when converting from DataFrame to GeoDataFrameF)rU   r/   r#   )r5   r   r<   )r=   rM   rU   r/   r#   Zgfr   r   r    _dataframe_set_geometry	  s    r  )N)FFN)-r   r   numpyr(   Zpandasr   Zshapely.errorsr   r   r   Zpandas.core.accessorr   Zshapely.geometryr   r   Zshapely.geometry.baser   Zpyprojr   Zgeopandas.arrayr	   r
   r   r   r   Zgeopandas.baser   r   Zgeopandas.geoseriesr   Zgeopandas.iord   Zgeopandas.explorer   r   r   r0   Z
_decoratorr   r!   r+   r6   r   r  r<   r   r   r   r    <module>   sR   
                  t

