Page MenuHomePhabricator

Provide way to cast variables to type geo:wktLiteral in WDQS queries
Closed, ResolvedPublic


It would be good to be able to cast calculated variables to type geo:wktLiteral in WDQS SPARQL queries, to allow calculated co-ordinates as well as retrieved ones to be included in map views of WDQS output, etc.

Currently there seems to be no way to do this.

Event Timeline

Jheald created this task.Mar 13 2017, 12:08 PM
Restricted Application added a project: Discovery. · View Herald TranscriptMar 13 2017, 12:08 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Jheald added a comment.EditedMar 13 2017, 12:16 PM

Example case:

I wanted to be able to look at the geographic distribution of property P 3616 by grouping into one-degree-by-one-degree squares, and plotting on a map, colour-coded by the number of instances.

The grouping into one-degree-by-one-degree squares is easy enough, but there seemed to be no good way to then plot the centrepoints of these squares on a map -- i.e. no way to cast the calculated variables to a geo:wktLiteral.

I tried the following (full query in query editor):

BIND(CONCAT("Point(",str(?int_lon)," ",str(?int_lat),")") AS ?string) .

But the string itself, although it looks right in the table display, is not recognised as a pair of plottable co-ordinates.

So I hoped there might be a cast function geo:wktLiteral(), by way of analogy with eg xsd:dateTime():

BIND(geo:wktLiteral(?string) AS ?int_coords)

but back comes the error

"Unknown error: unknown function:"

I also tried appending ^^geo:wktLiteral in various places, eg BIND(?string^^geo:wktLiteral) AS ... but this just returns a syntax error.

Would it be possible to implement some kind of casting mechanism? Or alternatively, is there any way I can do this cast with just the sort of string operations available in SPARQL ?

Trying to get round this, by just plotting the values in a scatterplot, without a map, also failed -- though that's likely to be an issue with the scatterplot routine. (Ticket T160325 opened).

Another case where it could be useful to be able to cast calculated co-ordinates back to a geo:wktLiteral would be to allow AVG() co-ordinates to be calculated and plotted, in cases where SAMPLE() is not sufficient.

Jheald updated the task description. (Show Details)Mar 13 2017, 12:29 PM

I don't think though AVG() and other math functions are defined on coordinates.

Perfect. I would never ever have found that.

That was exactly what was was needed to make the query work. (results).

As for AVG(), no, I think it is not defined over geo:wktLiteral. But so long as one can extract the latitudes and longitudes, AVG() those separately, and then cast the result back into a geo:wktLiteral (which with strdt() is now easy), then one can achieve the same result -- to calculate and display the centroid of a set of points.

The one thing I still don't understand is why, clicking on a point in the map view, the fields are presented top to bottom in the opposite order from the order in which they appear as columns -- but that's a question for a different ticket, I think.

Smalyshev closed this task as Resolved.Mar 13 2017, 11:44 PM
Smalyshev claimed this task.