In QGIS 2.14.2 I have a series of polylines of which I want the start and endpoint to be labeled with its coordinates in WGS84 (EPSG 4326) like this: 51*15'23.40"N, 5*17'56.58"E
I thought I figured a workaround by:
- Creating new point shapefile and creating points manually at start and endpoint of each polyline.
- Open field calculator and create a virtual field "X" containing xandanothercontainingY (Decimals)
- Label them by X||'\n'||Y
However the field calculator gives me an output like this X:5.26344964931 Y:51.20551633106
How do I display them in DMS format?
Answer
You're in the right direction. What you need to do is use the QGIS expression builder to concatenate a string with the degrees, minutes, seconds, and any symbols you want in between.
This example calculates the $x value, and will work for positive or negative values.
(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) || '"'
You can change the symbol signs, like °, ' and '' to fit any style you need.
Do note though that the resulting field has to be a string.
No comments:
Post a Comment