a
    1$e                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZ	d dl
mZmZmZ d dlZd dlZd dlZd dlm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 zd dlZW n ey   dZY n0 dd	lm Z! dd
lm"Z# ddl$m%Z% eej&Z'G dd deZ(ee( d,ddZ)d-ddZ*dd Z+dd Z,dd Z-d.ddZ.dd Z/d/ddZ0d0d d!Z1d1d"d#Z2d$d% Z3d2d&d'Z4G d(d) d)eZ5d*d+ Z6dS )3    N)	lru_cache)ExtensionArrayExtensionDtyperegister_extension_dtype)BaseGeometry)CRSTransformer)AreaOfInterest)query_utm_crs_info   )_compat)_vectorized)_get_sindex_classc                   @   s2   e Zd ZeZdZejZe	dd Z
e	dd ZdS )GeometryDtypegeometryc                 C   sD   t |tstdt|n"|| jkr.|  S td| j|d S )Nz0'construct_from_string' expects a string, got {}z!Cannot construct a '{}' from '{}')
isinstancestr	TypeErrorformattypename__name__)clsstring r   K/var/www/html/django/DPS/env/lib/python3.9/site-packages/geopandas/array.pyconstruct_from_string*   s    

z#GeometryDtype.construct_from_stringc                 C   s   t S N)GeometryArray)r   r   r   r   construct_array_type7   s    z"GeometryDtype.construct_array_typeN)r   
__module____qualname__r   r   r   npnanna_valueclassmethodr   r   r   r   r   r   r   %   s   
r   Fc                 C   s(   |r| j r|j sdS | j |j ks$dS dS )z{
    Check if the projection of both arrays is the same.

    If allow_none is True, empty CRS is treated as the same.
    TFcrs)leftright
allow_noner   r   r   
_check_crs?   s    r+      c                 C   s   | j r8| j  }t|dkr |nd|dd dg}nd}|j rt|j  }t|dkr\|nd|dd dg}nd}tjd||t|d dS )zP
    Raise a CRS mismatch warning with the information on the assigned CRS.
    2    Nz...zCRS mismatch between the CRS of left geometries and the CRS of right geometries.
Use `to_crs()` to reproject one of the input geometries to match the CRS of the other.

Left CRS: {0}
Right CRS: {1}

stacklevel)r'   	to_stringlenjoinwarningswarnr   UserWarning)r(   r)   r0   Zleft_srsZ	right_srsr   r   r   _crs_mismatch_warnM   s     
(
$r7   c                 C   s"   t jr
| S t js| S t| S dS )zY
    Convert internal representation (PyGEOS or Shapely) to external Shapely object.
    N)compatUSE_SHAPELY_20
USE_PYGEOS
vectorizedZ_pygeos_to_shapelygeomr   r   r   _geom_to_shapelyp   s
    r>   c                 C   s"   t jr
| S t js| S t| S dS )zY
    Convert external Shapely object to internal representation (PyGEOS or Shapely).
    N)r8   r9   r:   r;   Z_shapely_to_pygeosr<   r   r   r   _shapely_to_geom|   s
    r?   c                 C   s$   t jrt| tjtfS t| tS d S r   )r8   r:   r   pygeosZGeometryr   r<   r   r   r   _is_scalar_geometry   s    rA   c                 C   s   t t| |dS )a  
    Convert a list or array of shapely objects to a GeometryArray.

    Validates the elements.

    Parameters
    ----------
    data : array-like
        list or array of shapely objects
    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.

    r&   )r   r;   from_shapelydatar'   r   r   r   rB      s    rB   c                 C   s   t | tstdt| jS )zI
    Convert GeometryArray to numpy object array of shapely objects.
    'geoms' must be a GeometryArray)r   r   
ValueErrorr;   
to_shapely_data)geomsr   r   r   rG      s    
rG   c                 C   s   t t| |dS )a  
    Convert a list or array of WKB objects to a GeometryArray.

    Parameters
    ----------
    data : array-like
        list or array of WKB objects
    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.

    r&   )r   r;   from_wkbrC   r   r   r   rJ      s    rJ   c                 K   s*   t | tstdtj| jfd|i|S )zG
    Convert GeometryArray to a numpy object array of WKB objects.
    rE   hex)r   r   rF   r;   to_wkbrH   )rI   rK   kwargsr   r   r   rL      s    
rL   c                 C   s   t t| |dS )a  
    Convert a list or array of WKT objects to a GeometryArray.

    Parameters
    ----------
    data : array-like
        list or array of WKT objects
    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.

    r&   )r   r;   from_wktrC   r   r   r   rN      s    rN   c                 K   s&   t | tstdtj| jfi |S )zG
    Convert GeometryArray to a numpy object array of WKT objects.
    rE   )r   r   rF   r;   to_wktrH   )rI   rM   r   r   r   rO      s    
