GeoBox.parse constructor

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

Parses a geographic bounding box from text.

Coordinate values in text are separated by delimiter.

Supported coordinate value combinations by coordinate type:

Type Expected values
xy west, south, east, north
xyz west, south, minElev, east, north, maxElev
xym west, south, minM, east, north, maxM
xyzm west, south, minElev, minM, east, north, maxElev, maxM

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

If swapXY is true, then swaps x and y (west <-> south, east <-> north) for the result.

Throws FormatException if coordinates are invalid.

Examples:

// a 2D box (lon: 10.0 .. 15.0, lat: 20.0 .. 25.0)
GeoBox.parse('10.0,20.0,15.0,25.0');

// a 3D box (lon: 10.0 .. 15.0, lat: 20.0 .. 25.0, elev: 30.0 .. 35.0)
GeoBox.parse('10.0,20.0,30.0,15.0,25.0,35.0');

// a measured 2D box (lon: 10.0..15.0, lat: 20.0..25.0, m: 40.0..45.0)
// (need to specify the coordinate type XYM)
GeoBox.parse('10.0,20.0,40.0,15.0,25.0,45.0', type: Coords.xym),

// a measured 3D box
// (lon: 10.0..15.0, lat: 20.0..25.0, elev: 30.0..35.0, m: 40.0..45.0)
GeoBox.parse('10.0,20.0,30.0,40.0,15.0,25.0,35.0,45.0');

// a 2D box (lon: 10.0 .. 15.0, lat: 20.0 .. 25.0) using an alternative
// delimiter
GeoBox.parse('10.0;20.0;15.0;25.0', delimiter: ';');

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

Implementation

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