
    h                     V    d dl Z d dlmZ d dlZd dlmZ d dlZd Zd	dZ	d	dZ
d Zd Zy)
    N)defaultdict)Pointc                 @    ddl }| |j                  j                  k(  ryy)z
    Amount of time to wait between requests to a geocoding API, for providers
    that specify rate limits in their terms of service.
    r   N   )geopy.geocoders	geocoders	Nominatim)providergeopys     L/var/www/html/immo/lib/python3.12/site-packages/geopandas/tools/geocoding.py_get_throttle_timer      s!    
  5??,,,    c                 >    |d}t        |      }t        | d||fi |S )ab  
    Geocode a set of strings and get a GeoDataFrame of the resulting points.

    Parameters
    ----------
    strings : list or Series of addresses to geocode
    provider : str or geopy.geocoder
        Specifies geocoding service to use. If none is provided,
        will use 'photon' (see the Photon's terms of service at:
        https://photon.komoot.io).

        Either the string name used by geopy (as specified in
        geopy.geocoders.SERVICE_TO_GEOCODER) or a geopy Geocoder instance
        (e.g., geopy.geocoders.Photon) may be used.

        Some providers require additional arguments such as access keys
        See each geocoder's specific parameters in geopy.geocoders

    Notes
    -----
    Ensure proper use of the results by consulting the Terms of Service for
    your provider.

    Geocoding requires geopy. Install it using 'pip install geopy'. See also
    https://github.com/geopy/geopy

    Examples
    --------
    >>> df = geopandas.tools.geocode(  # doctest: +SKIP
    ...         ["boston, ma", "1600 pennsylvania ave. washington, dc"]
    ...     )
    >>> df  # doctest: +SKIP
                        geometry                                            address
    0  POINT (-71.05863 42.35899)                          Boston, MA, United States
    1  POINT (-77.03651 38.89766)  1600 Pennsylvania Ave NW, Washington, DC 20006...
    photonTr   _query)stringsr
   kwargsthrottle_times       r   geocoder      s0    J &x0M'4=CFCCr   c                 >    |d}t        |      }t        | d||fi |S )a  
    Reverse geocode a set of points and get a GeoDataFrame of the resulting
    addresses.

    The points

    Parameters
    ----------
    points : list or Series of Shapely Point objects.
        x coordinate is longitude
        y coordinate is latitude
    provider : str or geopy.geocoder (opt)
        Specifies geocoding service to use. If none is provided,
        will use 'photon' (see the Photon's terms of service at:
        https://photon.komoot.io).

        Either the string name used by geopy (as specified in
        geopy.geocoders.SERVICE_TO_GEOCODER) or a geopy Geocoder instance
        (e.g., geopy.geocoders.Photon) may be used.

        Some providers require additional arguments such as access keys
        See each geocoder's specific parameters in geopy.geocoders

    Notes
    -----
    Ensure proper use of the results by consulting the Terms of Service for
    your provider.

    Reverse geocoding requires geopy. Install it using 'pip install geopy'.
    See also https://github.com/geopy/geopy

    Examples
    --------
    >>> from shapely.geometry import Point
    >>> df = geopandas.tools.reverse_geocode(  # doctest: +SKIP
    ...     [Point(-71.0594869, 42.3584697), Point(-77.0365305, 38.8977332)]
    ... )
    >>> df  # doctest: +SKIP
                         geometry                                            address
    0  POINT (-71.05941 42.35837)       29 Court Sq, Boston, MA 02108, United States
    1  POINT (-77.03641 38.89766)  1600 Pennsylvania Ave NW, Washington, DC 20006...
    r   Fr   )pointsr
   r   r   s       r   reverse_geocoder   E   s0    V &x0M&%=CFCCr   c                 H   ddl m} ddlm} |r0t	        | t
        j                        sEt        j                  |       } n/t	        | t        j                        st        j                  |       } t	        |t              r ||      } |di |}i }| j                         D ]^  \  }	}
	 |r|j                  |
      ||	<   n,|j                  |
j                  |
j                  fd      ||	<   t!        j"                  |       ` t%        |      }|S # |t        f$ r d||	<   Y 6w xY w)Nr   )get_geocoder_for_service)GeocoderQueryErrorT)exactly_one)NN )r   r   geopy.geocoders.baser   
isinstancepdSeries	geopandas	GeoSeriesstritemsr   reverseyx
ValueErrortimesleep_prepare_geocode_result)dataforwardr
   r   r   r   r   coderresultsisdfs               r   r   r   w   s    87$		*99T?D$	 3 34&&t,D(C +H5vEG

 "1	&"]]1-
"]]ACC:4]H
 	

=!" 
!	)BI #J/ 	&%GAJ	&s   'ADD! D!c                 `   t        t              }g }| j                         D ]q  \  }}|t               }d}n$|\  }}|t               }nt        |d   |d         }|d   j	                  |       |d   j	                  |       |j	                  |       s t        j                  ||d      }|S )zConvert the geocode results to a GeoDataFrame.

    Takes a dict where keys are index entries, values are tuples containing:
    (address, (lat, lon))

    Nr   r   geometryaddressz	EPSG:4326)indexcrs)r   listr&   r   appendr#   GeoDataFrame)	r1   dr8   r2   r3   pr7   locr4   s	            r   r-   r-      s     	DAE 19AG LGS {G#a&#a&)	*Q	)G$Q!$ 
		K	@BIr   )N)r+   collectionsr   pandasr!   shapely.geometryr   r#   r   r   r   r   r-   r   r   r   <module>rC      s1     #  " )DX/Dd>r   