fromJson static method
Returns a deserialized GeographyLineString from various formats.
Handles:
- GeographyLineString — returned as-is
- Uint8List — decoded from EWKB binary (as returned by PostgreSQL)
- String — decoded from EWKT (e.g.
SRID=4326;LINESTRING(0 0, 1 1)) - Map — decoded from a JSON map with srid and points keys
Implementation
static GeographyLineString fromJson(dynamic value) {
if (value is GeographyLineString) return value;
if (value is Uint8List) return GeographyLineString.fromBinary(value);
if (value is String) return _fromEwkt(value);
if (value is Map) {
final srid = value['srid'] as int? ?? Geography.defaultSrid;
final rawPoints = value['points'] as List;
final points = rawPoints.map((p) {
final m = p as Map;
return GeographyPoint(
longitude: (m['longitude'] as num).toDouble(),
latitude: (m['latitude'] as num).toDouble(),
srid: srid,
);
}).toList();
return GeographyLineString(points: points, srid: srid);
}
throw ArgumentError(
'Cannot deserialize ${value.runtimeType} as GeographyLineString',
);
}