我有一些看起来像这样的非结构化JSON:
{
"Entities": [{
"BeginOffset": 19, "EndOffset": 32, "Score": 2.0,
"Text": "WASHINGTON", "Type": "LOCATION"
}, {
"BeginOffset": 33, "EndOffset": 35, "Score": 1,
"Text": "Ha", "Type": "LOCATION"
}, {
"BeginOffset": 36, "EndOffset": 39, "Score": 2.2,
"Text": "JAN", "Type": "LOCATION"
}],
"File": "sample.txt",
"Line": 11
}
我将其上传到Elasticsearch中以供在Kibana中使用-但是地理标记功能为WASHINGTON
提供了西澳州的坐标,而不是我们尊敬的首都哥伦比亚特区。我需要直流坐标。
上面的JSON全部包含WASHINGTON
-我想将每个WASHINGTON
更改为District of Columbia
。我正在使用Google Maps API对JSON中的位置进行地理标记:
if str(json_package['document']['Entities'][0]['Type']) == "LOCATION":
geocode_result = gmaps.geocode(
json_package['document'] ['Entities'][0]['Text'])
lat_long = {
'lat': geocode_result[0]['geometry']['location']['lat'],
'lon': geocode_result[0]['geometry']['location']['lng']
}
# print(lat_long)
该如何更新?上面的示例显示了如何将lng
的所有实例更改为lon
,但是同一件事不适用于城市。我去了off this link
我还意识到,更改文字必须在实际的地理编码之前进行