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 locationsTable = schema["locations"];
var query = new Query()
.Select([locationsTable["id"], locationsTable["name"], locationsTable["geom"]])
.From(locationsTable);
using (ResultReader reader = manager.Search(query))
{
// Convert results to GeoJSON — the "id" column is promoted to each Feature's top-level "id"
string geoJson = reader.GetGeoJSON("geom");
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.
This overload materializes every feature in memory before returning the completed string. For large result sets, prefer the GetGeoJSON(Stream, string, string) overload, which writes each feature to the stream as it's read, holding only one row in memory at a time.
GetGeoJSON(Stream, string, string)
Converts query results containing geospatial data to GeoJSON format, writing each feature to
stream as it's read rather than materializing the entire result set in memory first.
public void GetGeoJSON(Stream stream, string geospatialColumnName, string idPropertyName = "id")
Parameters
streamStreamThe stream to write the GeoJSON to. Not closed by this method.
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. Pass
nullor an empty string to disable promotion and leave it as a regular property.
Examples
using (var manager = new Manager(conn))
using (ResultReader reader = manager.Search(query))
using (FileStream file = File.Create("locations.geojson"))
{
// Only one row is held in memory at a time, regardless of result set size
reader.GetGeoJSON(file, "geom");
}
Remarks
Warning
GeoJSON export for geospatial data is not available in the Community Edition of Velocity. It requires the Full Edition.