rO   c                 C   s   t t| |||dS )aN  
    Generate GeometryArray of shapely Point geometries from 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
    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.

    Examples
    --------
    >>> import pandas as pd
    >>> df = pd.DataFrame({'x': [0, 1, 2], 'y': [0, 1, 2], 'z': [0, 1, 2]})
    >>> df
       x  y  z
    0  0  0  0
    1  1  1  1
    2  2  2  2
    >>> geometry = geopandas.points_from_xy(x=[1, 0], y=[0, 1])
    >>> geometry = geopandas.points_from_xy(df['x'], df['y'], df['z'])
    >>> gdf = geopandas.GeoDataFrame(
    ...     df, geometry=geopandas.points_from_xy(df['x'], df['y']))

    Having geographic coordinates:

    >>> df = pd.DataFrame({'longitude': [-140, 0, 123], 'latitude': [-65, 1, 48]})
    >>> df
       longitude  latitude
    0       -140       -65
    1          0         1
    2        123        48
    >>> geometry = geopandas.points_from_xy(df.longitude, df.latitude, crs="EPSG:4326")

    Returns
    -------
    output : GeometryArray
    r&   )r   r;   points_from_xy)xyzr'   r   r   r   rP      s    +rP   c                       sN  e Zd ZdZe ZdddZedd Zedd Z	ed	d
 Z
edd Zejdd Zdd Zedd Zdd Zdd Zdd Zdd Zdd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zd2d3 Zed4d5 Z d6d7 Z!ed8d9 Z"d:d; Z#ed<d= Z$d>d? Z%ddCdDZ&edEdF Z'ddHdIZ(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/e0dXdY Z1dZd[ Z2d\d] Z3d^d_ Z4d`da Z5dbdc Z6ddde Z7dfdg Z8dhdi Z9djdk Z:dldm Z;dndo Z<dpdq Z=drds Z>dtdu Z?dvdw Z@dxdy ZAdzd{ ZBd|d} ZCd~d ZDdd ZEdd ZFdddZGdddZHdddZIdddZJdd ZKdd ZLdd ZMdddZNdddZOdddZPdddZQdddZRdddZSedd ZTedd ZUedd ZVedd ZWedd ZXedd ZYedd ZZedd Z[dd Z\dddZ]dd Z^dddZ_dddZ`dd ZadebdddZcddĄ ZdeddƄ Zed fddɄ	Zfegddd˄Zhdd̈́ Ziegddτ Zjddф ZkdebeldҜddԄZmdebeldҜddքZnddd؄Zoegddڄ Zpddd܄ZqdddބZrdd Zsdd Ztdd Zudd Zv  ZwS )r   zj
    Class wrapping a numpy array of Shapely objects and
    holding the array-based implementations.
    Nc                 C   sb   t || jr|s|j}|j}n(t |tjs4tdn|jdksFtd|| _d | _	|| _d | _
d S )Nzx'data' should be array of geometry objects. Use from_shapely, from_wkb, from_wkt functions to construct a GeometryArray.r   z;'data' should be a 1-dimensional array of geometry objects.)r   	__class__r'   rH   r"   ndarrayr   ndimrF   _crs_sindex)selfrD   r'   r   r   r   __init__  s     
zGeometryArray.__init__c                 C   s   t jdtdd | jS )Na  Accessing the underlying geometries through the `.data` attribute is deprecated and will be removed in GeoPandas 1.0. You can use `np.asarray(..)` or the `to_numpy()` method instead.
Note that if you are using PyGEOS and using this attribute to get an array of PyGEOS geometries, those other methods will always return an array of Shapely geometries. Accessing the underlying PyGEOS geometries directly is deprecated, and you should migrate to use Shapely >= 2.0 instead.   r/   )r4   r5   DeprecationWarningrH   rY   r   r   r   rD   )  s    zGeometryArray.datac                 C   s   | j d u rt | j| _ | j S r   )rX   r   rH   r]   r   r   r   sindex9  s    
zGeometryArray.sindexc                 C   s
   | j duS )a_  Check the existence of the spatial index without generating it.

        Use the `.sindex` attribute on a GeoDataFrame or GeoSeries
        to generate a spatial index if it does not yet exist,
        which may take considerable time based on the underlying index
        implementation.

        Note that the underlying spatial index may not be fully
        initialized until the first use.

        See Also
        ---------
        GeoDataFrame.has_sindex

        Returns
        -------
        bool
            `True` if the spatial index has been generated or
            `False` if not.
        N)rX   r]   r   r   r   
has_sindex?  s    zGeometryArray.has_sindexc                 C   s   | j 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
        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.
        )rW   r]   r   r   r   r'   W  s    zGeometryArray.crsc                 C   s   |sdnt || _dS )zSets the value of the crsN)r   from_user_inputrW   )rY   valuer   r   r   r'   e  s    c                 C   s2   | j r.| j jr.tjdt d jt|d dS )zFCheck CRS and warn if the planar operation is done in a geographic CRSzGeometry is in a geographic CRS. Results from '{}' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
r   r/   N)	r'   is_geographicr4   r5   r   inspectstackfunctionr6   )rY   r0   r   r   r   check_geographic_crsj  s    z"GeometryArray.check_geographic_crsc                 C   s   | j S r   )_dtyper]   r   r   r   dtypew  s    zGeometryArray.dtypec                 C   s
   | j d S )Nr   )shaper]   r   r   r   __len__{  s    zGeometryArray.__len__c                 C   s>   t |tjrt| j| S tjj| |}t	| j| | j
