我使用geonames API来验证一个“字符串”是否是一个位置/位置。下面是我的代码片段。
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正如你所看到的,我在搜索的时候添加了一个印度尼西亚的边框。但令我惊讶的是,这个代码的结果是“真”,我们都知道波尔多位于法国。我的密码有什么问题吗?
发布于 2017-07-06 08:13:16
例如,不要使用坐标包围框,而是使用国家代码:
result = sa.query('bordeaux').country('id').execute()不返回任何结果,而:
result = sa.query('jakarta').country('id').execute()返回一些适当的结果,如下所示:
result = sa.query('bordeaux').country('fr').execute()还包括:
result = sa.query('bordeaux').country('us').execute()更新:
进行了一些研究,而geonames_rdf库没有正确地将边界框参数转换为HTTP参数--它应用了一个参数“东西、南、北”,而这些参数都应该是单独的值。
要解决这个问题,在c:\python27\lib\site-packages\geonames\adapters\base.py,更改中:
def east_west_north_south_box(self, value):
return self.set_string_parameter('east,west,north,south', value)to (为我的简单测试工作):
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就个人而言,使用国名似乎比使用相当粗糙的边框更可取。
https://stackoverflow.com/questions/44940721
复制相似问题