toText method

String toText({
  1. String delimiter = ' ',
  2. int decimals = 0,
  3. bool compactNums = true,
  4. bool swapXY = false,
  5. bool formatAlsoElevM = false,
  6. bool zeroPadZone = false,
})

The UTM coordinate string representation with values separated by delimiter (default is whitespace).

Use decimals to set a number of decimals (not applied if no decimals).

If compactNums is true, any ".0" postfixes of numbers without fraction digits are stripped.

Set swapXY to true to print y (or northing) before x (or easting).

Set formatAlsoElevM to true if any elevation or m coordinate values optionally present in the projected position should be written on the text output (z is elevation, m is optional M value).

If zeroPadZone is true, then all zone numbers (1..60) are formatted with two digits, e.g. 31 or 04. By default only significant digits are formatted, e.g. 31 or 4.

Examples:

  final utmCoord = Utm(31, 'N', 448251.0, 5411932.0);
  print(utmCoord.toText()); // '31 N 448251 5411932'

Implementation

String toText({
  String delimiter = ' ',
  int decimals = 0,
  bool compactNums = true,
  bool swapXY = false,
  bool formatAlsoElevM = false,
  bool zeroPadZone = false,
}) {
  // ensure leading zeros on zone if `zeroPadZone` is set true
  final lonZone = zone.lonZone;
  final zPadded =
      zeroPadZone ? lonZone.toString().padLeft(2, '0') : lonZone.toString();

  final buf = StringBuffer()
    ..write(zPadded)
    ..write(delimiter)
    ..write(zone.hemisphere.symbol)
    ..write(delimiter);

  var pos = projected;
  if (!formatAlsoElevM && (pos.is3D || pos.isMeasured)) {
    pos = pos.copyByType(Coords.xy);
  }

  Position.writeValues(
    pos,
    buf,
    delimiter: delimiter,
    decimals: decimals,
    compactNums: compactNums,
    swapXY: swapXY,
  );

  return buf.toString();
}