a
    }ce                     @   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                       sZ   e Zd ZdZdZdeededd fdd
Zddd	d
edddZdd Zdd Z	  Z
S )r
   zGeocoder using the Physical Address Geocoder from DataBC.

    Documentation at:
        http://www.data.gov.bc.ca/dbc/geographic/locate/geocoding.page
    z/pub/geocoder/addresses.geojsonNschemetimeoutproxies
user_agentssl_contextadapter_factoryc                   s4   t  j||||||d 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
        r   zapps.gov.bc.caz	%s://%s%sN)super__init__r   geocode_pathapi)selfr   r   r   r   r   r   domain	__class__ R/var/www/html/django/DPS/env/lib/python3.9/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< |r8d}||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``.
        ZaddressStringr   ZsetBack)r   ZaccessPointZfrontDoorPointZparcelPointZrooftopPointZroutingPointzYou did not provided a location_descriptor the webservice can consume. It should be any, accessPoint, frontDoorPoint, parcelPoint, rooftopPoint or routingPoint.ZlocationDescriptor   Z
maxResults?z%s.geocode: %s)r!   )r   )r   joinr   r   r	   debugr   __name__r   _parse_jsonZ_call_geocoder)
r   queryr   r   r    r!   r   paramsurlcallbackr   r   r   geocodeA   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!   Zgeocodedfeaturer   r   r   r'   ~   s    zDataBC._parse_jsonc                 C   s0   |d }|d d }t |d |d |d f|S )N
propertiesZgeometrycoordinatesZfullAddressr"   r   r   )r   r2   r3   r4   r   r   r   r0      s    zDataBC._parse_feature)r&   
__module____qualname____doc__r   r   r   r,   r'   r0   __classcell__r   r   r   r   r
      s"   0=r
   N)	functoolsr   urllib.parser   Z	geopy.excr   Zgeopy.geocoders.baser   r   Zgeopy.locationr   Z
geopy.utilr	   __all__r
   r   r   r   r   <module>   s   