PYTHON 53
QGIS Range / Bearing on line By mike on 28th March 2021 03:40:35 PM
  1. # Three ways to Rome, to get range / bearing of a line
  2. ####
  3. ####
  4.  
  5. ### 1) ALL IN ONE
  6. concat (
  7.         format_number($length / 1800,2),
  8.         ' NM @',
  9.         format_number(angle_at_vertex( $geometry, vertex:=1 ),0),
  10.         ' ',
  11.         if (angle_at_vertex( $geometry, vertex:=1 ) - 180 < 0,
  12.                 format_number(angle_at_vertex( $geometry, vertex:=1 )+180,0),
  13.                 format_number(angle_at_vertex( $geometry, vertex:=1 )-180,0)
  14.                 ),
  15.         '°)'
  16. )
  17.  
  18.  
  19. ### 2) USE ARGUJMENTS
  20. format('%1 NM @ %2/%3°',
  21.         format_number($length / 1800,2),
  22.         format_number(angle_at_vertex( $geometry, vertex:=1 ),0),
  23.         if (angle_at_vertex( $geometry, vertex:=1 ) - 180 < 0,
  24.                 format_number(angle_at_vertex( $geometry, vertex:=1 )+180,0),
  25.                 format_number(angle_at_vertex( $geometry, vertex:=1 )-180,0)
  26.         )
  27. )
  28.  
  29.  
  30.  
  31.  
  32. ### 3) USE A CASE
  33. CASE
  34. WHEN angle_at_vertex( $geometry, vertex:=1 ) > 180 THEN
  35.  
  36. format('%1 NM @ %2/%3°',
  37.         format_number($length / 1800,2),
  38.         format_number(angle_at_vertex( $geometry, vertex:=1 )-180,0),
  39.         format_number(angle_at_vertex( $geometry, vertex:=1 ),0)
  40. )
  41.  
  42. ELSE
  43.  
  44. format('%1 NM @ %2/%3°',
  45.         format_number($length / 1800,2),
  46.         format_number(angle_at_vertex( $geometry, vertex:=1 ),0),
  47.         format_number(angle_at_vertex( $geometry, vertex:=1 )+180,0)
  48. )
  49.  
  50. END

Hasta la pasta! is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.