geometry<T extends Geometry> method
Parses a geometry from a data
object.
Throws FormatException if parsing fails.
Implementation
@override
T geometry<T extends Geometry>(dynamic data) {
// expects data of Map<String, dynamic> as returned by json.decode()
final json = _ensureDecodedMap(data);
dynamic geom;
switch (json['type']) {
case 'Point':
// expected 'coordinates' data like : [100.0, 100.0, 10.0]
geom = point(json['coordinates'] as Iterable);
break;
case 'LineString':
// expected 'coordinates' data like :
// [
// [100.0, 100.0, 10.0],
// [200.0, 200.0, 20.0]
// ]
geom = lineString(json['coordinates'] as Iterable);
break;
case 'Polygon':
// expected 'coordinates' data like :
// [
// [
// [100.0, 100.0, 10.0],
// [200.0, 200.0, 20.0]
// [100.0, 200.0, 20.0]
// [100.0, 100.0, 10.0],
// ]
// ]
geom = polygon(json['coordinates'] as Iterable);
break;
case 'MultiPoint':
// expected 'coordinates' data like :
// [
// [100.0, 100.0, 10.0],
// [200.0, 200.0, 20.0]
// ]
geom = multiPoint(json['coordinates'] as Iterable);
break;
case 'MultiLineString':
// expected 'coordinates' data like :
// [
// [
// [100.0, 100.0, 10.0],
// [200.0, 200.0, 20.0]
// ],
// [
// [300.0, 300.0, 30.0],
// [400.0, 400.0, 40.0]
// ]
// ]
geom = multiLineString(json['coordinates'] as Iterable);
break;
case 'MultiPolygon':
// expected 'coordinates' data like :
// [
// [
// [
// [100.0, 100.0, 10.0],
// [200.0, 200.0, 20.0]
// [100.0, 200.0, 20.0]
// [100.0, 100.0, 10.0],
// ]
// ]
// ]
geom = multiPolygon(json['coordinates'] as Iterable);
break;
case 'GeometryCollection':
geom = geometryCollection(json['geometries'] as Iterable);
break;
}
if (geom is T) {
return geom;
}
throw const FormatException('Not valid GeoJSON geometry.');
}