Dart Documentationsimple_featuresGeometryCollection

GeometryCollection class

A GeometryCollection is a geometric object that is a collection of some number of geometric objects.

It implements the accesor methods numGeometries and getGeometryN which are specified in the SFS. In addition, it provides the more Dart'ish length property and an overloaded index operator. It also implements the Iterable interface.

class GeometryCollection extends Geometry
 with IterableMixin<Geometry>, _GeometryContainerMixin {

 List<Geometry> _geometries;

 /**
  * Creates a geometry collection given a collection of
  * [geometries].
  */
 GeometryCollection(Iterable<Geometry> geometries) {
   if (geometries == null || geometries.isEmpty) {
     _geometries = null;
   } else {
     _geometries = new List<Geometry>.from(geometries, growable:false);
     _require(this.every((p) => p != null));
   }
 }
 /**
  * Creates an empty geometry collection.
  */
 factory GeometryCollection.empty() => _EMPTY_GEOMETRY_COLLECTION;

 /**
  * Creates a new geometry collection from the WKT string [wkt].
  *
  * Throws a [WKTError] if [wkt] isn't a valid representation of
  * a [GeometryCollection].
  */
 factory GeometryCollection.wkt(String wkt) {
   var g = parseWKT(wkt);
   if (g is! GeometryCollection) {
     throw new WKTError("WKT string doesn't represent a GeometryCollection");
   }
   return g;
 }

 /**
  * Replies the number of geometries in this collection.
  *
  * This getter is equivaled to the method `getNumGeometries()`
  * in the SFS, but see also [length].
  */
 @specification(name:"getNumGeometries")
 int get numGeometries => length;

 /**
  * Replies the <em>n</em>-th geometry in this collection.
  */
 @specification(name:"getGeometryN")
 Geometry getGeometryN(int n) => elementAt(n);

 /**
  * Replies the <em>n</em>-th geometry in this collection.
  *
  * This is the Dart'ish implemenation of `getGeometryN()` using
  * operator overloading.
  */
 @specification(name:"getGeometryN")
 operator [](int n) => elementAt(n);

 /// the iterator to access the geometry objects
 Iterator<Geometry> get iterator {
   if (_geometries == null) return [].iterator;
   else return _geometries.iterator;
 }

 /**
  * A geometry collection is simple if all its child geometries are
  * simple.
  */
 @override bool get isSimple => every((g) => g.isSimple);

 @override
 _writeTaggedWKT(writer, {bool withZ: false, bool withM: false}) {
   writer.write("GEOMETRYCOLLECTION");
   writer.blank();
   if (! isEmpty) {
     writer.ordinateSpecification(withZ: withZ, withM: withM);
   }
   if (isEmpty){
     writer.empty();
   } else {
     writer..lparen()..newline();
     writer..incIdent()..ident();
     for(int i=0; i< length; i++) {
       if (i > 0) writer..comma()..newline()..ident();
       elementAt(i)._writeTaggedWKT(writer, withZ: withZ, withM: withM);
     }
     writer..newline();
     writer..decIdent()..ident()..rparen();
   }
 }

 @override String get geometryType => "GeometryCollection";
 @override int get dimension => fold(0, (prev, g) => max(prev, g.dimension));
}

Extends

Geometry > Geometry_IterableMixin > Geometry_IterableMixin__GeometryContainerMixin > GeometryCollection

Subclasses

MultiLineString, MultiPoint, MultiSurface

Constructors

new GeometryCollection(Iterable<Geometry> geometries) #

Creates a geometry collection given a collection of geometries.

GeometryCollection(Iterable<Geometry> geometries) {
 if (geometries == null || geometries.isEmpty) {
   _geometries = null;
 } else {
   _geometries = new List<Geometry>.from(geometries, growable:false);
   _require(this.every((p) => p != null));
 }
}

factory GeometryCollection.empty() #

Creates an empty geometry collection.

factory GeometryCollection.empty() => _EMPTY_GEOMETRY_COLLECTION;

factory GeometryCollection.wkt(String wkt) #

Creates a new geometry collection from the WKT string wkt.

Throws a WKTError if wkt isn't a valid representation of a GeometryCollection.

