Table of Contents

Method GetGeoJSONAsync

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

GetGeoJSONAsync(string, string, CancellationToken)

Asynchronously converts the results to GeoJSON format.

public Task<string> GetGeoJSONAsync(string geospatialColumnName, string idPropertyName = "id", CancellationToken cancellationToken = default)

Parameters

geospatialColumnName string

The name of the column containing geospatial data.

idPropertyName string

The attribute name promoted from GeoJSON "properties" to the Feature's top-level "id" member. Pass null or an empty string to disable promotion and leave it as a regular property.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<string>

A task representing the asynchronous operation, containing a GeoJSON string representing the results as a FeatureCollection.

Examples

using (var manager = new Manager(conn))
{
    var schema = manager.LoadSchema("public");
    var locationsTable = schema["locations"];

    var query = new Query()
        .Select([locationsTable["id"], locationsTable["name"], locationsTable["geom"]])
        .From(locationsTable);

    await using (ResultReader reader = await manager.SearchAsync(query))
    {
        // Convert results to GeoJSON
        string geoJson = await reader.GetGeoJSONAsync("geom");
        await File.WriteAllTextAsync("locations.geojson", geoJson);
    }
}

Remarks

This overload materializes every feature in memory before returning the completed string. For large result sets, prefer the GetGeoJSONAsync(Stream, string, string, CancellationToken) overload, which writes each feature to the stream as it's read, holding only one row in memory at a time.

GetGeoJSONAsync(Stream, string, string, CancellationToken)

Asynchronously converts query results containing geospatial data to GeoJSON format, writing each feature to stream as it's read via non-blocking I/O, rather than materializing the entire result set in memory first.

public Task GetGeoJSONAsync(Stream stream, string geospatialColumnName, string idPropertyName = "id", CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to write the GeoJSON to. Not closed by this method.

geospatialColumnName string

The name of the column containing geometry or geography data.

idPropertyName string

The attribute name promoted from GeoJSON "properties" to the Feature's top-level "id" member. Pass null or an empty string to disable promotion and leave it as a regular property.

cancellationToken CancellationToken

A token to cancel the underlying ReadAsync calls.

Returns

Task

Examples

await using (var manager = new Manager(conn))
await using (ResultReader reader = await manager.SearchAsync(query))
await using (FileStream file = File.Create("locations.geojson"))
{
    // Only one row is held in memory at a time, and the thread is released between row fetches
    await reader.GetGeoJSONAsync(file, "geom");
}