Yahoo! GeoPlanet and YQL
Friday, November 21st, 2008On October 28, 2008, Yahoo! announced the launch of several components of the Yahoo! Open Strategy (Y!OS). Among these was the Yahoo! Query Language (YQL), a web service that enables developers to query, filter, and combine data across multiple Yahoo! web services using a SQL-like syntax. The GeoPlanet Web Service has been integrated into YQL, allowing users to take advantage of place in a number of different ways. Web Services that return place names can be used to generate WOEIDs. The GeoPlanet Web Service can be used to get place names needed by other web services from WOEIDs. The possibilities are endless!
A great place to start exploring YQL is the YQL Console. This web application allows developers to experiment with YQL queries and create URLs they can then embed in their own web applications. More information about YQL is available on the Yahoo! Developer Network YQL website.
YQL in a nutshell
YQL represents web service collections as tables with primary and secondary keys representing collection filters and data fields representing each of the collection’s response elements. The YQL DESC verb describes a table, including its primary key, other supported input fields, the output fields, and an example query. The YQL SELECT verb selects specific data fields (response elements) from a table (collection) using a key (filter).
GeoPlanet collections and resources are represented by eight YQL tables.
| Collection | Table |
|---|---|
| /places | geo.places |
| /place | geo.places |
| /place/…/ancestors | geo.places.ancestors |
| /place/…/belongtos | geo.places.belongtos |
| /place/…/children | geo.places.children |
| /place/…/neighbors | geo.places.neighbors |
| /place/…/parent | geo.places.parent |
| /place/…/siblings | geo.places.siblings |
| /placetypes | geo.placetypes |
Examples
The following are some examples showing how information from GeoPlanet can be generated using YQL and used in various ways. The basic examples use only the geo tables to return data. The intermediate examples combine various geo tables to return data. The advanced examples combine geo data with data from other Yahoo! web services.
Basics
- Learn about the geo.places table
- desc geo.places
- Determine the WOEID for a place (e.g. SFO)
- select woeid from geo.places where text = “SFO”
- Determine the name of a place known by its WOEID
- select name from geo.places where woeid = 12521721
- Determine the name of the country a place is located in (e.g. Sunnyvale, CA)
- select country from geo.places where text = “Sunnyvale, CA”
Intermediate
- Return just place name and place type name for administrative areas containing a place (Sunnyvale, CA)
- select name,placeTypeName from geo.places.ancestors where descendant_woeid in (select woeid from geo.places where text=”Sunnyvale, CA”)
- Determine the timezone of a place (e.g. SFO)
- select name from geo.places.belongtos where member_woeid in (select woeid from geo.places where text = “SFO”) and placetype = “Time Zone”
- Determine the names of neighboring places (e.g. Sunnyvale, CA)
- select name from geo.places.neighbors where neighbor_woeid in (select woeid from geo.places where text = “Sunnyvale, CA”)
- Determine the Zip Codes in a town (e.g. Sunnyvale, CA)
- select name from geo.places.children where parent_woeid in (select woeid from geo.places where text = “Sunnyvale, CA”) and placetype = “Postal Code”
Advanced
- Determine the WOEID for a user (e.g. me)
- select woeid from geo.places where text in (select location from social.profile where guid = me)
- Determine the timezone for a user (e.g. me)
- select name from geo.places.belongtos where member_woeid in (select woeid from geo.places where text in (select location from social.profile where guid = me)) and placetype = “Time Zone”
- Get weather forecast for a specific place known by its WOEID
- select item.description from weather.forecast where location in (select postal from geo.places where woeid = 12797568)
Summary
YQL is a powerful tool that combines and filters the data provided by many Yahoo! web services in a form that allows developers already familiar with SQL to be productive quickly and effectively. By integrating GeoPlanet with YQL, Yahoo! Geo Technologies has added the value of GeoPlanet’s geo-permanent named place management system to an already powerful service.
Eddie Babcock, Yahoo! Geo Technologies