GeometryCollection<E extends Geometry>.build constructor

GeometryCollection<E extends Geometry>.build(
  1. WriteGeometries geometries, {
  2. Coords? type,
  3. int? count,
  4. Box? bounds,
})

Builds a geometry collection from the content provided by geometries.

Only geometry objects of E are built, any other geometries are ignored.

An optional type specifies the coordinate type of geometry objects in a collection. When not provided, the type can be resolved from objects.

An optional expected count, when given, specifies the number of geometry objects in a content stream. Note that when given the count MUST be exact.

An optional bounds can used set a minimum bounding box for a geometry collection.

Examples:

GeometryCollection.build(
  count: 3,
  (GeometryContent geom) {
    geom
      // a point with a 2D position
      ..point([10.0, 20.0].xy)

      // a point with a 3D position
      ..point([10.0, 20.0, 30.0].xyz)

      // a line string from three 3D positions
      ..lineString(
        [
          10.0, 20.0, 30.0,
          12.5, 22.5, 32.5,
          15.0, 25.0, 35.0,
          //
        ].positions(Coords.xyz),
      );
  },
);

Implementation

factory GeometryCollection.build(
  WriteGeometries geometries, {
  Coords? type,
  int? count,
  Box? bounds,
}) =>
    GeometryCollection<E>(
      GeometryBuilder.buildList<E>(geometries, count: count),
      bounds: bounds,
      type: type,
    );