Geographic.parse constructor

Geographic.parse(
  1. String text, {
  2. Pattern delimiter = ',',
  3. Coords? type,
  4. bool swapXY = false,
})

Parses a geographic position from text.

Coordinate values in text are separated by delimiter.

Supported coordinate value combinations for text are: (lon, lat), (lon, lat, elev), (lon, lat, m) or (lon, lat, elev, m)

Use an optional type to explicitely set the coordinate type. If not provided and text has 3 items, then (lon, lat, elev) coordinates are assumed.

If swapXY is true, then swaps x (lon) and y (lat) for the result.

Throws FormatException if coordinates are invalid.

Examples:

// a 2D position (lon: 10.0, lat: 20.0)
Geographic.parse('10.0,20.0');

// a 3D position (lon: 10.0, lat: 20.0, elev: 30.0)
Geographic.parse('10.0,20.0,30.0');

// a measured 2D position (lon: 10.0, lat: 20.0, m: 40.0)
// (need to specify the coordinate type XYM)
Geographic.parse('10.0,20.0,40.0', type: Coords.xym);

// a measured 3D position (lon: 10.0, lat: 20.0, elev: 30.0, m: 40.0)
Geographic.parse('10.0,20.0,30.0,40.0');

// a 2D position (lon: 10.0, lat: 20.0) using an alternative
// delimiter
Geographic.parse('10.0;20.0', delimiter: ';');

// a 2D position (lon: 10.0, lat: 20.0) from an array with y (lat)
// before x (lon)
Geographic.parse('20.0,10.0', swapXY: true);

Implementation

factory Geographic.parse(
  String text, {
  Pattern delimiter = ',',
  Coords? type,
  bool swapXY = false,
}) =>
    Position.parsePosition(
      text,
      to: Geographic.create,
      delimiter: delimiter,
      type: type,
      swapXY: swapXY,
    );