2

我正在使用 Google Refine 对带有 Nominatim API 请求的地址进行地理编码,正如这篇很棒的帖子https://opensas.wordpress.com/2013/06/30/using-openrefine-to-geocode-your-data-using-中所建议的那样google-and-openstreetmap-api/

一切正常:这里有两个样本......

http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q=Via%20Pietro%20Paleocapa%2073,Alzano%20Lombardo,Italia

生产

[{"place_id":"55017260","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"22565087","boundingbox":["45.7324335","45.736092","9.7222512","9.7235157"],"lat":"45.7343899","lon":"9.7231855","display_name":"Via Pietro Paleocapa, Alzano Lombardo, BG, Lombardy, 24027, Italy","class":"highway","type":"unclassified","importance":0.6}]

http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q=Via%20Cernaia%2020,%20Torino%20,%20Italia

生产

[{"place_id":"24085209","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"node","osm_id":"2334729647","boundingbox":["45.0715728","45.0715728","7.6742348","7.6742348"],"lat":"45.0715728","lon":"7.6742348","display_name":"20, Via Cernaia, Quadrilatero Romano, Circoscrizione 1, Turin, TO, Piemont, 10122, Italy","class":"place","type":"house","importance":0.201}]

不同之处在于第一个响应具有“osm_type”:“way”类型,而第二个响应具有“osm_type”:“node”类型。

我只对有关“osm_type”:“node”的响应感兴趣,对于这些我想提取 lat 和 lon 值。

我不知道如何在 Google Refine 中使用 GREL 提取它们.....有什么建议吗?

如果有用的话,我还可以获取 XML 中的响应……这是你的请求

http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q=Via%20Pietro%20Paleocapa%2073,Alzano%20Lombardo,Italia&format=xml

http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q=Via%20Cernaia%2020,%20Torino%20,%20Italia&format=xml
4

2 回答 2

3

您可以通过多种方式解决此问题,但基本步骤是提取 osm_type。鉴于您在此处发布的 JSON,GREL 将是:

value.parseJson()[0].osm_type

一种方法是基于该值创建一个列,然后使用 Facet 过滤到该新列中的值为“节点”的那些。

或者,您可以使用“if”将这些步骤组合在一个 GREL 语句中:

if(value.parseJson()[0].osm_type=="node",value.parseJson()[0].lat,"")

如果 osm_type 等于 'node' 则提取纬度,否则在单元格中放置一个空字符串。

于 2015-05-19T13:26:55.747 回答
1

对欧文公式稍作调整可以消除一些冗余:

with(value.parseJson()[0], place, if(place.osm_type=='node',place.lat,''))

这不是一个很大的节省,但它是一种了解表达式何时变得更长和更复杂的好方法。控制函数将with值分配给您以后可以使用的变量。

于 2015-05-19T18:54:10.533 回答