fromJson static method
Returns a deserialized GeographyGeometryCollection from various formats.
Handles:
- GeographyGeometryCollection — returned as-is
- Uint8List — decoded from EWKB binary (as returned by PostgreSQL)
- String — decoded from EWKT
- Map — decoded from a JSON map with srid and geometries keys
Implementation
static GeographyGeometryCollection fromJson(dynamic value) {
if (value is GeographyGeometryCollection) return value;
if (value is Uint8List) {
return GeographyGeometryCollection.fromBinary(value);
}
if (value is String) return _fromEwkt(value);
if (value is Map) {
final srid = value['srid'] as int? ?? Geography.defaultSrid;
// Each element is already a serialized geography (EWKT or map).
final rawGeoms = value['geometries'] as List;
final geoms = rawGeoms.map<Geography>((g) {
if (g is String) return _geomFromEwktString(g);
if (g is Map) return _geomFromMap(g);
throw ArgumentError('Cannot deserialize geometry element: $g');
}).toList();
return GeographyGeometryCollection(geometries: geoms, srid: srid);
}
throw ArgumentError(
'Cannot deserialize ${value.runtimeType} as GeographyGeometryCollection',
);
}