Following on from the last update concerning the GSTAR web services, the final pieces of infrastructure for the case studies and demonstrator are nearly complete. Building on the API, a GeoJSON output format has been added so that results from GeoSPARQL queries can a) be accessed via a simple URL as with all other outputs and b) visualised using a web map or indeed any platform which can consume GeoJSON.
I had assumed this last element would be straightforward, after all, plotting results on a map is just one of those things one would expect from some geospatial resource. But a couple of hurdles presented themselves.
Consider me slapped. But the triple store is doing exactly as asked, outputting a JSON version of the query results, whatever form they may be in. So I needed an extra step to produce a proper GeoJSON output in which geometries are represented as JSON arrays rather than WKT.
This inclusion of a CRS URI element in a geo:wktLiteral node is problematic for systems expecting a plain old WKT string in which the first element is the geometry type. The overall node structure of a feature geometry when represented in RDF is as follows, comprising the three elements: CRS, WKT + Datatype.
More generally speaking, it has been noted by the research community (for example by a number of contributors to the Linked Geosptial Data event I attended) that this compound approach is unhelpful and somewhat at odds with the usual approach to semantic structures in which each assertion is represented as a discrete triple. But currently, this is what we have, so that’s that.
Anyway, the solution was actually rather low tech. One of the only Triple Stores to natively support GeoJSON output is Strabon, but the Triple Store selected for use in the GSTAR project is Parliament. So it was necessary to investigate suitable approaches using the platforms in use. A quick look at the Strabon source code (available online under the Mozilla Public License v2.0) revealed an elegantly simple solution. Taking the same example used above, it is clear that there is a pattern to the structure which, with some judicious use of basic Java string functions, can be used to clean up the string and extract the individual components.
Firstly, the EPSG code for the CRS can be extracted by first checking to see if the string begins with a < character, indicating there is a URI present. If so, the EPSG code will be the last element of the URI, appended to the base URI for the namespace. Secondly, the WKT serialisation itself will follow the closing > for the CRS URI tag. These marker elements used to get indices used for substrings are shown in green, the EPSG code shown in blue and the WKT geometry shown in red.
Having resolved the WKT issue, the only remaining hurdle was to take the processed WKT geometries and output JSON coordinate arrays within a GeoJSON structure, as per the GeoJSON standard. This was accomplished using Jackson to manipulate the JSON data combined with geojson-jackson to fuse the JSON and GeoJSON elements. This made it relatively easy to take the Query Results Json Format data and transform it into GeoJSON.
This extra output format has now been added to the Sparqlr API so GeoJSON can be returned for the results of any query containing spatial data.
The final pieces of the puzzle are the demonstrator interface and case study queries showing the capabilities of such resources. The former comprises a web based interface including some Seneschal widgets (for selecting controlled vocabulary items to be used in queries) combined with a web map for visualising results and making spatial selections. The latter comprises some interesting prebuilt GeoSPARQL queries based on real world archaeological research questions, visualised using the same web based UI.