Friday 23 June 2017

qgis - Display coordinates of points in DMS format in print composer


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:



  1. Creating new point shapefile and creating points manually at start and endpoint of each polyline.


  2. Open field calculator and create a virtual field "X" containing $x and another containing $Y (Decimals)

  3. 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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...