GeoJSON is used for representing geographical features with non-spatial features. Whereas, TopoJSON is an extension of GeoJSON that utilizes Topology. You can convert GeoJSON to TopoJSON as well as TopoJSON to GeoJSON as per your requirements. Let us explore the following use cases in details:
- GeoJSON and TopoJSON inter-conversion – C# .NET API Installation
- Convert GeoJSON to TopoJSON Programmatically using C#
- Convert GeoJSON to TopoJSON with Quantization using C#
- Convert TopoJSON to GeoJSON Programmatically in C#
GeoJSON and TopoJSON inter-conversion – C# .NET API Installation
Aspose.GIS for .NET API can be used to manipulate or convert geographical data. You can easily configure the API by downloading its DLL file from the Downloads section, or via the NuGet gallery with the following installation command:
PM> Install-Package Aspose.GIS
Convert GeoJSON to TopoJSON Programmatically using C#
GeoJSON to TopoJSON file conversion is helpful because it encodes geospatial features and is smaller in file size. It is smaller in file size because of topology and eliminating redundancy. Furthermore, even when there is no shared topology, the fix-precision encoding is way more efficient than floating point encoding of GeoJSON file format. You can convert GeoJSON to TopoJSON with the following steps:
- Load input GeoJSON file
- Convert GeoJSON to TopoJSON
The following code snippet shows how to convert GeoJSON to TopoJSON programmatically using C#:
Convert GeoJSON to TopoJSON with Quantization using C#
GeoJSON to TopoJSON conversion is popular because of the fixed-precision efficiency and lesser file size. Moreover, quantization reduces the precision of coordinates. Resultantly, it optimizes the file size by representing the coordinates as integers. So you can convert GeoJSON to TopoJSON with quantization with the steps below:
- Initialize ConversionOptions class object
- Specify Quantization Number
- Or set Transform property
- Convert GeoJSON to TopoJSON with quantization
The code below shows how to convert GeoJSON to TopoJSON with quantization. It explains two alternative approaches for the conversion:
Convert TopoJSON to GeoJSON Programmatically in C#
Aspose.GIS for .NET API supports TopoJSON to GeoJSON file conversion. So you can add this feature in your .NET applications. Moreover, GeoJSON file are usually preferred in server-side manipulation of geometries which do not require topologies. You can follow the following steps for TopoJSON to GeoJSON conversion:
- Load input TopoJSON file
- Converting TopoJSON to GeoJSON
The following code shows how to convert TopoJSON to GeoJSON programmatically using C#:
Conclusion
In this article, you have learned the differences and suitability of GeoJSON and TopoJSON file formats. Moreover, you have explored how to convert them into each other as per your requirements. Aspose.GIS for .NET API can efficiently and quickly perform the inter-conversion in your applications. Furthermore, you can learn more by visiting the API Documentation. In case of any query or concerns, please feel free to write back to us at the Free Support Forums.
See Also
Create KML File or Read its Features Programmatically using C#