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 citiesTable = schema["cities"];

    var query = new Query()
        .Select([citiesTable["id"], citiesTable["name"], citiesTable["population"], citiesTable["location"]])
        .From(citiesTable);

    ResultSet results = manager.ExecuteResultSet(query);

    // Export to GeoJSON for mapping applications
    string geoJson = results.GetGeoJSON("location", isGeography: true);
    File.WriteAllText("cities.geojson", geoJson);

    results.Dispose();
}

Remarks

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