factory GeometryCollection.wkt(String wkt) {
 var g = parseWKT(wkt);
 if (g is! GeometryCollection) {
   throw new WKTError("WKT string doesn't represent a GeometryCollection");
 }
 return g;
}

Properties

final String asText #

inherited from Geometry

A WKT representation of the geometry

@specification(name:"asText()")
String get asText {
 var buffer = new StringBuffer();
 var writer = new _WKTWriter(buffer);
 _writeTaggedWKT(writer, withZ: is3D, withM: isMeasured);
 return buffer.toString();
}

final Geometry boundary #

inherited from Geometry

Returns the closure of the combinatorial boundary of this geometric object

@specification(name:"boundary()")
Geometry get boundary;

final int dimension #

The inherent dimension of this geometric object, which must be less than or equal to the coordinate dimension. In non-homogeneous collections, this will return the largest topological dimension of the contained objects.

docs inherited from Geometry
@override int get dimension => fold(0, (prev, g) => max(prev, g.dimension));

final E first #

inherited from Geometry_IterableMixin

Returns the first element.

If this is empty throws a StateError. Otherwise this method is equivalent to this.elementAt(0)

docs inherited from Iterable<E>
E get first {
 Iterator it = iterator;
 if (!it.moveNext()) {
   throw new StateError("No elements");
 }
 return it.current;
}

final String geometryType #

Returns the name of the instantiable subtype of Geometry of which this geometric object is an instantiable member. The name of the subtype of Geometry is returned as a string.

docs inherited from Geometry
@override String get geometryType => "GeometryCollection";

final bool is3D #

A collection of geometries is considered 3D if every child geometry has a non-null z-component.

The value of this property is computed upon first access and then cached. Subsequent reads of the property efficiently reply the cached value.

@override
bool get is3D {
 if (_is3D == null) _computeIs3D();
 return _is3D;
}

final bool isEmpty #

inherited from Geometry_IterableMixin

Returns 1 true if this geometric object is the empty Geometry.

docs inherited from Geometry
bool get isEmpty => !iterator.moveNext();

final bool isMeasured #

A collection of geometries is considered measured if every child geometry has an m-component.

The value of this property is computed upon first access and then cached. Subsequent reads of the property efficiently reply the cached value.

@override
bool get isMeasured {
 if (_isMeasured == null) _computeIsMeasured();
 return _isMeasured;
}

final bool isSimple #

A geometry collection is simple if all its child geometries are simple.

@override bool get isSimple => every((g) => g.isSimple);

final Iterator<Geometry> iterator #

the iterator to access the geometry objects

Iterator<Geometry> get iterator {
 if (_geometries == null) return [].iterator;
 else return _geometries.iterator;
}

final E last #

inherited from Geometry_IterableMixin

Returns the last element.

If this is empty throws a StateError.

docs inherited from Iterable<E>
E get last {
 Iterator it = iterator;
 if (!it.moveNext()) {
   throw new StateError("No elements");
 }
 E result;
 do {
   result = it.current;
 } while(it.moveNext());
 return result;
}

final int length #

inherited from Geometry_IterableMixin

Returns the number of elements in this.

Counting all elements may be involve running through all elements and can therefore be slow.

docs inherited from Iterable<E>
int get length {
 int count = 0;
 Iterator it = iterator;
 while (it.moveNext()) {
   count++;
 }
 return count;
}

final int numGeometries #

Replies the number of geometries in this collection.

This getter is equivaled to the method getNumGeometries() in the SFS, but see also length.

@specification(name:"getNumGeometries")
int get numGeometries => length;

final E single #

inherited from Geometry_IterableMixin

Returns the single element in this.

If this is empty or has more than one element throws a StateError.

docs inherited from Iterable<E>
E get single {
 Iterator it = iterator;
 if (!it.moveNext()) throw new StateError("No elements");
 E result = it.current;
 if (it.moveNext()) throw new StateError("More than one element");
 return result;
}

int get SRID #

inherited from Geometry

Returns the Spatial Reference System ID for this geometric object.

@specification(name:"srid()")
int get SRID => _srid;

dynamic set SRID(int value) #

inherited from Geometry

the Spatial Reference System ID for this geometric object.

set SRID(int value) => _srid = value;

Operators

dynamic operator [](int n) #

Replies the <em>n</em>-th geometry in this collection.

This is the Dart'ish implemenation of getGeometryN() using operator overloading.

@specification(name:"getGeometryN")
operator [](int n) => elementAt(n);

Methods

bool any(bool f(E element)) #

inherited from Geometry_IterableMixin

Returns true if one element of this collection satisfies the predicate f. Returns false otherwise.

docs inherited from Iterable<E>
bool any(bool f(E element)) {
 for (E element in this) {
   if (f(element)) return true;
 }
 return false;
}

bool contains(E element) #

inherited from Geometry_IterableMixin

Check whether the collection contains an element equal to element.

docs inherited from Iterable<E>
bool contains(E element) {
 for (E e in this) {
   if (e == element) return true;
 }
 return false;
}

E elementAt(int index) #

inherited from Geometry_IterableMixin

Returns the indexth element.

If [this] [Iterable] has fewer than index elements throws a RangeError.

Note: if this does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index elements in this.

docs inherited from Iterable<E>
E elementAt(int index) {
 if (index is! int || index < 0) throw new RangeError.value(index);
 int remaining = index;
 for (E element in this) {
   if (remaining == 0) return element;
   remaining--;
 }
 throw new RangeError.value(index);
}

bool every(bool f(E element)) #

inherited from Geometry_IterableMixin

Returns true if every elements of this collection satisify the predicate f. Returns false otherwise.

docs inherited from Iterable<E>
bool every(bool f(E element)) {
 for (E element in this) {
   if (!f(element)) return false;
 }
 return true;
}

Iterable expand(Iterable f(E element)) #

inherited from Geometry_IterableMixin

Expand each element of this Iterable into zero or more elements.

The resulting Iterable will run through the elements returned by f for each element of this, in order.

The returned Iterable is lazy, and will call f for each element of this every time it's iterated.

docs inherited from Iterable<E>
Iterable expand(Iterable f(E element)) =>
   new ExpandIterable<E, dynamic>(this, f);

E firstWhere(bool test(E value), {E orElse()}) #

inherited from Geometry_IterableMixin

Returns the first element that satisfies the given predicate f.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

docs inherited from Iterable<E>
E firstWhere(bool test(E value), { E orElse() }) {
 // TODO(floitsch): check that arguments are of correct type?
 for (E element in this) {
   if (test(element)) return element;
 }
 if (orElse != null) return orElse();
 throw new StateError("No matching element");
}

dynamic fold(initialValue, combine(previousValue, E element)) #

inherited from Geometry_IterableMixin

Reduces a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function.

Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.

Example of calculating the sum of an iterable:

iterable.fold(0, (prev, element) => prev + element);
docs inherited from Iterable<E>
dynamic fold(var initialValue,
            dynamic combine(var previousValue, E element)) {
 var value = initialValue;
 for (E element in this) value = combine(value, element);
 return value;
}

void forEach(void f(E element)) #

inherited from Geometry_IterableMixin

Applies the function f to each element of this collection.

docs inherited from Iterable<E>
void forEach(void f(E element)) {
 for (E element in this) f(element);
}

Geometry getGeometryN(int n) #

Replies the <em>n</em>-th geometry in this collection.

@specification(name:"getGeometryN")
Geometry getGeometryN(int n) => elementAt(n);

String join([String separator]) #

inherited from Geometry_IterableMixin

Converts each element to a String and concatenates the strings.

Converts each element to a String by calling Object.toString on it. Then concatenates the strings, optionally separated by the separator string.

docs inherited from Iterable<E>
String join([String separator]) {
 Iterator<E> iterator = this.iterator;
 if (!iterator.moveNext()) return "";
 StringBuffer buffer = new StringBuffer();
 if (separator == null || separator == "") {
   do {
     buffer.write("${iterator.current}");
   } while (iterator.moveNext());
 } else {
   buffer.write("${iterator.current}");
   while (iterator.moveNext()) {
     buffer.write(separator);
     buffer.write("${iterator.current}");
   }
 }
 return buffer.toString();
}

E lastWhere(bool test(E value), {E orElse()}) #

inherited from Geometry_IterableMixin

Returns the last element that satisfies the given predicate f.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

