Polygon.parse constructor

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

Parses a polygon geometry 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.

Examples:

// a polygon (with an exterior ring only) from 2D positions
Polygon.parse(
  format: GeoJSON.geometry,
  '''
  {
    "type": "Polygon",
    "coordinates": [
      [
        [10.0,20.0],
        [12.5,22.5],
        [15.0,25.0],
        [11.5,27.5],
        [10.0,20.0]
      ]
    ]
  }
  ''',
);
Polygon.parse(
  format: WKT.geometry,
  'POLYGON ((10.0 20.0,12.5 22.5,15.0 25.0,11.5 27.5,10.0 20.0))',
);

// a polygon (with an exterior ring only) from 3D positions
Polygon.parse(
  format: GeoJSON.geometry,
  '''
  {
    "type": "Polygon",
    "coordinates": [
      [
        [10.0,20.0,30.0],
        [12.5,22.5,32.5],
        [15.0,25.0,35.0],
        [11.5,27.5,37.5],
        [10.0,20.0,30.0]
      ]
    ]
  }
  ''',
);
Polygon.parse(
  format: WKT.geometry,
  '''
  POLYGON Z (
    (
      10.0 20.0 30.0,
      12.5 22.5 32.5,
      15.0 25.0 35.0,
      11.5 27.5 37.5,
      10.0 20.0 30.0
    )
  )
  ''',
);

// a polygon (with an exterior ring only) from measured 2D positions
Polygon.parse(
  format: WKT.geometry,
  '''
  POLYGON M (
    (
      10.0 20.0 40.0,
      12.5 22.5 42.5,
      15.0 25.0 45.0,
      11.5 27.5 47.5,
      10.0 20.0 40.0
    )
  )
  ''',
);

// a polygon (with an exterior ring only) from measured 3D positions
Polygon.parse(
  format: GeoJSON.geometry,
  '''
  {
    "type": "Polygon",
    "coordinates": [
      [
        [10.0,20.0,30.0,40.0],
        [12.5,22.5,32.5,42.5],
        [15.0,25.0,35.0,45.0],
        [11.5,27.5,37.5,47.5],
        [10.0,20.0,30.0,40.0]
      ]
    ]
  }
  ''',
);
Polygon.parse(
  format: WKT.geometry,
  '''
  POLYGON ZM (
    (
      10.0 20.0 30.0 40.0,
      12.5 22.5 32.5 42.5,
      15.0 25.0 35.0 45.0,
      11.5 27.5 37.5 47.5,
      10.0 20.0 30.0 40.0
    )
  )
  ''',
);

Implementation

factory Polygon.parse(
  String text, {
  TextReaderFormat<SimpleGeometryContent> format = GeoJSON.geometry,
  CoordRefSys? crs,
  Map<String, dynamic>? options,
}) =>
    GeometryBuilder.parse<Polygon>(
      text,
      format: format,
      crs: crs,
      options: options,
    );