Geo-tutorial
From RDFaWiki
PLEASE NOTE THIS IS A WORK IN PROGRESS AND IS NOT YET COMPLETE!
Contents |
Adding Geolocation information to HTML
One frequent request from web authors is to be able to indicate exactly where something is. Obviously we on Earth have a power mechanism in the latitude and longitude system. A precise latitude and longitude (sometimes coupled with an altitude) can express pretty much any location anyone would care about. There are a number of ways to accomplish this. The Basic Geo Location vocabulary is a deceptively simple grammar that is in wide use already. This grammar, when coupled with RDFa, makes it very easy to annotate your existing HTML with location information. Consider the following paragraph from an HTML document:
<p>During our trip we visited the Washington Monument:
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" /></p>
That's a semantically rich statement to an English speaker, but to a computer is more or less gibberish. However, with a couple of simple annotations we can say all sorts of things about that location, about the picture, and about how that location relates to that picture.
Setting up a traditional hyperlink
First, let's connect to the Washington Monument web site (its "Home Page"):
<p>During our trip we visited the
<a href="http://www.nps.gov/wamo/">Washington Monument</a>:
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" /></p>
I now have a selectable connection to information about the monument so my reader can find out more. That's plain old HTML - the stuff we have done for years.
Setting the subject
Let's augment that with some data so a computer looking at this paragraph can learn a little more about what is *meant* by it. To do that, first we need to say what the paragraph is "about":
<p about="http://www.dbpedia.org/resource/Washington_Monument">During our trip we visited the
<a href="http://www.nps.gov/wamo/">Washington Monument</a>:
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" />
</p>
Connecting the subject to a location
Now that we have declared the "subject" of this paragraph, can we connect that subject to some "objects" in meaningful ways? Sure we can! That's the whole point of RDF. First, its location:
<p about="http://www.dbpedia.org/resource/Washington_Monument"
property="geo:lat_long" content="38.8895563,-77.0352546">During our trip we visited the
<a href="http://www.nps.gov/wamo/">Washington Monument</a>:
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" />
</p>
By adding this "property" to the paragraph, we are telling the system something about the subject of that paragraph.
The "property" is a called "lat_long" and it is in a vocabulary called "geo".
It has a value defined by its "content" attribute that is
really only meaningful to computers. A computer that examines this via RDFa will know that the subject
http://www.dbpedia.org/resource/Washington_Monument
has a "lat_long" property with a value of "38.8895563,-77.0352546".
Why would I want to do that? Well, so an RDFa-aware user agent could do nifty things like automatically take me to a map of that location, or find hotels nearby, or tell me the zipcode there... Who knows?
Interpreting vocabulary items
But I know what you are thinking: How does the computer know what "lat_long" means, and therefore how to interpret that value? That's where the vocabulary name comes in. A vocabulary defines, using some fancy notation, a bunch of terms. Smart software can interpret that notation and basically learn how to interpret the values automatically. In this case, we need to tell the system that the "geo" vocabulary is defined somewhere - in other words, map that "prefix" to some value. In the case of the Simple Geo Vocabulary that value is "http://www.w3.org/2003/01/geo/wgs84_pos#". That value, when combined with a term like "lat_long" uniquely identifies the terms definition and the system knows or learns what is meant by the content! (Normally that prefix is defined at the top of the document, but really you can define it anywhere.)
Saying more things about the same subject
We can continue to extend this model, adding more and more meaningful information about our subject. For example, we learned while we were there that the Monument is 555 feet above sea level at its peak. The "geo" vocabulary has a way to express that, but only in meters...
<p about="http://www.dbpedia.org/resource/Washington_Monument"
property="geo:lat_long" content="38.8895563,-77.0352546">During our trip we visited the
<a href="http://www.nps.gov/wamo/">Washington Monument</a>:
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" />
<br />
While taking a tour, we learned it is <span property="geo:alt">169</span> meters tall!
</p>
Notice that in this case I used the "alt" property of the "geo" vocabulary, but I did not specify its value using the
content attribute. RDFa is happy to the content of an element as its "object" so that I don't need to duplicate
information! Sadly, the "geo" vocabulary requires the use of meters for the "alt" property. Since I am American and apparently don't really understand meters, I could also have said:
While taking a tour, we learned it is <span property="geo:alt" content="169">555 feet</span> tall!
In this case, the contents of the span are ignored for RDF purposes - the value of the content attribute is used instead.
Mixing in another vocabulary
By making an additional change I can also show how the picture and the homepage relate to that same subject:
<p about="http://www.dbpedia.org/resource/Washington_Monument"
property="geo:lat_long" content="38.8895563,-77.0352546">During our trip we visited the
<a rel="foaf:homepage" href="http://www.nps.gov/wamo/">Washington Monument</a>:
<span rel="foaf:depiction">
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" />
</span><br />
While taking a tour, we learned it is <span property="geo:alt">169</span> meters tall!
</p>
In this case what I have done is said that the href<code> attribute
of the <code>a element is a the
"homepage" for the subject, and that the image indicated by the src attribute of
the img element is a "depiction" of the subject. Those terms are defined
in the "foaf" vocabulary.
Bringing it all together
The following is a complete example, just to wrap it all up:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<head>
<title>My Summer Vacation</title>
</head>
<body>
<p about="http://www.dbpedia.org/resource/Washington_Monument"
property="geo:lat_long" content="38.8895563,-77.0352546">During our trip we visited the
<a rel="foaf:homepage" href="http://www.nps.gov/wamo/">Washington Monument</a>:
<span rel="foaf:depiction">
<img alt="Washington Monument at Dusk"
src="http://www.american-architecture.info/USA/USA-Washington/Washington_Monument_Dusk_Jan_2006.jpg" />
</span><br />
While taking a tour, we learned it is <span property="geo:alt">169</span> meters tall!
</p>
</body>
</html>
The geo vocabulary
The vocabulary discussed here is best defined at Basic Geo Location vocabulary and in the associated RDF definition at RDF for geo. The vocabulary supports locations as defined by the WGS84 standard - the same standard used by the Global Positioning System, and therefore a good way for computers to understand what is meant by locations. You can look at these documents for lots more information on how to specify locations, and what they really mean. However, just as a quick reference, here are the terms in the vocabulary with some simple definitions:
| Term | Meaning |
|---|---|
| lat | The latitude of a point in decimal notation with 6 significant digits in the range -179.999999 to 179.999999 |
| long | The longitude of a point in decimal notation with 6 significant digits in the range -179.999999 to 179.999999 |
| alt | The altitude of a point in meters in decimal notation relative to sea level (more or less) |
| lat_long | The latitude and longitude of a point in decimal notation, separated by a comma |

