o
    ÔèFhÄ  ã                   @   sd   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ dZG dd	„ d	eƒZd
S )é    )Úpartial)Ú	urlencode)ÚGeocoderQueryError)ÚDEFAULT_SENTINELÚGeocoder©ÚLocation)Úlogger)ÚDataBCc                       s\   e Zd ZdZdZdeededddœ‡ fdd„
Zdd	d
dedœdd„Zdd„ Zdd„ Z	‡  Z
S )r
   z­Geocoder using the Physical Address Geocoder from DataBC.

    Documentation at:
        https://github.com/bcgov/ols-geocoder/blob/gh-pages/geocoder-developer-guide.md
    z/addresses.geojsonNzgeocoder.api.gov.bc.ca)ÚschemeÚtimeoutÚproxiesÚ
user_agentÚssl_contextÚadapter_factoryÚdomainc                   s0   t ƒ j||||||d� d| j|| jf | _dS )a   

        :param str scheme:
            See :attr:`geopy.geocoders.options.default_scheme`.

        :param int timeout:
            See :attr:`geopy.geocoders.options.default_timeout`.

        :param dict proxies:
            See :attr:`geopy.geocoders.options.default_proxies`.

        :param str user_agent:
            See :attr:`geopy.geocoders.options.default_user_agent`.

        :type ssl_context: :class:`ssl.SSLContext`
        :param ssl_context:
            See :attr:`geopy.geocoders.options.default_ssl_context`.

        :param callable adapter_factory:
            See :attr:`geopy.geocoders.options.default_adapter_factory`.

            .. versionadded:: 2.0

        :param str domain: base api domain

            .. versionadded:: 2.4
        )r   r   r   r   r   r   z	%s://%s%sN)ÚsuperÚ__init__r   Úgeocode_pathÚapi)Úselfr   r   r   r   r   r   r   ©Ú	__class__© úO/var/www/html/loop/nvenv/lib/python3.10/site-packages/geopy/geocoders/databc.pyr      s   &úzDataBC.__init__é   r   ÚanyT)Úmax_resultsÚset_backÚlocation_descriptorÚexactly_oner   c          
      C   s„   d|i}|dkr||d< |dvrt dƒ‚||d< |rd}||d< d	 | jt|ƒf¡}t d
| jj|¡ t| j	|d�}	| j
||	|d�S )a~  
        Return a location point by address.

        :param str query: The address or query you wish to geocode.

        :param int max_results: The maximum number of resutls to request.

        :param float set_back: The distance to move the accessPoint away
            from the curb (in meters) and towards the interior of the parcel.
            location_descriptor must be set to accessPoint for set_back to
            take effect.

        :param str location_descriptor: The type of point requested. It
            can be any, accessPoint, frontDoorPoint, parcelPoint,
            rooftopPoint and routingPoint.

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :rtype: ``None``, :class:`geopy.location.Location` or a list of them, if
            ``exactly_one=False``.
        ÚaddressStringr   ÚsetBack)r   ÚaccessPointÚfrontDoorPointÚparcelPointÚrooftopPointÚroutingPointz You did not provided a location_descriptor the webservice can consume. It should be any, accessPoint, frontDoorPoint, parcelPoint, rooftopPoint or routingPoint.ÚlocationDescriptoré   Ú
maxResultsú?z%s.geocode: %s)r    )r   )r   Újoinr   r   r	   Údebugr   Ú__name__r   Ú_parse_jsonÚ_call_geocoder)
r   Úqueryr   r   r   r    r   ÚparamsÚurlÚcallbackr   r   r   ÚgeocodeE   s   %ÿzDataBC.geocodec                 C   sB   t |d ƒsd S g }|d D ]
}| |  |¡¡ q|r|d S |S )NÚfeaturesr   )ÚlenÚappendÚ_parse_feature)r   Úresponser    ÚgeocodedÚfeaturer   r   r   r/   ‚   s   zDataBC._parse_jsonc                 C   s0   |d }|d d }t |d |d |d f|ƒS )NÚ
propertiesÚgeometryÚcoordinatesÚfullAddressr)   r   r   )r   r<   r=   r?   r   r   r   r9   �   s   þzDataBC._parse_feature)r.   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r5   r/   r9   Ú__classcell__r   r   r   r   r
      s&    ÷4ø=r
   N)Ú	functoolsr   Úurllib.parser   Ú	geopy.excr   Úgeopy.geocoders.baser   r   Úgeopy.locationr   Ú
geopy.utilr	   Ú__all__r
   r   r   r   r   Ú<module>   s    