It's always a bit tricky to do this sort of stuff with regular expressions, and especially when it doesn't look like we have a precise grammar to work with, but I think the following approach works:
prefix ogc: <urn:ex:>
select ?lat ?long where {
values ?point { "POINT(48.5 11.7)"^^ogc:wktLiteral }
bind( replace( str(?point), "^[^0-9\\.]*([0-9\\.]+) .*$", "$1" ) as ?long )
bind( replace( str(?point), "^.* ([0-9\\.]+)[^0-9\\.]*$", "$1" ) as ?lat )
}
-------------------
| lat | long |
===================
| "11.7" | "48.5" |
-------------------
The key here is in the regular expressions
"^[^0-9\\.]*([0-9\\.]+) .*$" === <non-number>(number) <anything>
"^.* ([0-9\\.]+)[^0-9\\.]*$" === <anything> (number)<non-number>
Of course, that's really an approximation of number
, since it would match things with multiple dots, but if the data is good, you shouldn't have a problem. If you need to cast these values to numeric types, you can do that kind of cast too:
prefix ogc: <urn:ex:>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select ?lat ?long where {
values ?point { "POINT(48.5 11.7)"^^ogc:wktLiteral }
bind( xsd:decimal( replace( str(?point), "^[^0-9\\.]*([0-9\\.]+) .*$", "$1" )) as ?long )
bind( xsd:decimal( replace( str(?point), "^.* ([0-9\\.]+)[^0-9\\.]*$", "$1" )) as ?lat )
}
---------------
| lat | long |
===============
| 11.7 | 48.5 | # note: no quotation marks; these are numbers
---------------
Note that there are other types of WKT points as well, and this code won't handle them correctly. E.g., some examples from Wikipedia's Well-known text article:
POINT ZM (1 1 5 60)
POINT M (1 1 80)
POINT EMPTY