Creating map layers with Open Sahara
Open Sahara Server, the open source semantic web server, includes a pluggable API for adding smart search, query and analysis functionality. Open Sahara can be used to analyse and annotate documents from the Internet or intranets. The resulting knowledge can be queried, and Open Sahara can present the query results as feeds, charts, or even overlays on a map. This article will show how to create map overlays.
We will use the OpenLayers javascript library to display a map, and use the Open Sahara REST-based query API to show matching documents as a cluster layer on top of that map. Such a cluster layer is a nice way to show which areas of a region have many matches and which areas have few matches. Knowledge of the OpenLayers javascript library is assumed. The article demonstrates to Open Sahara REST API to represent search results as a map cluster-layer.
Shown below are two samples of map overlays, the first one shows aggregated data for reports of theft and burglary in the city of Eindhoven. The second one does the same, but for accidents. Under the samples you will find a summary of how such functionality can be added to a live Open Sahara Server installation, and how it can be used.
Reports of theft and burglary in Q4 of 2011
Reports of accidents in Q4 of 2011
The code
We are using the Open Sahara Template Query API to get the map overlays. This API can be customized per installation with custom REST-based functions that query the semantic database and/or document store. For our example the following two files need to be added to the tquery/.allfolder in the configuration directory of Open Sahara:
sampleQuery.properties
template=sampleQuery.sparql type=sparql
sampleQuery.sparql
#sampleQuery.sparql
dtStart:com.opensahara.rdf.tquery.DateTimeFactory
dtEnd:com.opensahara.rdf.tquery.DateTimeFactory
type:com.opensahara.rdf.tquery.UriFactory
city:com.opensahara.rdf.tquery.UriFactory
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX search: <http://rdf.opensahara.com/search#>
PREFIX geo: <http://rdf.opensahara.com/type/geo/>
SELECT ?id ?loc
WHERE {
?uri a $type .
?id <os:prop/analysis/refEntity> ?uri .
?id a <os:class/AnalysisResults> .
?id <http://purl.org/dc/terms/issued> ?issued .
FILTER (?issued >= $dtStart
&& ?issued < $dtEnd) .
?id <os:prop/analysis/refEntity> ?ref .
?ref <os:prop/loc/partOf> $city .
?ref <os:prop/loc/geo> ?loc
}
The sampleQuery.propertiesfile declares the API function sampleQuery as being a parametrized SPARQL query. The sampleQuery.sparqlcontains the real functionality. It declares the parameters dtStart, dtEnd, type, and city. These parameters are used inside a sparql query to search for all documents that are published between the specified dates, reference a named entity of the provided type, and reference a location that is known to be part of the specified city. For matching documents the REST function will return the geospatial whereabouts of the found location(s), and the id of the document.
Open Sahara can output the results of the query in many formats. In order to get a KML map layer, the function should be called with the .kmlextension. The complete URL for this may look like: http://localhost:8080/api/tquery/sampleQuery.kml?cht=plm&geo=loc&pid=id&dtStart=20111001&pid=id&dtEnd=20120101&city=os:os:elem/loc/Eindhoven&type=os:class/StealingNE. The parameter plmasks for a map-layer, and the parameters geoand piddefine that the locand idquery results define the placemark id's and geometries of the resulting KML response. The other parameters are the ones defined in the sampleQuery.sparql template.

Comments
Post new comment