Created
May 21, 2026 08:15
-
-
Save aspose-com-gists/a94a4a2cd22ae094dd8bf95b4d034078 to your computer and use it in GitHub Desktop.
GEOJSON to Topojson Conversion in .NET: Sample Guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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