Table of Contents

Method GetGeoJSON

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

GetGeoJSON(string, bool)

Converts query results containing geospatial data to GeoJSON format.

public string GetGeoJSON(string geospatialColumnName, bool isGeography = false)

Parameters

geospatialColumnName string

The name of the column containing geometry or geography data.

isGeography bool

True if the column contains geography data (lat/lon coordinates); false for geometry.

Returns

string

A GeoJSON FeatureCollection string containing all results.

Examples

var conn = new PostgreSqlDatasourceConnection
{
    Hostname = "localhost",
    Database = "gis_data",
    Username = "user",
    Password = "password"
};

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);

    using (ResultReader reader = manager.ExecuteReader(query))
    {
        // Convert results to GeoJSON
        string geoJson = reader.GetGeoJSON("geom", isGeography: false);
        File.WriteAllText("locations.geojson", geoJson);
    }
}

Remarks

WARNING: GeoJSON export for geospatial data is not available in the Community Edition of Velocity. It requires the Full Edition.