def bbox(self): south = self._bounds.get('southwest', {}).get('lat') north = self._bounds.get('northeast', {}).get('lat') west = self._bounds.get('southwest', {}).get('lng') east = self._bounds.get('northeast', {}).get('lng') if all([south, west, north, east]): return BBox.factory([south, west, north, east]).as_dict
def _build_params(self, location, provider_key, **kwargs): # handle specific case of proximity (aka 'location' for google) bbox = kwargs.get('proximity', '') if bbox: bbox = BBox.factory(bbox) # do not forget to convert bbox to google expectations... bbox = bbox.latlng # define all params = { # required 'query': location, 'key': provider_key, # optional 'location': bbox, 'radius': kwargs.get('radius', ''), 'language': kwargs.get('language', ''), 'minprice': kwargs.get('minprice', ''), 'maxprice': kwargs.get('maxprice', ''), 'type': kwargs.get('type', ''), } # optional, don't send unless needed if 'opennow' in kwargs: params['opennow'] = '' # optional, don't send unless needed if 'pagetoken' in kwargs: params['pagetoken'] = kwargs['pagetoken'] return params
def _build_params(self, location, provider_key, **kwargs): """Will be overridden according to the targetted web service""" base_kwargs = { 'q': location, 'fuzzy': kwargs.get('fuzzy', 0.8), 'username': provider_key, 'maxRows': kwargs.get('maxRows', 1), } # check out for bbox in kwargs bbox = kwargs.pop('proximity', None) if bbox is not None: bbox = BBox.factory(bbox) base_kwargs.update( {'east': bbox.east, 'west': bbox.west, 'north': bbox.north, 'south': bbox.south}) # look out for valid extra kwargs supported_kwargs = set(( 'name', 'name_equals', 'name_startsWith', 'startRow', 'country', 'countryBias', 'continentCode', 'adminCode1', 'adminCode2', 'adminCode3', 'cities', 'featureClass', 'featureCode', 'lang', 'type', 'style', 'isNameRequired', 'tag', 'operator', 'charset', 'east', 'west', 'north', 'south', 'orderby', 'inclBbox', )) found_kwargs = supported_kwargs & set(kwargs.keys()) LOGGER.debug("Adding extra kwargs %s", found_kwargs) # update base kwargs with extra ones base_kwargs.update(dict( [(extra, kwargs[extra]) for extra in found_kwargs] )) return base_kwargs
def test_factory_coordinates_dict(self): bbox = BBox.factory({ 'south': "43.0", 'west': -80.5, 'north': "43.6", 'east': -80.0 }) assert bbox.latlng == [43.3, -80.25]
def test_factory_latlng_dict(self): bbox = BBox.factory({'lat': 43.0, 'lng': "-80.0"}) assert BBox.DEGREES_TOLERANCE == 0.5 assert bbox.south == 42.5 assert bbox.north == 43.5 assert bbox.west == -80.5 assert bbox.east == -79.5 assert bbox.latlng == [43.0, -80.0]
def test_side_attributes(self): bbox = BBox.factory([-80.0, 43.0]) assert bbox.lat == -80.0 assert bbox.lng == 43.0 assert bbox.latitude == -80.0 assert bbox.longitude == 43.0 assert bbox.latlng == [-80.0, 43.0] assert bbox.xy == [43.0, -80.0]
def bbox(self): extent = self._properties.get('extent') if extent and all(extent): west = extent[0] north = extent[1] east = extent[2] south = extent[3] return BBox.factory([south, west, north, east]).as_dict
def bbox(self): viewport = self.raw.get('viewport', {}) if viewport: bbox = { 'south': viewport.get('btmRightPoint')['lon'], 'west': viewport.get('btmRightPoint')['lat'], 'north': viewport.get('topLeftPoint')['lon'], 'east': viewport.get('topLeftPoint')['lat'], } return BBox.factory(bbox).as_dict
def test_dict_output(self): bbox = BBox.factory({'bbox': [-80.5, 43.0, -80.0, 43.6]}) assert bbox.as_dict == { 'northeast': [43.6, -80.0], 'southwest': [43.0, -80.5] }
def test_factory_bbox_dict(self): bbox = BBox.factory({'bbox': [-80.5, "43.0", "-80.0", 43.6]}) assert bbox.latlng == [43.3, -80.25]
def test_factory_error_dict(self): with pytest.raises(ValueError): BBox.factory({'dummy': 43.0})
def bbox(self): return BBox.factory(self.latlng).as_dict
def test_factory_bounds_dict(self): bbox = BBox.factory({ 'southwest': [43.0, -80.5], 'northeast': ["43.6", "-80.0"] }) assert bbox.latlng == [43.3, -80.25]
def test_factory_bounds_list(self): bbox = BBox.factory([-80.5, "43.0", "-80.0", 43.6]) assert bbox.latlng == [43.3, -80.25]
def test_factory_error_list(self): with pytest.raises(ValueError): BBox.factory([1, 2, 3])
def test_factory_latlng_list(self): bbox = BBox.factory(["-80.0", "43.0"]) assert bbox.latlng == [-80.0, 43.0]