GoodRelations and Geo / Location Data

This recipe shows how you can attach and query for location data attached to an office or a store using the GoodRelations vocabulary for e-commerce on the Web of Linked Data.

Overview

GoodRelations itself does not provide properties for geo / position data. Instead, we recommend using existing vocabularies and attaching them to the respective location.
The most relevant GoodRelations classes for this purpose are

  • gr:BusinessEntity, if you want to attach a position to your main office (the legal residence of your business) and
  • gr:LocationOfSalesOrServiceProvisioning for your stores; this is the most important usage.


There exist three popular vocabularies for attaching geo position data to objects; those are

We recommend using either WGS84 or vcard 2006 properties, but when querying data, you have to expect all three patterns.

Patterns

WGS84

Note: As far as I can see from the spec, the WGS84 ontology assumes a range of untyped literals for the geo:lat and geo:long properties.

@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>.

foo:myStore
    a    gr:LocationOfSalesOrServiceProvisioning;
    gr:hasOpeningHoursSpecification foo:workdays, foo:saturdays;
    rdfs:label
       "Best Buy - Woodland, Store 1396"@en;
    geo:location
    [
     geo:lat "48.0802626";
         geo:long "11.6407428".
    ].

vCard 3.0 / 2001 (deprecated)

Note: It is unclear to me whether this pattern is used in the wild; also, while GEO is defined in the original vcard vocabulary, vCard:longitude and vCard:latitude are not defined in the RDF version.

Do not use this pattern for new data.

@prefix vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>.

foo:myStore
    a    gr:LocationOfSalesOrServiceProvisioning;
    gr:hasOpeningHoursSpecification foo:workdays, foo:saturdays;
    rdfs:label
       "Best Buy - Woodland, Store 1396"@en;
    vCard:ADR
            [ ... ];
    vCard:GEO
       [
    vCard:latitude "48.0802626";
    vCard:longitude "11.6407428".
    ].

vCard 2006 (as used by Yahoo)

Note 1:The current 2006 spec says the range of latitude and longitude is xsd:double, but in the wild, we mostly find xsd:float.

Note 2:This vocabulary will soon be superseded by the 2009 update of vcard, which may recommend WGS84 for geo position data.

@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.

foo:myStore a gr:LocationOfSalesOrServiceProvisioning;
   rdfs:label "Hepp Space Ventures Inc."@en;
   vcard:adr [ ... ];
   vcard:geo
       [
    vcard:latitude "48.0802626"^^xsd:double;
        vcard:longitude "11.6407428"^^xsd:double.
       ];
   vcard:tel "+49-89-6004-0"^^xsd:string.

Queries

The following SPARQL query lists the first 50 store locations and their longitude and latitude from a given graph or endpoint, taking into account all of the three patterns described above:

PREFIX geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
PREFIX vc:    <http://www.w3.org/2001/vcard-rdf/3.0#>


SELECT ?store, ?long, ?lat WHERE
{?store a gr:LocationOfSalesOrServiceProvisioning.

  {
    {
           ?store vcard:geo ?y.
           ?y vcard:latitude ?lat.
           ?y vcard:longitude ?long.
          }
UNION
    {
    ?store geo:location ?y.
    ?y geo:lat ?lat.
           ?y geo:long ?long.
          }
UNION
    {
    ?store vc:GEO ?y.
    ?y vc:latitude ?lat.
    ?y vc:longitude ?long.
    }
UNION
# The following is a wrong usage of the geo vocabulary, but may be a common pattern on the Web
     {
    ?store geo:lat ?lat.
          ?store geo:long ?long.
          }
  }
}

You can try it against the public Linked Open Commerce dataspace at http://lod.openlinksw.com/sparql:
Click here for executing the query.


Geospatial Queries with Virtuoso

The OpenLink Virtuoso repository has been augmented by powerful support for spatial queries, e.g. "find all stores that are withing 10 miles of my current position".

See Orri Erling's blogpost at <http://www.openlinksw.com/weblog/oerling/?id=1587>

We will add sample queries shortly.

Resources and References