dS Nr&   )r   numbersIntegralr>   rH   pdapiindexerscheck_array_indexerr   r'   )rY   idxr   r   r   __getitem__~  s    zGeometryArray.__getitem__c                 C   sR  t jj| |}t|t jr"|j}t|t jr8|j }t|t	t
jfrPt|}t|tr|t|tjrntd|j| j|< nt|tst|r8t|rd }n$t|trt|gjd }ntdt|tt	t
jfr,t
jdtd}t  |g|d d < W d    n1 s0    Y  || j|< n
|| j|< ntdt| d | _d S )Nz)cannot set a single element with an arrayr   zshould be valid geometryr   rh   z5Value should be either a BaseGeometry or None, got %s)rn   ro   rp   rq   r   Seriesvalues	DataFrameflattenlistr"   rU   rB   r   rl   rm   rF   rH   r   r;   isnar   sliceemptyobjectr8   ignore_shapely2_warningsr   rX   )rY   keyra   Zvalue_arrayr   r   r   __setitem__  s6    




.
zGeometryArray.__setitem__c                 C   s:   t jrt| j| jfS t jr0t| j| jfS | jS d S r   )	r8   r9   shapelyrL   rH   rW   r:   r@   __dict__r]   r   r   r   __getstate__  s
    zGeometryArray.__getstate__c                 C   s   t |ts6t|d }|d | _d | _|| _d | _nJd|v rL|d|d< t	j
rdt|d |d< d|vrtd |d< | j| d S )Nr   r   rD   rH   rW   )r   dictr;   rJ   rW   rX   rH   basepopr8   r:   rB   r   update)rY   staterI   r   r   r   __setstate__  s    

zGeometryArray.__setstate__c                 C   s   t | jS r   )r;   is_validrH   r]   r   r   r   r     s    zGeometryArray.is_validc                 C   s   t | jS r   )r;   is_emptyrH   r]   r   r   r   r     s    zGeometryArray.is_emptyc                 C   s   t | jS r   )r;   	is_simplerH   r]   r   r   r   r     s    zGeometryArray.is_simplec                 C   s   t | jS r   )r;   is_ringrH   r]   r   r   r   r     s    zGeometryArray.is_ringc                 C   s   t | jS r   )r;   	is_closedrH   r]   r   r   r   r     s    zGeometryArray.is_closedc                 C   s   t | jS r   )r;   has_zrH   r]   r   r   r   r     s    zGeometryArray.has_zc                 C   s   t | jS r   )r;   	geom_typerH   r]   r   r   r   r     s    zGeometryArray.geom_typec                 C   s   | j dd t| jS N   r/   )rf   r;   arearH   r]   r   r   r   r     s    zGeometryArray.areac                 C   s   | j dd t| jS r   )rf   r;   lengthrH   r]   r   r   r   r     s    zGeometryArray.lengthc                 C   s   t t| j| jdS rk   )r   r;   boundaryrH   r'   r]   r   r   r   r     s    zGeometryArray.boundaryc                 C   s"   | j dd tt| j| jdS )Nr   r/   r&   )rf   r   r;   centroidrH   r'   r]   r   r   r   r      s    zGeometryArray.centroidc                 C   s   t j| j||dS )N)ratioallow_holes)r;   concave_hullrH   )rY   r   r   r   r   r   r     s    zGeometryArray.concave_hullc                 C   s   t t| j| jdS rk   )r   r;   convex_hullrH   r'   r]   r   r   r   r     s    zGeometryArray.convex_hullc                 C   s   t t| j||| jdS rk   )r   r;   delaunay_trianglesrH   r'   )rY   	toleranceZ
only_edgesr   r   r   r     s    z GeometryArray.delaunay_trianglesc                 C   s   t t| j| jdS rk   )r   r;   enveloperH   r'   r]   r   r   r   r     s    zGeometryArray.envelopec                 C   s   t t| j| jdS rk   )r   r;   minimum_rotated_rectanglerH   r'   r]   r   r   r   r     s    z'GeometryArray.minimum_rotated_rectanglec                 C   s   t t| j| jdS rk   )r   r;   exteriorrH   r'   r]   r   r   r   r     s    zGeometryArray.exteriorc                 C   s   t t| j| jdS rk   )r   r;   extract_unique_pointsrH   r'   r]   r   r   r   r     s    z#GeometryArray.extract_unique_points   round      @c                 C   s    t tj| j||||d| jdS )N)	quad_segs
join_stylemitre_limitr&   )r   r;   offset_curverH   r'   )rY   distancer   r   r   r   r   r   r   "  s    zGeometryArray.offset_curvec                 C   s   t | jS r   )r;   	interiorsrH   r]   r   r   r   r   .  s    zGeometryArray.interiors        c                 C   s   t tj| j|d| jdS )Nr   r&   )r   r;   remove_repeated_pointsrH   r'   )rY   r   r   r   r   r   3  s    z$GeometryArray.remove_repeated_pointsc                 C   s   t t| j| jdS rk   )r   r;   representative_pointrH   r'   r]   r   r   r   r   9  s    z"GeometryArray.representative_pointc                 C   s   t t| j| jdS rk   )r   r;   minimum_bounding_circlerH   r'   r]   r   r   r   r   <  s    z%GeometryArray.minimum_bounding_circlec                 C   s   t | jS r   )r;   minimum_bounding_radiusrH   r]   r   r   r   r   A  s    z%GeometryArray.minimum_bounding_radiusc                 C   s   t t| j| jdS rk   )r   r;   	normalizerH   r'   r]   r   r   r   r   D  s    zGeometryArray.normalizec                 C   s   t t| j| jdS rk   )r   r;   
make_validrH   r'   r]   r   r   r   r   G  s    zGeometryArray.make_validc                 C   s   t t| j| jdS rk   )r   r;   reverserH   r'   r]   r   r   r   r   J  s    zGeometryArray.reversec                 C   s   t t| j|| jdS rk   )r   r;   
segmentizerH   r'   )rY   Zmax_segment_lengthr   r   r   r   M  s    zGeometryArray.segmentizec                 K   sn   t |trTt|t|kr6dt|t|}t|t||sNt||dd |j}tt	| |j|fi |S )Nz5Lengths of inputs do not match. Left: {0}, Right: {1}   r/   )
r   r   r2   r   rF   r+   r7   rH   getattrr;   )opr(   r)   rM   msgr   r   r   _binary_methodW  s    

