Printing Latitude, Longitude or Location/Geocode Values

In version 6.00.1300152000 20110314 and later, the %L code may be used with <fmt> to print a latitude, longitude or location (geocode) value, in a manner similar to how date/time values are printed with %t. Flags indicate what type of value is expected, and/or if a subformat is provided:

  • - (minus)

    A latitude argument is expected (memory aid: latitude lines are horizontal, so is minus sign). This is the default.

  • | (pipe)

    A longitude is expected (memory aid: longitude lines are vertical; so is pipe).

  • + (plus)

    A location is expected; either a geocode long value, or a latitude and longitude (e.g. comma-separated).

  • a

    Like %at (date/time format), the next argument (before the latitude/longitude/location) is a subformat indicating how to print the latitude and/or longitude. Without this flag, no subformat argument is expected, and a default subformat is used.

Latitude, longitude and location arguments should be in one of the formats supported by the parselatitude(), parselongitude(), or latlon2geocode() (with single arg) SQL functions, as appropriate. If the a flag is given, the subformat string may contain the following codes:

  • %D for degrees

  • %M for minutes

  • %S for seconds

  • %H for the hemisphere letter ("N", "S", "E" or "W")

  • %h for the hemisphere sign ("+" or "-")

  • %o for an ISO-8859-1 degree sign

  • %O for a UTF-8 degree sign

  • %% for a percent sign

A field width, precision, space, zero and/or minus flags may be given with the %D/%M/%S codes, with the same meaning as for numeric fmt codes. If no flags are given to a code, the width is set to 2 (or 3 for longitude degrees), with space padding for degrees and zero padding for minutes and seconds.

Additionally, a single d, i, f or g numeric-type flag may be given with the %D/%M/%S codes. This flag will print the value with the corresponding fmt numeric code, e.g. truncated to an integer for d or i, floating-point with potential roundoff for f or g. This flag is only valid for the smallest unit (degrees/minutes/seconds) printed: larger units will always be printed in integer format. This ensures that a fractional value will not be printed twice erroneously, e.g. 20.5 degrees will not have its ".5" degrees fractional part printed if "30" minutes is also being printed, because the degrees numeric-type will be forced to integer regardless of flags.

The default numeric-type flag is g for the smallest unit. This helps ensure values are printed with the least number of decimal places needed (often none), yet with more (sub-second) accuracy if specified in the original value. Additionally, for the g type, if a degrees/minutes/seconds value is less than ( 10^-(p-2) ), where p is the format code's precision (default 6), it will be truncated to 0. This helps prevent exponential-format printing of values, which is often merely an artifact of floating-point roundoff during unit conversion, and not part of the original user-specified value.

Examples:

<!-- Print latitude, default format: -->
  <fmt "%-L\n" 41.75>
  <!-- Print a longitude in Garmin format: -->
  <fmt "%a|L\n" "%H%03D%O%02.2fM'" -121.123>
  <!-- Dump geocodes for humans: -->
  <sql "select Geocode from geoTable">
    <fmt "Loc: %+L\n" $Geocode>
  </sql>


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.