SHP to GPX / GPS – Convert Shapefile to Global Positioning System

Shapefile shp can be converted into GPS ( Global Positioning System) using ogr2ogr utility. The GPS data is best option when routes and tracks are required in XML format. Here we will check how to convert shapefile shp to GPX / GPS.

Convert Shp to GPX – Using IGIS Map Tool

Go to MapOG Conversion Tool . Login with registered id and password or if you are new then register with valid email id. Then tap on Switch To button select conversion in the drop down list.

Upload your file from system or drive or from drop box. After uploading the file choose the output format. And in the last click on Convert File button. You will be directed to the map where converted file is published.

Download the converted SHP to GPX file from the download icon. For detailed conversion watch the video provided below.

Details for GPX/GPS (GPS Exchange Format) and Shapefile Format Before Converting Shapefile to GPX GPS data-

GPX (GPS Exchange Format) is a light-weight XML data format for the interchange of GPS data (waypoints, routes, and tracks) between applications and Web services on the Internet. Shapefile is collection of geometry with attributes mainly comprised of three files .shp for which stores geometry, .shx which stores index and .dbf which stores data of respective attributes.

The example is given below for linestring feature of gpx version. Here metadata contains the bounding box with min (lat,long) and max (lat, long). The tag trk defines the tracks, which contains extension tag, trkseg tag and trkpt tag. Here extension tag contains all the attributes in ogr tag with values. Trkseg tag is the track segment, which is composed of track points with latitude longitude.

<gpx version=”1.1″ creator=”GDAL 2.2.2″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:ogr=”http://osgeo.org/gdal” xmlns=”http://www.topografix.com/GPX/1/1″ xsi:schemaLocation=”http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd”>
<metadata><bounds minlat=”7.925284332688660″ minlon=”68.498222433926088″ maxlat=”35.501281464128759″ maxlon=”97.334792107009250″/></metadata>
<trk>
<extensions>
<ogr:MED_DESCRI>Without Median</ogr:MED_DESCRI>
<ogr:RTT_DESCRI>Secondary Route</ogr:RTT_DESCRI>
<ogr:F_CODE_DES>Road</ogr:F_CODE_DES>
<ogr:ISO>IND</ogr:ISO>
<ogr:ISOCOUNTRY>INDIA</ogr:ISOCOUNTRY>
<ogr:Length_km>0.3</ogr:Length_km>
</extensions>
<trkseg>
<trkpt lat=”35.501277495128768″ lon=”77.82774039748233″>
</trkpt>
<trkpt lat=”35.499500328132093″ lon=”77.825752306486052″>
</trkpt>
</trkseg>
</trk>

Convert- Shapefile shp to GPX / GPS- Global Positioning System

Convert shp to GPX /GPS using ogr2ogr utility-

Ogr2ogr utility has some options some of them are give below,

-dsco NAME=VALUE:

Dataset creation option (format specific)

-nlt type:

Define the geometry type for the created layer. One of NONE, GEOMETRY, POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTIPOINT, MULTIPOLYGON or MULTILINESTRING.

-f option:

format_name

GPX_USE_EXTENSIONS:

By default, the GPX driver will discard attribute fields that do not match the GPX XML definition (name, cmt, etc.).

If GPX_USE_EXTENSIONS=YES is specified, extra fields will be written inside the <extensions> tag.

–> ogr2ogr -f “GPX” -dsco GPX_USE_EXTENSIONS=YES output_gpx.gpx India_raods.shp -nlt MULTILINESTRING

If you don’t have ogr2ogr utility in your system please execute the given commands to install ogr2ogr,

Convert- shp to gpx

Check the presence of utility by typing ogr2ogr in command prompt-

Convert- shp to gpx

Code to Convert GPX GPS from Shp

The conversion thing can be done in PHP using shell_exec() method, given below-

public function shptogpx ($shpfilepath,$output,$type) {
$query=”ogr2ogr -f GPX -dsco GPX_USE_EXTENSIONS=YES $output.gps $shpfilepath.shp -nlt $type”;
shell_exec($query);
}

Convert- shp to gpx

Change coordinate system of GPS/GPX file-

Changing coordinate system using ogr2ogr is a one of the simple task. It has various option, here two are given, which will help to convert the coordinate system into desired one.

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

So using these option, we can get the data in required coordinate system. So for this you can write the query as-

