Re: Geocoding using Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg83778] Re: Geocoding using Mathematica
• From: mcmcclur at unca.edu
• Date: Fri, 30 Nov 2007 05:22:00 -0500 (EST)
• References: <fim82v\$qus\$1@smc.vnet.net>

```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";,
"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="; <>
latString <> "&lng=" <> lngString]

-- Out --
11

The result is a simple string indicating the elevation in
meters.

Have fun,
Mark

```

• Prev by Date: Re: "vector" Map[] / functional outer product?
• Next by Date: Re: Manipulate is sluggish?
• Previous by thread: Re: Geocoding using Mathematica
• Next by thread: Recursive function