zGeometryArray._binary_methodc                 C   s   |  d| |S )Ncoversr   rY   otherr   r   r   r   e  s    zGeometryArray.coversc                 C   s   |  d| |S )N
covered_byr   r   r   r   r   r   h  s    zGeometryArray.covered_byc                 C   s   |  d| |S )Ncontainsr   r   r   r   r   r   k  s    zGeometryArray.containsc                 C   s   |  d| |S )Ncrossesr   r   r   r   r   r   n  s    zGeometryArray.crossesc                 C   s   |  d| |S )Ndisjointr   r   r   r   r   r   q  s    zGeometryArray.disjointc                 C   s   |  d| |S )Nequalsr   r   r   r   r   geom_equalst  s    zGeometryArray.geom_equalsc                 C   s   |  d| |S )N
intersectsr   r   r   r   r   r   w  s    zGeometryArray.intersectsc                 C   s   |  d| |S )Noverlapsr   r   r   r   r   r   z  s    zGeometryArray.overlapsc                 C   s   |  d| |S )Ntouchesr   r   r   r   r   r   }  s    zGeometryArray.touchesc                 C   s   |  d| |S )Nwithinr   r   r   r   r   r     s    zGeometryArray.withinc                 C   s   | j d| ||dS )NZequals_exactr   r   )rY   r   r   r   r   r   geom_equals_exact  s    zGeometryArray.geom_equals_exactc                 C   s&   t jdtdd | |dd|   S )NzThe 'geom_almost_equals()' method is deprecated because the name is confusing. The 'geom_equals_exact()' method should be used instead.r[   r/   g      ?
   )r4   r5   FutureWarningr   )rY   r   decimalr   r   r   geom_almost_equals  s    z GeometryArray.geom_almost_equalsc                 C   s   t t| j||||| jdS rk   )r   r;   clip_by_rectrH   r'   )rY   xminyminxmaxymaxr   r   r   r     s    zGeometryArray.clip_by_rectc                 C   s   t | d| || jdS )N
differencer&   r   r   r'   r   r   r   r   r     s    zGeometryArray.differencec                 C   s   t | d| || jdS )Nintersectionr&   r   r   r   r   r   r     s    zGeometryArray.intersectionc                 C   s   t | d| || jdS )Nsymmetric_differencer&   r   r   r   r   r   r     s    z"GeometryArray.symmetric_differencec                 C   s   t | d| || jdS )Nunionr&   r   r   r   r   r   r     s    zGeometryArray.unionc                 C   s   t | d| || jdS )Nshortest_liner&   r   r   r   r   r   r     s    zGeometryArray.shortest_linec                 C   s   | j dd | d| |S )N   r/   r   rf   r   r   r   r   r   r     s    zGeometryArray.distancec                 K   s"   | j dd | jd| |fi |S )Nr   r/   hausdorff_distancer   rY   r   rM   r   r   r   r     s    z GeometryArray.hausdorff_distancec                 K   s"   | j dd | jd| |fi |S )Nr   r/   frechet_distancer   r   r   r   r   r     s    zGeometryArray.frechet_distance   c                 K   sF   t |ttfr|dks"| jdd ttj| j|fd|i|| jdS )Nr   r   r/   
resolutionr&   )	r   intfloatrf   r   r;   bufferrH   r'   )rY   r   r   rM   r   r   r   r     s    zGeometryArray.bufferFc                 C   s(   | j dd ttj| j||d| jdS )Nr   r/   
normalizedr&   )rf   r   r;   interpolaterH   r'   )rY   r   r   r   r   r   r     s
    zGeometryArray.interpolateTc                 C   s   t tj| j||d| jdS )N)preserve_topologyr&   )r   r;   simplifyrH   r'   )rY   r   r   r   r   r   r     s    zGeometryArray.simplifyc                 C   s6   t |trt|}nt |tr$|j}tj| j||dS )Nr   )r   r   r?   r   rH   r;   project)rY   r   r   r   r   r   r     s
    


