On Nov 29, 6:33 am, "Coleman, Mark" <Mark.Cole... at LibertyMutual.com>
wrote:
> There are a number of freely available web-based geocoding
> services. Would it possible to invoke them via Mathematica?
Sure, Mathematica has built in features that make this easy.
A good web-based geolocator will allow you to access its
data via a URL with a query string and give you the option
to retrieve it's output as XML. Thus, you can Import from a
URL to symbolic XML, which Mathematica can easily parse
using pattern matching.
geonames.org, for example, returns three results for "The
White House" in Washington, DC.
-- In --
result = Import[
"http://ws.geonames.org/search?q=The+White+House+DC+US&quot;,
"XML"];
#[[3, 1]] & /@ Cases[result,
XMLElement["name", __], Infinity]
-- Out --
{The White House, The White House Visitor Center,
The Hay Adams across from the White House}
It appears that the first of these is the actual Presidential
residence. Here's the latitude and longitude.
-- In --
{latString, lngString} = First /@ Map[#[[3, 1]] &,
{Cases[result, XMLElement["lat", __], Infinity],
Cases[result, XMLElement["lng", __], Infinity]},
{2}]
-- Out --
{38.8976118, -77.0363658}
These results are strings, so be sure to use ToExpression,
if you want to do any numeric work. On the other hand, it
might be nice to leave them as strings. For example, we can
pass them straight back to geonames to get the elevation.
-- In --
Import["http://ws.geonames.org/gtopo30?lat=&quot; <>
latString <> "&lng=" <> lngString]
-- Out --
11
The result is a simple string indicating the elevation in
meters.
Have fun,
Mark