The Shapefile format is ESRI’s one of the most common geospatial vector data formats used to display geographical information. In certain cases, we may need to export geographic data from ESRI Shapefile (SHP) format to SVG format. The SVG is an XML-based text format for describing the appearance of an image. In this article, we will learn how to convert a shapefile to SVG in C#.
This article shall cover the following topics:
C# Shapefile to SVG Converter API - Free Download
To convert a shapefile to SVG, we will be using the Aspose.GIS for .NET API. It allows exporting shapefile to SVG without needing software like ArcGIS, ArcMap, QGIS or Google Earth. The API also allows the rendering of maps, creating, reading, and converting geographic data available in the supported file formats.
The Map class of the API is a collection of layers that can be rendered on top of each other via Renderer. The SpatialReferenceSystem class provides a list of different spatial reference systems to use for the map. We can define a simple vector line symbolizer using the SimpleLine class. We have the VectorLayer class that represents a vector layer in the API. We can load the shapefile into a vector layer using the Open(string, FileDriver) method of this class. It opens the layer for reading.
PM> Install-Package Aspose.GIS
How to Convert Shapefile to SVG in C#
We can easily convert a shapefile to SVG using Aspose.GIS for .NET by following the steps given below:
- Initialize a Map.
- Assign the Wgs84 spatial reference to the map.
- Open a shapefile as a vector layer.
- Add the shapefile layer to the map.
- Render the map in SVG format.
Now, let’s see how to transform these steps into C# code and convert a shapefile file to SVG format.
Render ShapeFile to SVG in C#
Please follow the steps given below to render a shapefile as SVG:
- Firstly, create an instance of the Map class.
- Next, set the SpatialReferenceSystem as Wgs84.
- Then, define a simple line symbolizer using the SimpleLine class.
- Meanwhile, load a shapefile using the VectorLayer.Open() method.
- After that, add the shapefile layer to the map using the Map.Add() method.
- Finally, call the Map.Render() method to save as SVG. It takes the output SVG file path and Renderers.Svg as arguments.
The following code sample shows how to convert a shapefile to SVG using C#.
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
In this article, we have learned how to convert a shapefile to SVG in C#. We have also seen how to define a map and load a shapefile programmatically. Besides, you can explore how to work with several other GIS file formats and learn more about the API using documentation. In case of any ambiguity, please feel free to contact us on our free support forum.