Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/a94a4a2cd22ae094dd8bf95b4d034078 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/a94a4a2cd22ae094dd8bf95b4d034078 to your computer and use it in GitHub Desktop.
GEOJSON to Topojson Conversion in .NET: Sample Guide
// GEOJSON to Topojson Conversion in .NET: Sample Guide
// Read the full guide here: https://blog.aspose.com/gis/geojson-to-topojson-conversion-in-dotnet-sample-guide/
using System;
using System.Threading.Tasks;
using Aspose.GIS;
using Aspose.GIS.Geometries;
using Aspose.GIS.IO;
using Aspose.GIS.IO.GeoJson;
using Aspose.GIS.IO.TopoJson;
class Program
{
static async Task Main(string[] args)
{
// Input and output file paths
string inputPath = @"C:\Data\sample.geojson";
string outputPath = @"C:\Data\sample.topojson";
// Initialize reader and writer
var geoJsonReader = new GeoJsonReader(inputPath);
var topoJsonWriter = new TopoJsonWriter(outputPath)
{
// Quantization reduces file size while preserving topology
Quantization = 1e5,
// Preserve feature IDs if needed
PreserveFeatureIds = true
};
// Asynchronously read GEOJSON and write TopoJSON
var geometryCollection = await geoJsonReader.ReadAsync();
await topoJsonWriter.WriteAsync(geometryCollection);
Console.WriteLine("Conversion completed successfully.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment