RE: Re: Geocoding using Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg83863] RE: [mg83778] Re: Geocoding using Mathematica
- From: "Hobbs, Sylvia (DPH)" <Sylvia.Hobbs at state.ma.us>
- Date: Mon, 3 Dec 2007 05:41:02 -0500 (EST)
- References: <fim82v$qus$1@smc.vnet.net> <200711301022.FAA05670@smc.vnet.net>
Mark, Yes, that's one way to skin a cat, but not my idea of information on demand. Why parse using pattern matching from outside XML outputs (especially if you have to geocode, say, a million data points) when a possible Mathematica upgrade could incorporate a true geocoding add-in tool as deployed in the statistical functioning architecture of several Business Intelligence software products? (...which will remained unnamed - pace Wolfram Forum moderator) Mapping software companies are forming targeted open source alliances with specialized software companies allowing dynamic links between data subject matter analysis and real-time base location area map changes. This seems like such a timely ad-hoc integration that could save future generations from wasting the best years of their life PARSING DATA!!! Sylvia Hobbs ________________________________ From: mathgroup-adm at smc.vnet.net on behalf of mcmcclur at unca.edu Sent: Fri 11/30/2007 5:22 AM To: mathgroup at smc.vnet.net Subject: [mg83863] [mg83778] Re: Geocoding using Mathematica 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