You can find detailed information at: Convert KML to GeoJSON and GeoJSON to KML using C#
Last active
November 18, 2021 17:47
-
-
Save aspose-com-gists/e8f70865580779f27bfa7c896a963160 to your computer and use it in GitHub Desktop.
Convert KML to GeoJSON and GeoJSON to KML 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
string dataDir = RunExamples.GetDataDir(); | |
string sourceFile = dataDir + "intersection.geojson"; | |
string outputFile = dataDir + "output.kml"; | |
// Specify conversion settings if necessary. It is optional. | |
ConversionOptions options = null; | |
// This options assigns Wgs84 to the destination layer. | |
// Conversion may throw error If destination layer does not support the Wgs84 spatial reference. So need to check. | |
if (Drivers.Shapefile.SupportsSpatialReferenceSystem(SpatialReferenceSystem.Wgs84)) | |
{ | |
options = new ConversionOptions() | |
{ | |
DestinationSpatialReferenceSystem = SpatialReferenceSystem.Wgs84, | |
}; | |
} | |
// Convert file format from GeoJSON to KML. | |
VectorLayer.Convert(sourceFile, Drivers.GeoJson, outputFile, Drivers.Kml, 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
string dataDir = RunExamples.GetDataDir(); | |
string sourceFile = dataDir + "Kml_File.kml"; | |
string outputFile = dataDir + "output.geojson"; | |
// Specify conversion settings if necessary. It is optional. | |
ConversionOptions options = null; | |
// This options assigns Wgs84 to the destination layer. | |
// Conversion may throw error If destination layer does not support the Wgs84 spatial reference. So need to check. | |
if (Drivers.Shapefile.SupportsSpatialReferenceSystem(SpatialReferenceSystem.Wgs84)) | |
{ | |
options = new ConversionOptions() | |
{ | |
DestinationSpatialReferenceSystem = SpatialReferenceSystem.Wgs84, | |
}; | |
} | |
// Convert file format from KML to GeoJSON | |
VectorLayer.Convert(sourceFile, Drivers.Kml, outputFile, Drivers.GeoJson, options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment