spatialDistance method

Future<double?> spatialDistance(
  1. String table,
  2. String geomColumn,
  3. String wkt, {
  4. required String idColumn,
  5. required Object id,
})

The planar distance between the geometry in geomColumn of the row where idColumn equals id, and the geometry described by wkt, in the spatial reference system's units.

Returns null if no row matches.

Implementation

Future<double?> spatialDistance(
  String table,
  String geomColumn,
  String wkt, {
  required String idColumn,
  required Object id,
}) async {
  final rows = await rawQuery(
    'SELECT ST_Distance($geomColumn, GeomFromText(?)) AS distance '
    'FROM $table WHERE $idColumn = ?',
    [wkt, id],
  );
  if (rows.isEmpty) {
    return null;
  }
  return (rows.first['distance'] as num?)?.toDouble();
}