Method GetGeoJSON
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
GetGeoJSON(string, string)
Converts query results containing geospatial data to GeoJSON format.
public string GetGeoJSON(string geospatialColumnName, string idPropertyName = "id")
Parameters
geospatialColumnNamestringThe name of the column containing geometry or geography data.
idPropertyNamestringThe attribute name promoted from GeoJSON "properties" to the Feature's top-level "id" member (the idiomatic GeoJSON convention for a row's identifier, recognized by tools such as Mapbox GL and Leaflet). Pass
nullor an empty string to disable promotion and leave it as a regular property.
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);
using (ResultSet results = manager.Retrieve(query))
{
// Export to GeoJSON for mapping applications — the "id" column is promoted to
// each Feature's top-level "id"
string geoJson = results.GetGeoJSON("location");
File.WriteAllText("cities.geojson", geoJson);
}
}
Remarks
Warning
GeoJSON export for geospatial data is not available in the Community Edition of Velocity. It requires the Full Edition.