From GPS to PostGIS with simplicity

This article is a simple procedure to import your GPS data into PostGIS without pain, it merely boils down to:

  • Collect your data with your GPS device as always;
  • Export GPS data as GPX file using your device manager;
  • Load GPX file as layer into QGIS;
  • Configure PostGIS connection if not setup yet;
  • Drag and drop layers of interests on the PostGIS source.

And you are done, your layer is now a table in PostGIS database that you can query as you wish. Simple, isn’t it?

Download your data

Depending on your device, this step may be limiting. GPS devices generally allow you to download your data in specific formats.

If you are using a software to export your GPS data it may have an option to download or export the data you can visualize into the GPX format or another compatible GIS format such as KML, GDBFile or ShapeFile. Here we assume it is GPX format but other will do as well with QGIS.

If you chose the GPX format which is a plain text XML data model holding the following information (routes are omited):

  • Tracks: paths GPS recorded as LINESTRING;
  • Track points: points of path GPS recorded as POINT;
  • Waypoints: points of interest user defined as POINT.

Export your data as a GPX file and drag and drop the GPX file into the QGIS Layers are on the left pane.

Setup a PostGIS database

Installation

If you are doing GIS and you don’t have any GIS database, well you are in trouble or an unstoppable craftsman and lucky you, I’ll provide some links.

To be comfortable you need at least 2* pieces of software, but three will also do:

  • PostgreSQL*, the RDBMS that will store your data;
  • PostGIS*, the plugin that will boost GIS into your database;
  • PgAdmin, the admin interface that helps you to manage the database.

Fortunately the PostgreSQL installer provides all in one, just download it and carefully read all instructions, select at least those three products as you will need it. Restart your computer and now you have unleashed the full potential of free and open source GIS.

Security consideration

Open PgAdmin, connect the server and create a new role with specific properties:

  • Setup username and password;
  • Limit the number of connection to something soft like 20;
  • Check the CAN LOGIN option;
  • Leave unchecked SUPER USER and CREATE DATABASE options.

This role will now be used to own the new database and connect it with QGIS.

Database creation

Open PgAdmin, connect the server and create a new database with a sound name. Once the database created open a new query connection and issue the following command:

CREATE EXTENSION postgis;

Configure a PostGIS source in QGIS

Now you have a PostgeSQL+PostGIS, it time to configure the PostGIS source in QGIS. If you don’t have QGIS installed yet, download it (and chose the latest LTR version) and install it.

  • Open QGIS and go to the Browser pane on left;
  • Right click on PostGIS and create new connection;
  • Feed in the new connection dialog with Database connection information (see screenshots);
  • Check the “Allow saving/loading QGIS projects in the database” check box;
  • Test the connection and save.

If the connection test fails, read carefully the error as it will tell you what is not working properly. Not found yet, contact your system administrator. It’s you? No worry, it’s all documented over the internet, just issue the right search query, a copy paste of the actual error message should suffice.

Load GPX in QGIS

Now everything is setup, it’s time to load your data in QGIS. It is as simple as:

  • Drag and drop GPX file onto the Layers side pannel (bottom left);
  • Select which layers to import;
  • Click OK.

After import is performed, you can show on map local layers:

Import layer from QGIS to PostgreSQL

We are one drag and drop away from our goal! To import layer into PostgreSQL database, proceed as follow:

  • Deploy in Browser panel the PostGIS section and find your database connection (here jlandercy);
  • Drag and drop the layer from Layers panel to your database in PostGIS section;
  • Once import is performed a pop up confirm the transaction.

Export layer to another format

Another important functionality you may need is to convert the GPX file into another specific format. To do so:

  • Right click on the layer in Layers panel;
  • Go to Export > Save Feature as…;
  • Fill in the dialog with ad hoc parameters;
jlandercy
jlandercy
Articles: 24