I use geonames API to validate whether a "string" is a place/location. The following is a snippet of my code.
import geonames.adapters.search
sa = geonames.adapters.search.Search(my_user_name)
result = sa.query('bordeaux').east_west_north_south_box([141.021805, 95.009331, 5.904417, -10.941861]).execute()
theresult = set()
for id_, name in result.get_flat_results():
theresult.add(name.lower())
print 'bordeaux' in theresult
As you can see I added a bounding box of Indonesia when I did the search. But to my surprise the result of this code is "True" where we all know that Bordeaux is located in France. Is there something wrong with my code?
Instead of using coordinates bounding box use the country code, for example:
result = sa.query('bordeaux').country('id').execute()
returns no results, whereas:
result = sa.query('jakarta').country('id').execute()
returns some appropriate results, as does:
result = sa.query('bordeaux').country('fr').execute()
and also:
result = sa.query('bordeaux').country('us').execute()
Update:
Did some research and the geonames_rdf library doesn't convert the bounding box parameter into HTTP/REST parameters correctly - it applies a single parameter "east,west,south,north" when they should all be separate values.
To fix this, in c:\python27\lib\site-packages\geonames\adapters\base.py, change:
def east_west_north_south_box(self, value):
return self.set_string_parameter('east,west,north,south', value)
to (works for my simple testing):
def east_west_north_south_box(self, value):
for coord,val in zip(['east','west','north','south'],value):
self.set_string_parameter(coord, val)
return self
Personally, using the country name seems preferable to the rather crude bounding box.