–> ogr2ogr -f GPX -t_srs EPSG:32643 (new EPSG) -s_srs EPSG:4326 (old EPSG) -dsco GPX_USE_EXTENSIONS=YES newGPX_File.gpx  InputFile.shp -nlt MULTILINESTRING

You also can visit Shapefile to GeoJSON, Shapefile to KML, Shapefile to TopoJSON, Shapfile to geopackage, Shapefile to MapInfoFile etc.

If you find any problem during implementing this tutorial, please let us know. Feel free to comment in given comment box.

Convert Shapefile to GeoPackage – GPKG

GeoPackage is an open, standards-based, platform-independent, portable, self-describing, compact format for transferring geospatial information. Whereas shapefile is collection of geometry with attribute detail. Here in this article, we will check how to convert Shapefile to GeoPackage or GPKG GIS format.

Online Tool To Convert Shapefile to GeoPackage file

The GeoPackage Encoding Standard describes a set of conventions for storing the following within an SQLite database:

1. Vector features
2. Tile matrix sets of imagery and raster maps at various scales
3. Attributes (non-spatial data)
4. Extension

Convert Shapefile to GeoPackage - GPKG
Convert Shapefile to GeoPackage – GPKG

You can open the gpkg (GeoPackage) file in QGIS software and see some of the general properties of gpkg (GeoPackage) file-

1. Storage type of this layer
–> GPKG
2. Description of this provider
–> OGR data provider (compiled against GDAL/OGR library version 2.2.2, running against GDAL/OGR library version 2.2.2)
3. Source for this layer
–> /var/www/html/PHP_pgrouting/public/outputllll.gpkg
4. Geometry type of the features in this layer
–> Line
5. The number of features in this layer
–> 19148
6. Capabilities of this layer
–> Add Features, Delete Features, Change Attribute Values, Add Attributes, Delete Attributes, Fast Access to Features at ID, Change Geometries, Presimplify Geometries, Presimplify Geometries with Validity Check
7. Extents
–> In layer spatial reference system units
xMin,yMin 68.4982,7.92528 : xMax,yMax 97.3348,35.5013
8. Layer Spatial Reference System
–> +proj=longlat +datum=WGS84 +no_defs

Convert Shapefile to GeoPackage – GPKG  using OGR2OGR-

The command has some options, which can be seen by typing ogr2ogr in terminal. If this gives you error that means you don’t have ogr2ogr utility in your system. To install that you can follow the statements given below-

If Ogr2ogr utility is available, you will see the following result.

The command is given as-

–> ogr2ogr -f GPKG outp_gpkg.gpkg India_raods.shp

The command contains Utility name, option for file format, name for format, output file with .gpkg extension and input shape file.

To install ogr2ogr utility-
Convert Shapefile to GeoPackage - GPKG
Convert Shapefile to GeoPackage – GPKG

To check  if ogr2ogr utility is working properly or not-

Convert- Shapefile to GPKG- GeoPackage

Online Tool To Convert Shapefile to GeoPackage file

PHP Code to Convert Shapefile to GeoPackage – GPKG-

Using shell_exec() method, you can run the command in PHP. This return output as string.

public function shptogpkg($shpfilepath,$output) {
$query=”ogr2ogr -f GPKG $output.gpkg $shpfilepath.shp”;
shell_exec($query);
}

The output file can be open in QGIS software. I have converted Road File of one such country. Here is the output look in QGIS tool after Converting Shapefile to GeoPackage.

Convert Shapefile to GeoPackage - GPKG

Change Coordinate system of Output-

Many of times, we need the output file in other coordinate system. For this we can use options of ogr2ogr utility. It has

-a_srs srs_def:

Assign an output SRS

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

So using these option we can get the data in required coordinate system. So for this you can write the query as-

—> ogr2ogr -f GPKG -s_srs EPSG:4326 -t_srs EPSG:32643 Output_file_name.gpkg Input_file_name.shp

Here define old EPSG (European Petroleum Survey Group) in -s_srs option and new in -t_srs option.

You may also Check Shapefile to GeoJSON, Shapefile to KML, Shapefile to TopoJSON, etc conversion.

Let me know if you find any problem in converting Shapefile to GeoPackage file, by commenting below in the box provided.

Convert Shapefile to TopoJSON

ESRI shapefile are the binary vector data storage format for storing the location, shape, and attributes of geographic features. It is stored as a set of related files and contains one feature class. Whereas TopoJSON (topological geospatial data) is an extension of GeoJSON that encodes topology. The necessity of conversion is to reduce the size of data. While using Shapefile, you have to take care of all its mandatory files such as .shp, .shx, .dbf, .prj etc. Whereas GeoJSON and TopoJSON formats are single file formats.