zGeometryArray.projectc                 C   s   t |tr|j}t| j|S r   )r   r   rH   r;   relater   r   r   r   r     s    
zGeometryArray.relatec                 C   s   t | jS r   )r;   unary_unionrH   r]   r   r   r   r     s    zGeometryArray.unary_unionc                 C   s   t td| j|| jdS )Naffine_transformr&   r   r;   Z_affinity_methodrH   r'   )rY   matrixr   r   r   r     s    zGeometryArray.affine_transformc                 C   s   t td| j|||| jdS )N	translater&   r   )rY   xoffyoffZzoffr   r   r   r     s    zGeometryArray.translatecenterc                 C   s    t tjd| j|||d| jdS )Nrotateoriginuse_radiansr&   r   )rY   Zangler   r   r   r   r   r     s    zGeometryArray.rotate      ?c              	   C   s"   t tjd| j||||d| jdS )Nscale)r   r&   r   )rY   ZxfactZyfactZzfactr   r   r   r   r     s    zGeometryArray.scalec              	   C   s"   t tjd| j||||d| jdS )Nskewr   r&   r   )rY   ZxsZysr   r   r   r   r   r   	  s    zGeometryArray.skewc                 C   s~   | j du rtd|dur&t|}n|dur:t|}ntd| j |rR| S t| j |dd}t| j	|j}t
||dS )u
  Returns a ``GeometryArray`` with all geometries transformed to a new
        coordinate reference system.

        Transform all geometries in a GeometryArray to a different coordinate
        reference system.  The ``crs`` attribute on the current GeometryArray 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
        -------
        GeometryArray

        Examples
        --------
        >>> from shapely.geometry import Point
        >>> from geopandas.array import from_shapely, to_wkt
        >>> a = from_shapely([Point(1, 1), Point(2, 2), Point(3, 3)], crs=4326)
        >>> to_wkt(a)
        array(['POINT (1 1)', 'POINT (2 2)', 'POINT (3 3)'], dtype=object)
        >>> a.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

        >>> a = a.to_crs(3857)
        >>> to_wkt(a)
        array(['POINT (111319.490793 111325.142866)',
               'POINT (222638.981587 222684.208506)',
               'POINT (333958.47238 334111.171402)'], dtype=object)
        >>> a.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

        NzICannot transform naive geometries.  Please set a crs on the object first.zMust pass either crs or epsg.TZ	always_xyr&   )r'   rF   r   r`   	from_epsgZis_exact_sameTransformerFromCRSr;   Z	transformrH   r   )rY   r'   ZepsgtransformerZnew_datar   r   r   to_crs  s    E
zGeometryArray.to_crsWGS 84c           
      C   s   | j std| j\}}}}| j jrBt||g}t||g}ntt| j ddd}|||||\}}}}t||g}||kr|d7 }t||g}|d d d }nt||g}t|t	||||dd}	zt
|	d	 jW S  ty   td
Y n0 dS )uv  Returns the estimated UTM CRS based on the bounds of the dataset.

        .. versionadded:: 0.9

        .. note:: Requires pyproj 3+

        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_commpop")
        ... )
        >>> df.geometry.values.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
        z$crs must be set to estimate UTM CRS.z	EPSG:4326Tr   ih     )Zwest_lon_degreeZsouth_lat_degreeZeast_lon_degreeZnorth_lat_degree)
datum_nameZarea_of_interestr   zUnable to determine UTM CRSN)r'   RuntimeErrortotal_boundsrb   r"   meanr   Ztransform_boundsr
   r	   r   r   code
IndexError)
rY   r   ZminxZminyZmaxxZmaxyZx_centerZy_centerr   Zutm_crs_listr   r   r   estimate_utm_crsk  s:    '	zGeometryArray.estimate_utm_crsc                 C   st   | j |    dk rd| j}| rV| }tj|ttjd}t	
| j| ||< |S t	
| jS nd}t|dS )z8Return the x location of point geometries in a GeoSeriesPointrh   
fill_valuez5x attribute access only provided for Point geometriesN)r   rz   allr   anyr"   	full_liker   r#   r;   Zget_xrH   rF   rY   r|   ZnonemptyZcoordsmessager   r   r   rQ     s    zGeometryArray.xc                 C   st   | j |    dk rd| j}| rV| }tj|ttjd}t	
| j| ||< |S t	
| jS nd}t|dS )z8Return the y location of point geometries in a GeoSeriesr  r  z5y attribute access only provided for Point geometriesN)r   rz   r  r   r	  r"   r
  r   r#   r;   Zget_yrH   rF   r  r   r   r   rR     s    zGeometryArray.yc                 C   st   | j |    dk rd| j}| rV| }tj|ttjd}t	
