Point.parseCoords constructor

Point.parseCoords(
  1. String text, {
  2. Pattern delimiter = ',',
  3. Coords? type,
  4. bool swapXY = false,
  5. bool singlePrecision = false,
})

Parses a point geometry from text with coordinate values separated by delimiter.

Use an optional type to explicitely set the coordinate type. If not provided and text has 3 items, then xyz coordinates are assumed.

If swapXY is true, then swaps x and y for the result.

If singlePrecision is true, then coordinate values of a position are stored in Float32List instead of the Float64List (default).

Examples:

// a point with a 2D position (x: 10.0, y: 20.0)
Point.parseCoords('10.0,20.0');

// a point with a 3D position (x: 10.0, y: 20.0, z: 30.0)
Point.parseCoords('10.0,20.0,30.0');

// a point with a measured 2D position (x: 10.0, y: 20.0, m: 40.0)
// (need to specify the coordinate type XYM)
Point.parseCoords('10.0,20.0,40.0', type: Coords.xym);

// a point with a measured 3D position
// (x: 10.0, y: 20.0, z: 30.0, m: 40.0)
Point.parseCoords('10.0,20.0,30.0,40.0');

// a point with a 2D position (x: 10.0, y: 20.0) using an alternative
// delimiter
Point.parseCoords('10.0;20.0', delimiter: ';');

// a point with a 2D position (x: 10.0, y: 20.0) from an array with y
// before x
Point.parseCoords('20.0,10.0', swapXY: true);

// a point with a 2D position (x: 10.0, y: 20.0) with the internal storage
// using single precision floating point numbers (`Float32List` in this
// case)
Point.parseCoords('10.0,20.0', singlePrecision: true);

Implementation

factory Point.parseCoords(
  String text, {
  Pattern delimiter = ',',
  Coords? type,
  bool swapXY = false,
  bool singlePrecision = false,
}) {
  final str = text.trim();
  if (str.isEmpty) {
    return Point.build(const [double.nan, double.nan]);
  }
  return Point(
    parsePositionFromText(
      str,
      delimiter: delimiter,
      type: type,
      swapXY: swapXY,
      singlePrecision: singlePrecision,
    ),
  );
}