Navigation auf uzh.ch

Swiss Art Research Infrastructure (SARI)

Adding and Using Geospatial Data Support in Blazegraph Instances

Fig.1: Screenshot of Bilder der Schweiz Online Research Platform where we can search for images that are geographically close to where the drawing of Hotel Bellevue was taken.

Blazegraph DB is a high-performance graph database that is compatible with RDF and SPARQL. At SARI, we use Blazegraph DB in order to store data for all our projects. One important feature that we have recently integrated into our instances of Blazegraph DB is support for geospatial data. Enabling this support adds two prefixes that can be used:

PREFIX geoliteral: <http://www.bigdata.com/rdf/geospatial/literals/v1#>
PREFIX geo: <http://www.bigdata.com/rdf/geospatial#>

In the blazegraph, geospatial data may be presented through one of two data types: 

  • geoliteral:lat-long: A data type that stores the longitude and the latitude in the format [lat]#[long] such that [lat] is the latitude (a double) and [long] is the longitude (a double).
  • geoliteral:lat-lon-time: A data a type that contains coordinates in the format [lat]#[long]#[time] such that [lat] is the latitude (a double),  [long] is the longitude (a double) and [time] is the time in the unix epoch format (a long). This data type is typically used in order to model events.

Enabling geospatial data support allows us to make geospatial SPARQL queries. In particular, we can use such queries to get locations that are within a given perimeter. This can be done as follows: 

SELECT * WHERE {
  #start of query
  SERVICE geo:search {
    ?nearbyplace geo:search [shape] .
    ?nearbyplace geo:predicate [pred] .
    ?nearbyplace geo:searchDatatype [type] .
    ?nearbyplace geo:spatialCircleCenter [center] . 
  # required if [shape] is "inCircle"
    ?nearbyplace geo:spatialCircleRadius [radius] . 
  # required if [shape] is "inCircle", default unit: Kilometers
    ?nearbyplace geo:spatialRectangleSouthWest [sw] . 
  # required if [shape] is "inRectangle"
    ?nearbyplace geo:spatialRectangleNorthEast [ne] . 
  # required if [shape] is "inRectangle"
    ?nearbyplace geo:timeStart [time_start] . 
  # required if [type] is geoliteral:lat-lon-time
    ?nearbyplace geo:timeEnd [time_end] . 
  # required if [type] is geoliteral:lat-lon-time
  }
  #rest of query
}

such that:

  • [shape] is either be "in Circle" or "inRectangle" depending on whether we want the range of the map to cover a rectangular or circular shape.
  • [pred] is the predicate that precedes the entities containing the geographical coordinates.
  • [type] is the entity representing the geographical coordinates (if one of the two default types is used, it should be set to either geoliteral:lat-lon or geoliteral:lat-lon-time)
  • [center] are the coordinates of the center of the circle or rectangle that we are using for the search. The format has to be [lat]#[long] such that [lat] is the latitude (a double) and [long] is the longitude (a double). This line is required if and only if [shape] is set to "inCircle".
  • [radius] is the radius of search in kilometers. This line is required if and only if [shape] is set to "inCircle".
  • [sw] are the coordinates of the southwestern part of the rectangular search area. This line is required if and only if [shape] is set to "inRectangle".
  • [ne] are the coordinates of the northeastern part of the rectangular search area. This line is required if and only if [shape] is set to "inRectangle".
  • [time_start] is the start of the timespan search (a long). This line is required if and only if [type] is set to geoliteral:lat-lon-time.
  • [time_end] is the end of the timespan search (a long). This line is required if and only if [type] is set to geoliteral:lat-lon-time.

For example, in the context of BSO, such a query can be used in order to get images that have been taken near a given image: 

SELECT ?nearbyimg WHERE {
  #beginning of query
<https://resource.swissartresearch.net/artwork/zbz-990113960470205508> crm:P128_carries ?work .
    ?work crm:P138_represents ?place .
    ?place crm:P168_place_is_defined_by ?coords .
  FILTER ( datatype(?coords) = geoliteral:lat-lon) .
  SERVICE geo:search {
    ?nearbyplace geo:search "inCircle" . 
  # circular search
    ?nearbyplace geo:predicate crm:P168_place_is_defined_by . 
  # the coordinate entities have the predicate P168_place_is_defined_by 
    ?nearbyplace geo:searchDatatype geoliteral:lat-lon . 
  # the type we are using is geoliteral:lat-lon
    ?nearbyplace geo:spatialCircleCenter  ?coords . 
  # we set the center of the search area to the coordinates of the image zbz-
  990113960470205508

    ?nearbyplace geo:spatialCircleRadius "50" .
  # the radius in km
  }
    ?nearbyimg crm:P128_carries ?nearbywork .
    ?nearbywork crm:P138_represents ?nearbyplace .
} LIMIT 100

Using this feature, we can leverage geographic data in order to introduce new ways of searching for images and objects in the BSO research portal, thus enhancing the overall search experience. One feature that is already online is the display of images that are geographically close to a given image on the image’s page. Other features could be added in the future, for instance to display artists that worked in geographic proximity to other artists at given moments in time.


Author: Andre Ghattas