parse<R extends Geometry> static method

R parse<R extends Geometry>(
  1. String text, {
  2. TextReaderFormat<SimpleGeometryContent> format = GeoJSON.geometry,
  3. CoordRefSys? crs,
  4. Map<String, dynamic>? options,
})

Parses a geometry of R from text conforming to format.

When format is not given, then the geometry format of GeoJSON is used as a default.

Use crs to give hints (like axis order, and whether x and y must be swapped when read in) about coordinate reference system in text input. When data itself have CRS information it overrides this value.

Format or decoder implementation specific options can be set by options.

Implementation

static R parse<R extends Geometry>(
  String text, {
  TextReaderFormat<SimpleGeometryContent> format = GeoJSON.geometry,
  CoordRefSys? crs,
  Map<String, dynamic>? options,
}) {
  R? result;

  // get geometry builder to build a geometry of R
  final builder = GeometryBuilder<R, Geometry>._((geometry, {name}) {
    if (result != null) {
      throw const FormatException('Already decoded one');
    }
    result = geometry;
  });

  // get decoder with the content decoded sent to builder
  final decoder = format.decoder(
    builder,
    crs: crs,
    options: options,
  );

  // decode and return result if succesful
  decoder.decodeText(text);
  if (result != null) {
    return result!;
  } else {
    throw const FormatException('Could not decode text');
  }
}