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

shp to GPX

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.

Free Conversion Tool – Simply upload and convert SHP to GPX/GPS

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=”” xmlns:ogr=”” xmlns=”″ xsi:schemaLocation=””>
<metadata><bounds minlat=”7.925284332688660″ minlon=”68.498222433926088″ maxlat=”35.501281464128759″ maxlon=”97.334792107009250″/></metadata>
<ogr:MED_DESCRI>Without Median</ogr:MED_DESCRI>
<ogr:RTT_DESCRI>Secondary Route</ogr:RTT_DESCRI>
<trkpt lat=”35.501277495128768″ lon=”77.82774039748233″>
<trkpt lat=”35.499500328132093″ lon=”77.825752306486052″>

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,


Dataset creation option (format specific)

-nlt type:


-f option:



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”;

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.

Author: Akshay Upadhyay

Owner and Director of a Private Limited company which serves individual to large scale industries in the field of Maps and GIS. He is a Gold Medalist in M.Tech(Spatial Information Technology) and owns some famous Technology blogs and website... Know more