There are many online and desktop application based solutions to do this conversion. But the method everyone looking forward is an easy way to convert a file to a preferred format. In this article we will see how easy is IGISMAP for the conversion process. Following are the methods to convert Shapefile to TopoJSON using IGISMAP Converter tool.

Use Online Converter Tool – Shapefile to TopoJSON MapOG

IGISMAP (Now MAPOG) to Convert Shapefile to TopoJSON

Go to MAPOG Converter Tool, after logging in with your registered email and password. If you are a new user, click the Sign Up button in the Login popup and register to IGISMAP by filling the details.

There are three main steps for using GIS Converter:

  • Upload the data
  • Choose the format to which it should be converted
  • Download the converted file.

Step one is to upload your Shapefile which you want to convert. You can upload the file from your system or select from the Recent Files.

Converter Tool - Upload Shapefile
Upload Shapefile

Here we using the Shapefile of India state level boundaries with demographic information. You can find this data in IGISMAP GIS Data Collection –

Step two is to select choose the output format of the converted file, in this case its TopoJSON. You can also set the Coordinate Reference System of your preference. As a default CRS will set to WGS 84 (World) [EPSG:4326]. Click on the Convert File button.

Converter Tool - TopoJSON as Output Format
Select TopoJSON as Output Format

Your Shapefile will then get converted to TopoJSON file after a few seconds and will be published in the map canvas. You can download the TopoJSON file of New York state boundary by clicking the Download Converted File button.

Download and Publish TopoJSON File
Download and Publish TopoJSON File

You can also choose to style the layer or continue with further conversion process by clicking the Convert Another File button.

Converted Files section from the dashboard contains the list of the details of all the conversion done in your account, providing both input and output data available for download their corresponding formats.

IGIS Map Converter Tool provides many benefits other then just conversion of data. This tool provides us to generate this published map in PDF or as image format.

Info GIS Map supports most of the commonly used GIS or AutoCAD files like Shapefile SHP, KML, KMZ, CSV, TopoJSON, GeoJSON, GML, DXF, GeoTIFF, NetCDF, GRIB, HDF5, OSM, PBF, and many more raster and vector files, along with that it support more than 4000 Coordinate Reference System.

Here are other two ways to convert shapefile to topojson

Use Online Converter Tool – Shapefile to TopoJSON MapOG

Offline Method : Convert Shapefile to topojson through GDAL and then through geo2topo tool npm:

To convert shape file to topojson format offline you need to download GDAL and Node.js.  First step is to convert shapefile to geojson data format, which is done by using ogr2ogr command available in GDAL package. After successful installation check ogr2ogr availability by typing ogr2ogr in command prompt or by typing dir that will show all available directories.

convert shapefile to topojson

Now you can convert shapefile to geojson data format by using given command

  • Ogr2ogr –f Geojson file_name.json input.shp

Here –f option is used to shows the file format, which shows output file format is geojson. GDAL takes name of output file prior to input file.

Convert geojson to topojson:

Now to convert geojson data to topojson data format you have to download node.js which is available https://nodejs.org/en/ here. After successful installation you need to check npm availability using command

  • npm –check.
convert shapefile to topojson

If not available use

  • npm install -g npm-check

After this you need to install topojson-server for conversion of data that can be done by using

  • npm install topojson-server command

Now all setup is ready

Use geo2topo command to convert geojson data to topojson data

  • geo2topo –o geo.json topo.json

Here –o option is used to give the output. If command doesn’t run and gives error as no such file or directory. Then specify full path for file for both input and output. The older versions were having topojson as a command to convert geojson data format to topojson data format. Topojson is named as geo2topo command in new version.

Convert Shapefile to TopoJSON – Online Method

Mapshaper is an online tool that converts shape file to topojson data format directly. You only need to drag the shape file to http://mapshaper.org/ site. Then use export option to convert this data into topojson format. In Mapshaper there are many option are available to simplify the geometry, which you can explore.

convert shapefile to topojson
convert shapefile to topojson

You may also look over converting kml to shapefile and shapefile to kml conversion.

I hope this article helped you in converting the file from Shapefile to TopoJSON. If you find any problem in performing operation do let me know by commenting below.

Convert GeoJSON to TopoJSON – GIS

Convert GeoJSON to TopoJSON. GeoJSON is an open standard format designed for representing simple geographical features, along with their non-spatial attributes, based on JavaScript Object Notation. The need of conversion is to reduce the size of data, so that rendering of data on browser can be made faster. TopoJSON (topological geospatial data) is an extension of GeoJSON that encodes topology. Here we have explored two methods for conversion of GeoJSON to TopoJSON (i.e. online and offline).

Use Online Converter Tool – Geojson to TopoJSON MapOG

Offline Method to Convert GeoJSON to TopoJSON:

You can directly convert GeoJSON to TopoJSON with the help of topojoson-server node package manager. For using this package you need to first install node js in your system (can be installed in windows, linux based operating system or Mac).

If you have Shapefile or KML file, then you can refere this articles i.e convert kml to shapefile, convert shapefile to GeoJSON and converting shapefile to kml, so that you can generate new GeoJSON file out of other GIS format files.

Convert GeoJSON to TopoJSON – NPM method

NPM (Node Package Manager) is a command-line utility that aids in package installation, version management, and dependency management or can be considered npm as a tool that helps to install another tools like topojson-server.

For this method you need to download node.js which is available https://nodejs.org/en/ here. After successful installation you need to check npm availability using command

  • npm –check.

If not available use

  • npm install -g npm-check

convert geojson to topojson
convert geojson to topojson

After this you need to install topojson-server for conversion of data that can be done by using

  • npm install -g topojson-server

Now all setup is ready

Use geo2topo command to convert geojson data to topojson data

  • geo2topo –o geo.json topo.json

Where geo.json is the geojson file i.e input file and topo.json is the file we are creating with the name topo as topo.json file i.e output file.

Here –o is output. If command doesn’t run and gives error as no such file or directory. Then specify full path for file for both input and output. It is recommended that you run this command from the same directory where geo.json file is stored.

If you don’t have any input files ready or any geojson or shapefile then you can download free GIS data fromat for testing this article.

Online method: Convert GeoJson to TopoJson

This is the simple and fast method. For the conversion you just need to drag the geojson file in http://mapshaper.org/ site. Then use export option to convert this data into topojson format. Map shaper website render and convert the file in the browser itself, but it you might face problem while converting a big geojson file. 

I hope that this methods listed above to convert geojson to topojson would have helped you in achieving result. If you find any problem or know any other method to perform this operation and want to share with us, then do let us know by commenting below, in the box provided.

Different ways to convert Shapefile to GeoJSON – Online or Offline or API

Convert Shapefile to GeoJSON. Shapefile, ESRI made a standard vector file format which is largely adopted in the field of GIS by programmers and geographers . While GeoJSON is also an open standard format designed for Web which largely supported with GIS JavaScript API, other programming API and with GIS (Geographic Information System) software tools too, for easily rendering. GeoJSON is based on JavaScript Object Notation. Here we will explore different methods to convert the files online, or offline or with the help of API which programmers can make use of.

Convert shapefile to geojson

You may be interested to refer following articles:

Different ways to convert Shapefile to GeoJSON

I.) Online Method : Convert Shapefile to GeoJSON:

The simplest and fast way to access the internet is through the online method, as you don’t need to install and configure any tool on your PC. Just drag the Shapefile files, one click on button and convert to GeoJSON. There are many website which provides the tool to convert the files by browsing them to server side and convert and also some client side conversion too. Lets explore the list, which is only client side as client side conversion will secure your file and doesn’t take your data pack for uploading the file:

A.) MAPOG Converter Tool :

IGIS Map tool is one stop solution for all GIS data analysis and conversion.

 Shapefile to Geojson Conversion

  •  Go to the tool MapOG Converter Tool.
  •  If you are already registered then login otherwise sign up.
  • Once get register tap on Converter Button Shown in figure.

Convert shapefile to geojson

  • Upload the Shapefile from data set or Google Drive or Drop Box or already added in drive then choose the file. Lets we want to convert already uploaded file from My Drive then select the file.

Convert shapefile to geojson

  • Tap the file and new window will appear shown below.

Convert shapefile to geojson

  • Select the desired Output in our case choose Geojson. You can also change CRS. Now tap on Convert file button.

Convert shapefile to geojson

  • It will so the table in the next step. You can directly download the converted file or you can check it through clicking on publish button.

Convert shapefile to geojson

  • Below is the screen of published Geojson file.

Convert shapefile to geojson