| j| ||< |S t	
| jS nd}t|dS )z8Return the z location of point geometries in a GeoSeriesr  r  z5z attribute access only provided for Point geometriesN)r   rz   r  r   r	  r"   r
  r   r#   r;   Zget_zrH   rF   r  r   r   r   rS     s    zGeometryArray.zc                 C   s   t | jS r   )r;   boundsrH   r]   r   r   r   r    s    zGeometryArray.boundsc              
   C   s   t | dkr&ttjtjtjtjgS | j}tt|d d df t|d d df t|d d df t|d d df fS )Nr   r   r[   r,   )r2   r"   arrayr#   r  ZnanminZnanmax)rY   br   r   r   r     s    zGeometryArray.total_boundsc                 C   s   | j jS r   )rH   sizer]   r   r   r   r    s    zGeometryArray.sizec                 C   s   | j fS r   )r  r]   r   r   r   ri   
  s    zGeometryArray.shapec                 C   s
   t | jS r   )r2   ri   r]   r   r   r   rV     s    zGeometryArray.ndimc                 O   s   t | j | jdS rk   )r   rH   copyrW   )rY   argsrM   r   r   r   r    s    zGeometryArray.copyc                 C   s   ddl m} |rL|d u s"t|r(d }n$t|tr<t|}nt|sLtd|| j	|||d}|rx|d u rxd |t|< t
|| jdS )Nr   )takez&provide geometry or None as fill value)
allow_fillr  r&   )pandas.api.extensionsr  rn   rz   r   r   r?   rA   r   rH   r   r'   )rY   indicesr  r  r  resultr   r   r   r    s    

zGeometryArray.takec                 C   s   t |rdg}n8t|r"|g}n(t|tr6|| }ntdt|jtj	t
|td}t   t||dd< W d   n1 s0    Y  || j|< | S )zv
        Fill index locations with ``value``.

        ``value`` should be a BaseGeometry or a GeometryArray.
        NzT'value' parameter must be None, a scalar geometry, or a GeoSeries, but you passed a rt   )r;   rz   rA   r   r   r   r   r   r"   r|   r2   r}   r8   r~   r?   rH   )rY   rr   ra   Z	value_arrr   r   r   _fill&  s     



.
zGeometryArray._fillc                 C   sB   |durt d|  }|r&|  }n| }| r>|||S |S )au  
        Fill NA values with geometry (or geometries) or using the specified method.

        Parameters
        ----------
        value : shapely geometry object or GeometryArray
            If a geometry value is passed it is used to fill all missing values.
            Alternatively, an GeometryArray 'value' can be given. It's expected
            that the GeometryArray has the same length as 'self'.

        method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
            Method to use for filling holes in reindexed Series
            pad / ffill: propagate last valid observation forward to next valid
            backfill / bfill: use NEXT valid observation to fill gap

        limit : int, default None
            If method is specified, this is the maximum number of consecutive
            NaN values to forward/backward fill. In other words, if there is
            a gap with more than this number of consecutive NaNs, it will only
            be partially filled. If method is not specified, this is the
            maximum number of entries along the entire axis where NaNs will be
            filled.

        copy : bool, default True
            Whether to make a copy of the data before filling. If False, then
            the original should be modified and no new memory should be allocated.

        Returns
        -------
        GeometryArray
        Nz)fillna with a method is not yet supported)NotImplementedErrorrz   r  r	  r  )rY   ra   methodlimitr  mask
new_valuesr   r   r   fillna?  s     
zGeometryArray.fillnac                 C   s   t |tr|r|  S | S njtjj|rvtjj|svt| }tjj	|}t |tj
rhtj||dS |j|ddS tj| ||dS dS )a  
        Cast to a NumPy array with 'dtype'.

        Parameters
        ----------
        dtype : str or dtype
            Typecode or data-type to which the array is cast.
        copy : bool, default True
            Whether to copy the data, even if not necessary. If False,
            a copy is made only if the old dtype does not match the
            new dtype.

        Returns
        -------
        array : ndarray
            NumPy ndarray with 'dtype' for its dtype.
        rt   F)r  )rh   r  N)r   r   r  rn   ro   typesZis_string_dtypeZis_object_dtyperO   Zpandas_dtypeZStringDtyper  astyper"   )rY   rh   r  Zstring_valuesZpd_dtyper   r   r   r   i  s    
zGeometryArray.astypec                 C   sB   t jrt| jS t jr$t| jS tjdd | jD ddS dS )zI
        Boolean NumPy array indicating if each value is missing
        c                 S   s   g | ]}|d u qS r   r   ).0gr   r   r   
<listcomp>      z&GeometryArray.isna.<locals>.<listcomp>boolrt   N)	r8   r9   r   Z
is_missingrH   r:   r@   r"   r  r]   r   r   r   rz     s
    zGeometryArray.isnadropnac                 C   sL   t | }ddlm}m} ||j|d}|tt|j	 d|j|_|S )z
        Compute a histogram of the counts of non-null values.

        Parameters
        ----------
        dropna : bool, default True
            Don't include counts of NaN

        Returns
        -------
        pd.Series
        r   )Indexru   r&  N)
rL   pandasr(  ru   value_countsrJ   r"   whereindexrz   )rY   r'  rv   r(  ru   r  r   r   r   r*    s    zGeometryArray.value_countsc                 C   s   ddl m} || \}}|S )zwCompute the ExtensionArray of unique values.

        Returns
        -------
        uniques : ExtensionArray
        r   )	factorize)r)  r-  )rY   r-  _Zuniquesr   r   r   unique  s    zGeometryArray.uniquec                 C   s   | j jS r   )rH   nbytesr]   r   r   r   r0    s    zGeometryArray.nbytesr   c                    s   t  ||}| j|_|S )aL  
        Shift values by desired number.

        Newly introduced missing values are filled with
        ``self.dtype.na_value``.

        Parameters
        ----------
        periods : int, default 1
            The number of periods to shift. Negative values are allowed
            for shifting backwards.

        fill_value : object, optional (default None)
            The scalar value to use for newly introduced missing values.
            The default is ``self.dtype.na_value``.

        Returns
        -------
        GeometryArray
            Shifted.

        Notes
        -----
        If ``self`` is empty or ``periods`` is 0, a copy of ``self`` is
        returned.

        If ``periods > len(self)``, then an array of size
        len(self) is returned, with all values filled with
        ``self.dtype.na_value``.
        )supershiftr'   )rY   Zperiodsr  ZshiftedrT   r   r   r2    s    zGeometryArray.shiftc                 C   s   t |tr|g}t|S )a#  
        Construct a new ExtensionArray from a sequence of scalars.

        Parameters
        ----------
        scalars : Sequence
            Each element will be an instance of the scalar type for this
            array, ``cls.dtype.type``.
        dtype : dtype, optional
            Construct for this particular dtype. This should be a Dtype
            compatible with the ExtensionArray.
        copy : boolean, default False
            If True, copy the underlying data.

        Returns
        -------
        ExtensionArray
        )r   r   rB   )r   Zscalarsrh   r  r   r   r   _from_sequence  s    
zGeometryArray._from_sequencec                 C   s   t | }|dfS )as  Return an array and missing value suitable for factorization.

        Returns
        -------
        values : ndarray
            An array suitable for factorization. This should maintain order
            and be a supported dtype (Float64, Int64, UInt64, String, Object).
            By default, the extension array is cast to object dtype.
        na_value : object
            The value in `values` to consider missing. This will be treated
            as NA in the factorization routines, so it will be coded as
            `na_sentinal` and not included in `uniques`. By default,
            ``np.nan`` is used.
        N)rL   )rY   valsr   r   r   _values_for_factorize  s    z#GeometryArray._values_for_factorizec                 C   s   t ||jdS )a  
        Reconstruct an ExtensionArray after factorization.

        Parameters
        ----------
        values : ndarray
            An integer ndarray with the factorized values.
        original : ExtensionArray
            The original ExtensionArray that factorize was called on.

        See Also
        --------
        pandas.factorize
        ExtensionArray.factorize
        r&   )rJ   r'   )r   rv   originalr   r   r   _from_factorized  s    zGeometryArray._from_factorizedc                 C   s   ddl m} | jdkr$tjg ddS | j}| }|  |B }| r|  }t	| d }|jrr| |d  }nt
jdd}|||< n| }|r|j}|d |d  d }	|d |d  d }
|t|	 |
 |	|
g7 }nd	}|||d
}|rd||< |S )a  Return values for sorting.

        Returns
        -------
        ndarray
            The transformed values should maintain the ordering between values
            within the array.

        See Also
        --------
        ExtensionArray.argsort
        r   )_hilbert_distanceZuint32rt   r[   g{Gz?r,   r   N)r   )Zgeopandas.tools.hilbert_curver9  r  r"   r  r   r	  rz   r  Znonzeror   r   r  r   )rY   r9  Z
mask_emptyZ	has_emptyr  rI   r  r=   r   r   r   Z	distancesr   r   r   _values_for_argsort-  s0    

z!GeometryArray._values_for_argsort)skipnareturnc                 C   s   t dd S Nz%geometries have no minimum or maximumr   rY   r;  r   r   r   argminh  s    zGeometryArray.argminc                 C   s   t dd S r=  r>  r?  r   r   r   argmaxk  s    zGeometryArray.argmaxc                    s  |rddl }|jj  du r| jr8| jjr2d qd nt > tjdtd | | 	   dd j
\}}}}W d   n1 s0    Y  d|  krd	krn nNd|  krd	krn n6d
|  krdkrn nd
|  krdkrn nd nd  fddS tS )aO  Formatting function for scalar values.

        This is used in the default '__repr__'. The returned formatting
        function receives instances of your scalar type.

        Parameters
        ----------
        boxed: bool, default False
            An indicated for whether or not your array is being printed
            within a Series, DataFrame, or Index (True), or just by
            itself (False). This may be useful if you want scalar values
            to appear differently within a Series versus on its own (e.g.
            quoted or not).

        Returns
        -------
        Callable[[Any], str]
            A callable that gets instances of the scalar type and
            returns a string. By default, :func:`repr` is used
            when ``boxed=False`` and :func:`str` is used when
            ``boxed=True``.
        r   Nr,   r   ignore)categoryr   iLr   iZ   c                    s   t jj|  dS )N)Zrounding_precision)r   Zwktdumpsr<   	precisionr   r   <lambda>  r$  z*GeometryArray._formatter.<locals>.<lambda>)	geopandasoptionsZdisplay_precisionr'   Zis_projectedr4   catch_warningssimplefilterRuntimeWarningrz   r   repr)rY   ZboxedrI  r   r   r   r   r   rF  r   
