如何使用 Google Refine 在 Nominatim 响应中仅提取节点 "osm_type":"node" 的经纬度值
How to extract ONLY lat, lon values for node "osm_type":"node" in a Nominatim response using Google Refine
我正在使用 Google Refine 对地址进行地理编码,请求 Nominatim API 按照这篇很棒的 post 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" 的回复感兴趣,对于这些回复,我想提取纬度和经度值。
我不知道如何在 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
您可以通过多种方式解决此问题,但基本步骤是提取 osm_type。鉴于您在此处发布的 JSON,GREL 将是:
value.parseJson()[0].osm_type
一种方法是根据此值创建一个列,然后使用 Facet 过滤到此新列中的值为 'node'.
的列
或者,您可以使用 'if':
将这些步骤组合在一个 GREL 语句中
if(value.parseJson()[0].osm_type=="node",value.parseJson()[0].lat,"")
如果 osm_type 等于 'node',则提取纬度,否则在单元格中放置一个空字符串。
对 Owen 的公式稍作调整可以消除一些冗余:
with(value.parseJson()[0], place, if(place.osm_type=='node',place.lat,''))
这并不是一个很大的节省,但这是了解表达式何时变得更长和更复杂的好方法。 with
控制函数为您以后可以使用的变量赋值。
我正在使用 Google Refine 对地址进行地理编码,请求 Nominatim API 按照这篇很棒的 post 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" 的回复感兴趣,对于这些回复,我想提取纬度和经度值。
我不知道如何在 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
您可以通过多种方式解决此问题,但基本步骤是提取 osm_type。鉴于您在此处发布的 JSON,GREL 将是:
value.parseJson()[0].osm_type
一种方法是根据此值创建一个列,然后使用 Facet 过滤到此新列中的值为 'node'.
的列或者,您可以使用 'if':
将这些步骤组合在一个 GREL 语句中if(value.parseJson()[0].osm_type=="node",value.parseJson()[0].lat,"")
如果 osm_type 等于 'node',则提取纬度,否则在单元格中放置一个空字符串。
对 Owen 的公式稍作调整可以消除一些冗余:
with(value.parseJson()[0], place, if(place.osm_type=='node',place.lat,''))
这并不是一个很大的节省,但这是了解表达式何时变得更长和更复杂的好方法。 with
控制函数为您以后可以使用的变量赋值。