Whole process is same from new uploaded file from data set or from google drive or from drop box. If you face any problem ping us at website.

You might be interested in Query on Geojson data file then try our tool IGIS Map tool.

This is presented by Engineer Philosophy pvt. ltd, working in GIS Sector an IT company. What you need to do is to just Register, login and upload only .shp and .dbf file and then export the uploaded layer to GeoJSON file by just selecting the option which appear at upper right corner in Navigation bar. You can also explore the attribute table from the website directly and filter the same which no other online tool provides.

different ways to convert Shapefile to Geojson - Online or Offline or API
different ways to convert Shapefile to Geojson – Online or Offline or API

Not only this, but you can classify the Map according to the shapefile dbf attributes and automatically classify and color it. The classified map can be exported as Scalable Vector Graphics i.e svg file.

Disclaimer: The above project is handled by me and my team and the project is in beta phase while you can definetly convert the shapefile to GeoJSON at client side securing your shapefile data. I would welcome your suggestion to improve the tool by commenting below or contacting me.

B.) Map Shapper : 

Map Shapper is the best tool which we should refer first. It is the best online tool which also handles large shapefiles and renders it quickly. Its an open source project and is licensed under MPL 2.0. Just drag the shapefile or zipped shapefile which will render the shapefile on map and can be further exported as geojson file with the option provided in tool itself.

different ways to convert Shapefile to Geojson - Online or Offline or API

With No doubt Map Shaper is much more better than any other tool for now, while the only reason why I placed this tool in second place just because the first tool was my own tool which provides more option for classifying the map, see all attributes in the data table and also exported as svg file.

2.) Offline Method – Convert Shapefile to GeoJSON in QGIS:

You must have installed QGIS  (Quantum GIS) before performing the provided steps. You may also look over other tutorial in QGIS.

1.) Open QGIS Desktop and Select Layer -> Add Layer -> Add Vector Layer or click on Add Vector layer icon appears at the upper left in the application.

different ways to convert Shapefile to Geojson - Online or Offline or API
different ways to convert Shapefile to Geojson – Online or Offline or API

2.) Select the zipped shapefile or any of file i.e .shp or .dbf or .shx by browing the folder. Note, that all the three files i.e .shp, .dbf and .shx file should be present in the same foder with same name.

3.) Once uploaded, the map will be rendered and showed in QGIS application. Now navigate to Layer menu and select Save As option or just from the layers panel select the layer and right click from it to select Save As option.

4.) A window pop up will opne up. From the window just select the GeoJSON format and provide the name of the file in the input box as shown in the image provided below. Save the file. It will export the file in GeoJSON format.

different ways to convert Shapefile to Geojson - Online or Offline or API

3.) Offline Method – Convert Shapefile to GeoJSON with command line ogr2ogr tool:

Firstly you need to install an ogr2ogr tool of GDAL which is a GIS utlitly command line tool so as to convert one file to another. Now if the ogr2ogr is installed globally check by simple tying the ogr2ogr in command line if it is working or not. Or if it residing in some file system you need to navigate to ogr2ogr file and type in the same in command line. Now Just type in the following:

  • “ogr2ogr -f GeoJSON -t_srs crs:84 [name].geojson [name].shp”

To get more option list and format you may see this gdal org link.

This tool will be helpful if you want to convert bulk files from shapefile to geojson. You can refer the .sh script found at github.

4.) Convert Shapefile to GeoJSON -API or library:

Shapefile is a binary file and cannot be viewed directly in notepad or textpad as like with GeoJSON file. So if you want to create your own API, to convert Shapefile to GeoJSON you should first have a knowledge of how to read the binary shapefile. You may refer to some of the articles which I have written some post which would help you to get the basic knowledge to know the format of files and read.

You may further refer to some of the best Shapefile to GeoJSON converter API which is open source project:

https://github.com/wavded/js-shapefile-to-geojson :  This is dedicated library to convert to GeoJSON, created by Marc Harter and Licensed with MIT.

https://github.com/gipong/shp2geojson.js : This library is also MIT Licensed and is inspired by the above wavded library which uploads zipped file of shapefile. The library provided an example to use with leaflet js.

https://github.com/mbloch/mapshaper : Map Shaper as desricbed above is licensed under MPL 2.0 and can be very useful if you want to convert to GeoJSON as well as TopoJSON.

