Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created July 1, 2026 05:14
Show Gist options
  • Select an option

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

Select an option

Save aspose-com-gists/dfda24964c64dd5470fd6d08fa493984 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

Discover how GIS‑focused .NET developers can convert GEOJSON to Topojson with Aspose.GIS for .NET. This guide covers prerequisites, a C# implementation, async streaming, performance tuning for large files, and best‑practice tips, all with a code sample.

Read the full guide here: https://blog.aspose.com/gis/geojson-to-topojson-conversion-in-dotnet-sample-guide/

using System;
using System.IO;
using System.Threading.Tasks;
using Aspose.Gis;
using Aspose.Gis.Export;
using Aspose.Gis.Geometries;
namespace GeoJsonToTopoJsonDemo
{
class Program
{
static async Task Main(string[] args)
{
// Path to the source GEOJSON file
string geoJsonPath = @"C:\Data\sample.geojson";
// Output TopoJSON file path
string topoJsonPath = @"C:\Data\sample.topojson";
// Load GEOJSON into a VectorLayer
using (VectorLayer geoLayer = VectorLayer.FromFile(geoJsonPath))
{
// Prepare export options
var options = new TopoJsonExportOptions
{
// Set topology precision (higher = more accurate, larger file)
Precision = 0.00001,
// Optional: reproject to WGS84 if needed
TargetCoordinateSystem = SpatialReferenceSystem.Wgs84
};
// Open a file stream for async writing
using (FileStream outputStream = new FileStream(topoJsonPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, useAsync: true))
{
// Perform async conversion
await geoLayer.ExportToTopoJsonAsync(outputStream, options);
}
}
Console.WriteLine("Conversion completed successfully.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment