3

I'm somewhat new to QGIS.

I used my Garmin GPS unit to record my tracks while collecting plant specimens for a plant inventory. When I collected each plant I noted the time of collection. I want to get lat/long info for each collection time.

But when I import the GPX file and then save as an .shp file so that I can add lat/long columns, the "time" column is reduced to only the "date" - the hhmm has been removed.

I used XY tools to export the gpx and shp files to get a look at the time column.

The gpx timestamp format looks like this: >>PyQt4.QtCore.QDateTime(2016, 3, 19, 17, 33, 55)

The shp file, looks like this: >>PyQt4.QtCore.QDate(2016, 3, 19)

I'd like to not have to export files to .xls and combine from there, is there a way to retain the original timestamp when converting from GPX to SHP?

  • Welcome to GIS SE! As a new user please take the Tour where you will see that there should be only one question asked per question. – PolyGeo Mar 21 '16 at 21:26
3

This does not seem to be possible in the QGIS GUI, but the underlying ogr2ogr can do it:

From http://www.gdal.org/drv_gpx.html:

ogr2ogr out input.gpx -fieldTypeToString DateTime

You might be able to use it in Python programming as well.

  • This worked like a charm! Thank you so much AndreJ! – Nastassja Mar 23 '16 at 18:16
  • @Nastassja - I agree that this is the best answer (just can't beat one-liner code!). You should accept AndreJ's answer by clicking the green-faded tick on the left-hand side of his answer =) – Joseph Mar 24 '16 at 9:57
3

It is possible to do it through the QGIS GUI although not a very direct route. There is a tool called Refactor fields which you can access from the Processing Toolbox :

Refactor fields from Processing Toolbox

Run this and select your relevant gpx layer. What we need to do is create a new field and essentially copy over the time from the "time" field. So click the button with the plus sign (highlighted by the red circle) and add in the parameters. You will need to use the String type to keep the time format as the Date type only allows 8 characters.

For the expression, you cannot use the column name "time". For some reason, this results in NULL values. Instead, you will need to take an x number of characters from the left side of the field. I used left("time", 20) to take 20 characters from the left. Once done then save it as a shapefile:

Refactor fields on gpx file

Your new shapefile should now contain the original time format in the new field as shown in the green box, compared to the original field as shown in the red box:

Result

  • Thank you so much Joseph for you detailed help! I am having one problem though -- my processing toolbox does not have refractor tools under the Vector Table Tools in the Processing Toolbar. I'll work on that part and post here if I figure out how to add that. Its not in the Plugins helper... – Nastassja Mar 23 '16 at 18:02
  • @Nastassja - Most welcome! Make sure at the bottom of the Processing Toolbox, you are using the "Advanced interface" and not the "Simplified interface". This makes a lot more tools available to you. – Joseph Mar 24 '16 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.