Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active June 25, 2022 14:09
How to Convert KML to SHP in C#. For more information, please follow the link: https://kb.aspose.com/gis/net/how-to-convert-kml-to-shp-using-csharp/
using Aspose.Gis;
using Aspose.Gis.SpatialReferencing;
namespace AsposeProjects
{
class Program
{
static void Main(string[] args) // Main function to Convert KML to SHP using C#
{
// Load license
Aspose.Gis.License lic = new Aspose.Gis.License();
lic.SetLicense(@"Aspose.Total.lic");
// Create ConversionOptions if required
ConversionOptions options = new ConversionOptions();
// 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.Wgs72))
options.DestinationSpatialReferenceSystem = SpatialReferenceSystem.Wgs72;
// Convert file format from KML to Shapefile.
VectorLayer.Convert("source.kml", Drivers.Kml, "destination.shp", Drivers.Shapefile, options);
System.Console.WriteLine("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment