Skip to content

Instantly share code, notes, and snippets.

@scottlowe
Created November 14, 2017 21:38
Show Gist options
  • Save scottlowe/e8139533f91537b27cf260b200748eaa to your computer and use it in GitHub Desktop.
Save scottlowe/e8139533f91537b27cf260b200748eaa to your computer and use it in GitHub Desktop.
SPARQL syntax for casting a variable (with a string in it) to a literal type
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ospc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX geopos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geosparql: <http://www.opengis.net/ont/geosparql>
CONSTRUCT {
?postcode geosparql:hasGeometry [
a geosparql:Geometry ;
geosparql:asWKT ?wktlit ;
]
}
WHERE {
{
SELECT (STR(?lat) as ?latstr)
(STR(?long) as ?longstr)
(CONCAT("POINT (", ?latstr, " ", ?longstr, ")") as ?wktstr)
(STRDT(?wktstr, geosparql:wktLiteral) as ?wktlit) # <- THERE IT IS!
WHERE
{
GRAPH ?source_postcodes_graph_uri {
?postcode a ospc:PostcodeUnit ;
geopos:lat ?lat ;
geopos:long ?long .
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment