This article provides information on how to convert KML to SHP using C# by sharing the steps to customize the environment and then defining the required procedure to write this application. You will get a step-by-step set of commands that highlight all the required classes, namespaces, and methods required for the conversion. In the end, a runnable sample code is shared to transform KML to SHP using C# that can be executed in MS Windows supporting .NET or Linux and macOS supporting .NET Core.
Steps to Convert KML to SHP using C#
- Establish the development environment to install Aspose.GIS for .NET from the NuGet package manager
- Declare a variable of type ConversionOptions to customize the process
- Check if the destination layer type supports the specific spatial reference system
- Set the desired spatial reference system property in the ConversionOptions class object
- Using the VectorLayer.Convert method convert the source KML to SHP with the selected options
These crisp steps assist for writing the KML to Shapefile converter using C# by introducing the resources that are to be installed for running the sample code. This process can be completed without performing any customization however for better understanding ConversionOptions class is introduced that can be used to set different parameters. In the last step, the actual method is introduced that performs the conversion along with the optional parameter with desired properties.
Code to Change KML to SHP using C#
You can use the last line of code only with the first four parameters only however if you want to assign a specific spatial reference system to the destination layer, only then you may use the ConversionOptions class object. The ConversionOptions class contains other properties also like AttributeConverter, DestinationDriverOptions, DestinationSpatialReferenceSystem, and SourceDriverOptions that can be configured if required. This sample code demonstrates a complete KML to Shapefile converter using C# that can be used as it is.
We learnt here to write a KML to SHP converter using C# however if you want to convert the Shapefile to Geojson, you may refer to the article on how to convert SHP to Geojson in C#.