You can read all the details at: Convert GeoJson to TopoJson and vice versa using C#
Last active
December 23, 2021 07:23
-
-
Save aspose-com-gists/2da6c458edc3e9005980432ae333d3f6 to your computer and use it in GitHub Desktop.
Convert GeoJson to TopoJson or TopoJSON to GeoJSON programmatically using C#
This file contains 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
// convert GeoJSON to TopoJSON with quantization - transforming doubles to integers to reduce file size. | |
string SampleGeoJsonPath = dataDir + "sample.geojson"; | |
var outputFilePath = dataDir + "convertedSampleWithQuantization_out.topojson"; | |
// Initialize ConversionOptions class object | |
var options = new ConversionOptions | |
{ | |
DestinationDriverOptions = new TopoJsonOptions | |
{ | |
// There are two ways to set quantization parameters - with Transform property or | |
// with quantization number. Here we specify quantization number. | |
// Quantization number specifies number of expressible values per dimension in a result | |
// coordinates. | |
QuantizationNumber = 100_000, | |
// Alternatively, 'Transform' property can be set (but not simultaneously with quantization number). | |
// Refer to TopoJSON specification for more details on transform object and quantization. | |
// | |
// Transform = new TopoJsonTransform( | |
// xTranslate: 0, | |
// yTranslate: 0, | |
// xScale: 0.0001000010000100001, | |
// yScale: 0.0001000010000100001), | |
} | |
}; | |
VectorLayer.Convert(SampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson, options); |
This file contains 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
// Load input GeoJSON file | |
string sampleGeoJsonPath = dataDir + "sample.geojson"; | |
var outputFilePath = dataDir + "convertedSample_out.topojson"; | |
// convert GeoJSON to TopoJSON | |
VectorLayer.Convert(sampleGeoJsonPath, Drivers.GeoJson, outputFilePath, Drivers.TopoJson); |
This file contains 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
// Load input TopoJSON file | |
var sampleTopoJsonPath = dataDir + "sample.topojson"; | |
var outputFilePath = dataDir + "convertedSample_out.geojson"; | |
// Convert TopoJSON to GeoJSON file | |
VectorLayer.Convert(sampleTopoJsonPath, Drivers.TopoJson, outputFilePath, Drivers.GeoJson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment