如何从美国地质调查局网站检索地理数据?

How to Retrieve Geographical Data from the US Geological Survey site?

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

https://nationalmap.gov/epqs/

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

X: -96.808971 // 经度

Y: 32.7792009 // 纬度

单位:英尺

输出:XML

点击 "Get Elevation" 后,我收到一条错误消息:

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

<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:

"The following is a sample HTTP GET request and response. The placeholders shown need to be replaced with actual values."

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

这就是我卡住的地方。

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

TIA

$ 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