I substituted the concat(string1,string2,string3)
concatenation method for the || character. When concatenating a complicated expression like this, concat()
is better because it converts NULL values to empty strings. When using ||, if the expression has any mistakes that evaluate to NULL, the whole output is empty, which is very difficult to troubleshoot. I did a bit of additional cleaning up and fixed a few mistakes (see my notes below). It's not perfect yet, but it should give you a starting point for more troubleshooting.
concat(CASE WHEN $x < 0 THEN '-' ELSE '' END,
floor(abs($x)),
'°',
floor(((abs($x)) - floor (abs($x))) * 60),
'`',
substr( tostring((((abs($x)) - floor (abs($x))) * 60) - floor(((abs($x)) - floor(abs($x))) * 60)) * 60, 1, 5),
'`` E')
Notes:
The biggest issue was the '\''
term. I assume the backslash is supposed to escape the single quotation mark, but it wasn't working that way. Instead it was printing a backslash as though the expression was '\'
and then everything after the third single quotation mark was converted into a string.
I couldn't figure out a way to get the single quotation mark into the output, so I gave up and substituted the tick mark: `
If it's important that you have a single quotation mark in there, try playing around with the char(code)
function. It should take a unicode code number and convert it into that symbol. I tried a few different unicode values that should convert to an apostrophe or single quote, and they gave me boxes or square corner brackets. Maybe QGIS uses a different version of unicode than my Google search results, or maybe the preview is just broken.
Another issue was the final term, '" E'"
. I used the same workaround as for the minutes, and just substituted a double tick mark. If you want some single or double quotes in the final output, see my notes above.
concat()
function instead of concatenating with || and see if that helps.