MultiPoint.parseCoords constructor

MultiPoint.parseCoords(
  1. Iterable<String> points, {
  2. Pattern delimiter = ',',
  3. Coords? type,
  4. bool swapXY = false,
  5. bool singlePrecision = false,
})

Parses a multi point geometry from points with positions formatted as texts containing coordinate values separated by delimiter.

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

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

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

Examples:

// a multi point from three 2D positions
MultiPoint.parseCoords([
  '10.0,20.0',
  '12.5,22.5',
  '15.0,25.0',
]);

// a multi point from three 3D positions
MultiPoint.parseCoords([
  '10.0,20.0,30.0',
  '12.5,22.5,32.5',
  '15.0,25.0,35.0',
]);

// a multi point from three 2D positions using an alternative delimiter
MultiPoint.parseCoords(
  [
    '10.0;20.0',
    '12.5;22.5',
    '15.0;25.0',
  ],
  delimiter: ';',
);

// a multi point from three 2D positions with x before y
MultiPoint.parseCoords(
  [
    '20.0,10.0',
    '22.5,12.5',
    '25.0,15.0',
  ],
  swapXY: true,
);

// a multi point from three 2D positions with the internal storage using
// single precision floating point numbers (`Float32List` in this case)
MultiPoint.parseCoords(
  [
    '10.0,20.0',
    '12.5,22.5',
    '15.0,25.0',
  ],
  singlePrecision: true,
);

Implementation

factory MultiPoint.parseCoords(
  Iterable<String> points, {
  Pattern delimiter = ',',
  Coords? type,
  bool swapXY = false,
  bool singlePrecision = false,
}) {
  if (points.isEmpty) {
    return MultiPoint.build(const []);
  } else {
    return MultiPoint(
      points
          .map(
            (point) => parsePositionFromText(
              point,
              delimiter: delimiter,
              type: type,
              swapXY: swapXY,
              singlePrecision: singlePrecision,
            ),
          )
          .toList(growable: false),
    );
  }
}