Hope this article helped you. If are facing some problem in converting the shapefile to geojson do comment below with the problem statement. We will definitely look over that. Also you can provide your valuable comment below if you are using any other library or tool to cover the same.

Upload Excel latitude longitude in QGIS as Spatial Layer

Upload Excel latitude longitude in QGIS as Spatial Layer and save as Shapefile.  When you have collection of point data i.e latitude and longitude, stored in Excel file in different column, then you can easily view and Save it as Vector layer file in QGIS(Quantum GIS). Well after uploading Excel latitude longitude values as spatial layer,  you are only one step back, to convert the Excel data in Shapefile or KML or any vector file.

Upload Excel latitude longitude in QGIS as Spatial Layer
Upload Excel latitude longitude in QGIS as Spatial Layer

Before starting the exercise, you need to have a data excel file, which should be convert to Comma Delimited .csv file(Depends upon your choice, Comma delimited is common). To convert Excel file in .csv file, open the file and select save as type “CSV (Comma delimited) (*.csv)”. Name the file and save it.

  • Note: If you are using old version of QGIS then, do download and install plugin “Add delimited text layer”.  To install a plugin,
  • Go to Plugins -> Manage and install Plugins, search for “Add delimited text layer“, and install it.

Visit this page to see more tutorial in QGIS.

Steps to Upload Excel latitude longitude in QGIS as Spatial Layer

You should have an already downloaded and installed QGIS , before going through this steps. 

1.) Open up QGIS and click on layer, from menu tab and select Add delimited text layer. 

Upload Excel latitude longitude in QGIS as Spatial Layer
Upload Excel latitude longitude in QGIS as Spatial Layer

2.) Browse the already created .csv excel file, which has latitude and longitude coordinates.

3.) By default, if your column is named as latitude and longitude, then, X will be mapped to longitude and Y will be mapped to latitude. Select OK after mapping X and Y.

Upload Excel latitude longitude in QGIS as Spatial Layer
Upload Excel latitude longitude in QGIS as Spatial Layer

4.) Select the desired coordinate reference system and press OK, the file get uploaded as Spatial layer in QGIS.

Well if you want to convert this uploaded Spatial layer in Shapefile or KML or any other vector file, select on layer, and click on save as. In the open window, select the desired format in which you want to save the file. Done. I suppose this tutorial would be helpful to you. If you are facing any problem, then do comment below.

Convert Shapefile to kml by QGIS

Convert Shapefile to kml by QGIS. Shapefile is ESRI based Vector file, While KML or Keyhole Markup Language is file which models and stores geographic features for display in Google Earth or Google maps. Many times you may require to convert the required shapefile to KML file, so that you can deploy the same over Google Earth for some reason. QGIS (Quantum GIS) is an open source GIS (Geographic Information System) tool, which let you upload the Shapefile and convert the same to KML file. Similarly ogr2ogr is also an open source tool, which let you to convert between GIS data formats. Look over shp to kml convert using ogr2ogr tool which can be marked as an alternative to this article. You can also see to convert Kml to Shapefile and also Shapefile to GeoJSON in QGIS.

You can also try Online conversion instead of QGIS MAPOG Online converter tool

You can also go through other tutorial in QGIS.

Free SHP to KML conversion using GIS Converter Tool in one click.

Here are the steps to convert shapefile to kml:

Convert Shapefile to kml in QGIS

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Convert Shapefile to kml in QGIS:

1.) Open up the installed QGIS.
2.) In the menu bar, select Layer and press Add Vector Layer. Now select the source type in the pop up window opened as File and browse the source Shapefile(Note:Your shapefile .shp, .dbf and .shx file should be in same folder). Press open.

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Select the coordinate reference type system if coordinate reference window appears and press ok.

3.) Right click on the name of Shapefile layer Appearing in the Left upper side and select save as:
or
You can select layer from the menu, and click on save as. (Image below provide demonstrate both the options with the indicator displayed)

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

4.) In the Save vector layer as window, Select the format from the drop down box as Keyhole Markup Language(KML) and browse the folder in which you want to save the KML file . Name it and Press OK.

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Your KML file will be Exported in the directed folder. You can Verify the generated KML file for its validity by uploading the generated KML file to QGIS or uploading KML file in Google map. You may soon find the tool and the coding for the same on this site.

You may check in converting Geojson to Topojson and Shapefile to TopoJSON file. Hope this may help you in converting Shapefile to KML file easily. If you still find problem in converting the file, do let me know by commenting below.

Introduction of QGIS 3.2.1