【问题标题】:How to Retrieve Geographical Data from the US Geological Survey site?如何从美国地质调查局站点检索地理数据?
【发布时间】:2019-12-25 10:57:41
【问题描述】:

USGS 有一个页面供用户进行 GET 查询:

https://nationalmap.gov/epqs/

我尝试填写提供的 4 个字段:

X: -96.808971 // 经度

Y: 32.7792009 // 纬度

单位:英尺

输出:XML

点击“获取海拔”后,我收到一条错误消息:

“此 XML 文件似乎没有任何与之关联的样式信息。文档树如下所示。”

<USGS_Elevation_Point_Query_Service>
<Elevation_Query x="-96.808971" y="32.7792009">
<Data_Source>3DEP 1/3 arc-second</Data_Source>
<Elevation>420.61</Elevation>
<Units>Feet</Units>
</Elevation_Query>
</USGS_Elevation_Point_Query_Service>

他们提供了一个示例 URL GET:

“以下是一个示例 HTTP GET 请求和响应。显示的占位符需要替换为实际值。”

GET pqs.php?x=string&y=string&units=string&output=string HTTP/1.1
Host: nationalmap.gov/epqs/pqs.php

这就是我卡住的地方。

我有 curl 和 urlgrabber。只将它们用于简单的请求。

TIA

【问题讨论】:

  • 如果我在输出字段中选择“JASON”,则会产生更好的响应。
  • 为什么网站软件允许多个标签,而版主会删除它们?我从该网站收到的欢迎信息与严厉的版主不一致。通过删除两个标签,版主正在减少有人回答我的问题的机会。

标签: linux web-services curl


【解决方案1】:
$ curl 'https://nationalmap.gov/epqs/pqs.php?x=-96.808971&y=32.7792009&units=Feet&output=xml'
<?xml version="1.0" encoding="utf-8" ?><USGS_Elevation_Point_Query_Service><Elevation_Query x="-96.808971" y="32.7792009"><Data_Source>3DEP 1/3 arc-second</Data_Source><Elevation>420.61</Elevation><Units>Feet</Units></Elevation_Query></USGS_Elevation_Point_Query_Service>

如果你想美化它,你可以使用php来格式化它,例如:

$ curl 'https://nationalmap.gov/epqs/pqs.php?x=-96.808971&y=32.7792009&units=Feet&output=xml' -s | php -r '$domd=@DOMDocument::loadXML(stream_get_contents(STDIN));$domd->formatOutput=1;echo $domd->saveXML();'
<?xml version="1.0" encoding="utf-8"?>
<USGS_Elevation_Point_Query_Service>
  <Elevation_Query x="-96.808971" y="32.7792009">
    <Data_Source>3DEP 1/3 arc-second</Data_Source>
    <Elevation>420.61</Elevation>
    <Units>Feet</Units>
  </Elevation_Query>
</USGS_Elevation_Point_Query_Service>

或者如果你只想要原始数据,你可以用 PHP 来解析它

curl 'https://nationalmap.gov/epqs/pqs.php?x=-96.808971&y=32.7792009&units=Feet&output=json' -s | php -r '$data=json_decode(stream_get_contents(STDIN));echo json_encode($data->USGS_Elevation_Point_Query_Service->Elevation_Query,-1);'
{
    "x": -96.808971,
    "y": 32.7792009,
    "Data_Source": "3DEP 1/3 arc-second",
    "Elevation": 420.61,
    "Units": "Feet"
}

.. 或者如果你只是想要海拔,

$ curl 'https://nationalmap.gov/epqs/pqs.php?x=-96.808971&y=32.7792009&units=Feet&output=json' -s | php -r '$data=json_decode(stream_get_contents(STDIN));echo $data->USGS_Elevation_Point_Query_Service->Elevation_Query->Elevation;'
420.61

【讨论】:

    猜你喜欢
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多