Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 18, 2023 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b477704606d99159e2fc23ae7c7c5105 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b477704606d99159e2fc23ae7c7c5105 to your computer and use it in GitHub Desktop.
Convert KML to GPX and GPX to KML using C#

Convert KML to GPX and GPX to KML using C#

string dataDir = RunExamples.GetDataDir();
string sourceFile = dataDir + "schiehallion.gpx";
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 GPX to KML.
VectorLayer.Convert(sourceFile, Drivers.Gpx, outputFile, Drivers.Kml, options);
string dataDir = RunExamples.GetDataDir();
string sourceFile = dataDir + "Kml_File.kml";
string outputFile = dataDir + "output.gpx";
// 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 GPX.
VectorLayer.Convert(sourceFile, Drivers.Kml, outputFile, Drivers.Gpx, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment