MultiPoint class
A MultiPoint is a 0-dimensional GeometryCollection. The elements of a MultiPoint are restricted to Points. The Points are not connected or ordered in any semantically important way.
class MultiPoint extends GeometryCollection { /** * Creates a new multipoint object [points]. * * [points] must not include null values, otherwise throws an * [ArgumentError]. * * if [points] is null or empty, then an empty multipoint object * is created. * * [points] don't have to be homogeneous with respect to the z- and * m-coordinate. You can mix xy-, and xy{z,m}-points in a multipoint. * However, [is3D] only returns true, iff all points have a z-coordinate. * Similary, [isMeasured] only returns true, iff all points have an * m-value. */ MultiPoint(List<Point> points): super(points); /** * Creates an empty multipoint object. */ factory MultiPoint.empty() =>_EMPTY_MULTIPOINT; /** * Creates a new multipoint from the WKT string [wkt]. * * Throws a [WKTError] if [wkt] isn't a valid representation of * a [MultiPoint]. */ factory MultiPoint.wkt(String wkt) { var g = parseWKT(wkt); if (g is! MultiPoint) { throw new WKTError("WKT string doesn't represent a MultiPoint"); } return g; } @override int get dimension => 0; @override String get geometryType => "MultiPoint"; @override bool get isValid => true; bool _isSimple = null; _computeIsSimple() { compare(p, q) { int c = p.x.compareTo(q.x); return c != 0 ? c : p.y.compareTo(q.y); } checkDuplicate(last, that) { if (last == null) return that; // that is the first element if (last == false) return false; // we already have a duplicate if (last.x == that.x && last.y == that.y) { // now we have a duplicate return false; } // no duplicate -> that becomes last in the next step return that; } if (this.isEmpty) { _isSimple = true; return; } _geometries.sort(compare); var ret = _geometries.fold(null, checkDuplicate); _isSimple = !(ret == false); } /** * A MultiPoint is simple if no two points are identical. * * 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 isSimple { if (_isSimple == null) _computeIsSimple(); return _isSimple; } /// The boundary of a [MultiPoint] is an empty [GeometryCollection] @override Geometry get boundary => new GeometryCollection.empty(); _writeTaggedWKT(writer, {bool withZ: false, bool withM: false}) { writer.write("MULTIPOINT"); writer.blank(); if (!this.isEmpty) { writer.ordinateSpecification(withZ: withZ, withM: withM); } if (this.isEmpty){ writer.empty(); } else { writer..lparen()..newline(); writer..incIdent()..ident(); for(int i=0; i< length; i++) { if (i > 0) writer..comma(); if (i % 10 == 0) writer..newline()..ident(); writer.lparen(); elementAt(i)._writeCoordinates(writer, withZ: withZ, withM: withM); writer.rparen(); } writer..newline(); writer..decIdent()..ident()..rparen(); } } }
Extends
Geometry > Geometry_IterableMixin > Geometry_IterableMixin__GeometryContainerMixin > GeometryCollection > MultiPoint
Constructors
new MultiPoint(List<Point> points) #
Creates a new multipoint object points.
points must not include null values, otherwise throws an
ArgumentError
.
if points is null or empty, then an empty multipoint object is created.
points don't have to be homogeneous with respect to the z- and
m-coordinate. You can mix xy-, and xy{z,m}-points in a multipoint.
However, is3D
only returns true, iff all points have a z-coordinate.
Similary, isMeasured
only returns true, iff all points have an
m-value.
MultiPoint(List<Point> points): super(points);
factory MultiPoint.empty() #
Creates an empty multipoint object.
factory MultiPoint.empty() =>_EMPTY_MULTIPOINT;
factory MultiPoint.wkt(String wkt) #
Creates a new multipoint from the WKT string wkt.
Throws a WKTError if wkt isn't a valid representation of a MultiPoint.
factory MultiPoint.wkt(String wkt) { var g = parseWKT(wkt); if (g is! MultiPoint) { throw new WKTError("WKT string doesn't represent a MultiPoint"); } return g; }
Properties
final String asText #
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 #
The boundary of a MultiPoint is an empty GeometryCollection
@override Geometry get boundary => new GeometryCollection.empty();
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.
@override int get dimension => 0;
final E first #
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.
@override String get geometryType => "MultiPoint";
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 #
Returns 1 true if this geometric object is the empty 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 MultiPoint is simple if no two points are identical.
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 isSimple { if (_isSimple == null) _computeIsSimple(); return _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 #
final int length #
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 #
Returns the single element in this
.
If this
is empty or has more than one element throws a StateError
.
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; }
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)) #
bool contains(E element) #
E elementAt(int index) #
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
.
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)) #
Iterable expand(Iterable f(E element)) #
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.
Iterable expand(Iterable f(E element)) => new ExpandIterable<E, dynamic>(this, f);
E firstWhere(bool test(E value), {E orElse()}) #
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.
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)) #
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);
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)) #
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]) #
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.
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()}) #
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.
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)) #
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.
Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f);
E reduce(E combine(E value, E element)) #
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);
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)) #
Returns the single element that satisfies f
. If no or more than one
element match then a StateError
is thrown.
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) #
Iterable<E> skipWhile(bool test(E value)) #
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.
Iterable<E> skipWhile(bool test(E value)) { return new SkipWhileIterable<E>(this, test); }
Iterable<E> take(int n) #
Iterable<E> takeWhile(bool test(E value)) #
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.
Iterable<E> takeWhile(bool test(E value)) { return new TakeWhileIterable<E>(this, test); }
List<E> toList({bool growable: true}) #
Set<E> toSet() #
Iterable<E> where(bool f(E element)) #
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.
Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);