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?

0

2 Answers 2

4

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.

0
4

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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