docs inherited from Iterable<E>
E lastWhere(bool test(E value), {E orElse()}) {
 // TODO(floitsch): check that arguments are of correct type?
 E result = null;
 bool foundMatching = false;
 for (E element in this) {
   if (test(element)) {
     result = element;
     foundMatching = true;
   }
 }
 if (foundMatching) return result;
 if (orElse != null) return orElse();
 throw new StateError("No matching element");
}

Iterable map(f(E element)) #

inherited from Geometry_IterableMixin

Returns a lazy Iterable where each element e of this is replaced by the result of f(e).

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function f will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable will invoke the supplied function f multiple times on the same element.

docs inherited from Iterable<E>
Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f);

E reduce(E combine(E value, E element)) #

inherited from Geometry_IterableMixin

Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.

Example of calculating the sum of an iterable:

iterable.reduce((value, element) => value + element);
docs inherited from Iterable<E>
E reduce(E combine(E value, E element)) {
 Iterator<E> iterator = this.iterator;
 if (!iterator.moveNext()) {
   throw new StateError("No elements");
 }
 E value = iterator.current;
 while (iterator.moveNext()) {
   value = combine(value, iterator.current);
 }
 return value;
}

E singleWhere(bool test(E value)) #

inherited from Geometry_IterableMixin

Returns the single element that satisfies f. If no or more than one element match then a StateError is thrown.

docs inherited from Iterable<E>
E singleWhere(bool test(E value)) {
 // TODO(floitsch): check that argument is of correct type?
 E result = null;
 bool foundMatching = false;
 for (E element in this) {
   if (test(element)) {
     if (foundMatching) {
       throw new StateError("More than one matching element");
     }
     result = element;
     foundMatching = true;
   }
 }
 if (foundMatching) return result;
 throw new StateError("No matching element");
}

Iterable<E> skip(int n) #

inherited from Geometry_IterableMixin

Returns an Iterable that skips the first n elements.

If this has fewer than n elements, then the resulting Iterable will be empty.

docs inherited from Iterable<E>
Iterable<E> skip(int n) {
 return new SkipIterable<E>(this, n);
}

Iterable<E> skipWhile(bool test(E value)) #

inherited from Geometry_IterableMixin

Returns an Iterable that skips elements while test is satisfied.

The filtering happens lazily. Every new Iterator of the returned Iterable will iterate over all elements of this. As long as the iterator's elements do not satisfy test they are discarded. Once an element satisfies the test the iterator stops testing and uses every element unconditionally.

docs inherited from Iterable<E>
Iterable<E> skipWhile(bool test(E value)) {
 return new SkipWhileIterable<E>(this, test);
}

Iterable<E> take(int n) #

inherited from Geometry_IterableMixin

Returns an Iterable with at most n elements.

The returned Iterable may contain fewer than n elements, if this contains fewer than n elements.

docs inherited from Iterable<E>
Iterable<E> take(int n) {
 return new TakeIterable<E>(this, n);
}

Iterable<E> takeWhile(bool test(E value)) #

inherited from Geometry_IterableMixin

Returns an Iterable that stops once test is not satisfied anymore.

The filtering happens lazily. Every new Iterator of the returned Iterable will start iterating over the elements of this. When the iterator encounters an element e that does not satisfy test, it discards e and moves into the finished state. That is, it will not ask or provide any more elements.

docs inherited from Iterable<E>
Iterable<E> takeWhile(bool test(E value)) {
 return new TakeWhileIterable<E>(this, test);
}

List<E> toList({bool growable: true}) #

inherited from Geometry_IterableMixin

Creates a List containing the elements of this Iterable.

The elements will be in iteration order. The list is fixed-length if growable is false.

docs inherited from Iterable<E>
List<E> toList({ bool growable: true }) =>
   new List<E>.from(this, growable: growable);

Set<E> toSet() #

inherited from Geometry_IterableMixin

Creates a Set containing the elements of this Iterable.

docs inherited from Iterable<E>
Set<E> toSet() => new Set<E>.from(this);

Iterable<E> where(bool f(E element)) #

inherited from Geometry_IterableMixin

Returns a lazy Iterable with all elements that satisfy the predicate f.

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function f will not be invoked. Iterating will not cache results, and thus iterating multiple times over the the returned Iterable will invoke the supplied function f multiple times on the same element.

docs inherited from Iterable<E>
Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);