_formattern  s>    
>



zGeometryArray._formatterc                 C   s$   t dd |D }t|t|dS )z
        Concatenate multiple array

        Parameters
        ----------
        to_concat : sequence of this type

        Returns
        -------
        ExtensionArray
        c                 S   s   g | ]
}|j qS r   )rH   r!  gar   r   r   r#    r$  z3GeometryArray._concat_same_type.<locals>.<listcomp>r&   )r"   Zconcatenater   _get_common_crs)r   Z	to_concatrD   r   r   r   _concat_same_type  s    zGeometryArray._concat_same_typec                 K   sH   |dks|dkr t t| | S tdt| j d| j d| dd S )Nr	  r  'z' with dtype z does not support reduction ')r   rG   r   r   r   rh   )rY   r   r;  rM   r   r   r   _reduce  s    zGeometryArray._reducec                 C   s   t | S )zj
        The numpy array interface.

        Returns
        -------
        values : numpy array
        )rG   )rY   rh   r   r   r   	__array__  s    zGeometryArray.__array__c                    st   fdd}t |tjtjtjfr&tS }||}t|t|krJtd fddt||D }t	j
|td}|S )Nc                    s8   t | s&t| ts tjj| r&| }n| gt  }|S r   )rA   r   r   rn   ro   r  Zis_list_liker2   )paramZovaluesr]   r   r   convert_values  s    z,GeometryArray._binop.<locals>.convert_valueszLengths must match to comparec                    s   g | ]\}} ||qS r   r   )r!  ar  )r   r   r   r#    r$  z(GeometryArray._binop.<locals>.<listcomp>rt   )r   rn   ru   r(  rw   NotImplementedr2   rF   zipr"   Zasarrayr%  )rY   r   r   rX  ZlvaluesZrvaluesresr   )r   rY   r   _binop  s    	zGeometryArray._binopc                 C   s   |  |tjS r   )r]  operatoreqr   r   r   r   __eq__  s    zGeometryArray.__eq__c                 C   s   |  |tjS r   )r]  r^  ner   r   r   r   __ne__  s    zGeometryArray.__ne__c                 C   sH   t |r<|| jju s,t|| jjs,|du r8|   S dS | |k S )z,
        Return for `item in self`.
        NF)r;   rz   rh   r$   r   r   r	  )rY   itemr   r   r   __contains__  s    

zGeometryArray.__contains__)N)r   r   r   )r   )r   )F)T)F)r   r   r   )r   F)r   r   r   r   )r   r   r   F)NN)r   )FN)NNNT)T)T)r   N)NF)T)T)F)T)N)xr   r    r!   __doc__r   rg   rZ   propertyrD   r^   r_   r'   setterrf   rh   rj   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rQ   rR   rS   r  r   r  ri   rV   r  r  r  r  r   rz   r%  r*  r/  r0  r2  r%   r4  r6  r8  r:  r   r@  rA  rO  rS  rU  rV  r]  r`  rb  rd  __classcell__r   r   r3  r   r     s&  






	.


















	



	




Z
S









*
#  
'
;
7



r   c                 C   s   dd | D } dd | D }dd |D }dd |D }t |dkrHd S t |dkrt |dkrztjd	|d  d
dd |d S td| dd S )Nc                 S   s&   g | ]}|   r|jd u s|qS r   )rz   r  r'   rP  r   r   r   r#    r$  z#_get_common_crs.<locals>.<listcomp>c                 S   s   h | ]
}|j qS r   r&   )r!  Zarrr   r   r   	<setcomp>   r$  z"_get_common_crs.<locals>.<setcomp>c                 S   s   g | ]}|d ur|qS r   r   r!  r'   r   r   r   r#    r$  c                 S   s   g | ]
}|j qS r   )r   rk  r   r   r   r#    r$  r   r   zJCRS not set for some of the concatenation inputs. Setting output's CRS as z$ (the single non-null crs provided).r[   r/   z:Cannot determine common CRS for concatenation inputs, got zH. Use `to_crs()` to transform geometries to the same CRS before merging.)r2   r4   r5   rF   )Zarr_seqZcrs_setZcrs_not_nonenamesr   r   r   rR    s$    
rR  )F)r,   )N)N)F)N)NN)7rl   r^  r4   rc   	functoolsr   numpyr"   r)  rn   r  r   r   r   r   Zshapely.affinityZshapely.geometryZshapely.geometry.baser   Zshapely.opsZshapely.wktZpyprojr   r   Z
pyproj.aoir	   Zpyproj.databaser
   r@   ImportErrorZgeos r   r8   r   r;   r^   r   Zfrom_crsr   r   r+   r7   r>   r?   rA   rB   rG   rJ   rL   rN   rO   rP   r   rR  r   r   r   r   <module>   sb   



#
	

	
	
.         w