populated method

  1. @override
FeatureCollection<Feature<Geometry>> populated({
  1. int traverse = 0,
  2. bool onBounds = true,
  3. PositionScheme scheme = Position.scheme,
})
override

Returns a feature object of the same subtype as this with certain data members populated.

If nothing is populated then this is returned.

If onBounds is true (as by default):

  • The bounds in a returned feature object is ensured to be populated (expect when cannot be calculated, for example in the case of an empty geometry).
  • If traverse > 0, then also bounding boxes of child feature or geometry objects of this feature object are populated for child levels indicated by traverse (0: no childs, 1: only direct childs, 2: direct childs and childs of them, ..).

Use scheme to set the position scheme:

  • Position.scheme for generic position data (geographic, projected or any other), this is also the default
  • Projected.scheme for projected position data
  • Geographic.scheme for geographic position data

See also unpopulated.

Implementation

@override
FeatureCollection populated({
  int traverse = 0,
  bool onBounds = true,
  PositionScheme scheme = Position.scheme,
}) {
  if (onBounds) {
    // populate features when traversing is asked
    final coll = traverse > 0 && features.isNotEmpty
        ? features
            .map<E>(
              (f) => f.populated(
                traverse: traverse - 1,
                onBounds: onBounds,
                scheme: scheme,
              ) as E,
            )
            .toList(growable: false)
        : features;

    // create a new collection if features changed or bounds was unpopulated
    // or of other scheme
    final b = bounds;
    final empty = coll.isEmpty;
    if (coll != features ||
        (b == null && !empty) ||
        (b != null && !b.conforming.conformsWith(scheme))) {
      return FeatureCollection<E>._(
        coll,
        coordType,
        bounds: empty
            ? null
            : coll
                .map((f) => f.calculateBounds(scheme: scheme))
                .merge()
                ?.copyByType(coordType),
        custom: custom,
      );
    }
  }
  return this;
}