Coding with tracklib in QGIS (ubuntu)#
If you want to run tracklib as an 3rd party python library for QGIS, it’s possible. First you have to configure QGis environment,
then you can test if the example below.
Set environment#
Install tracklib
pip install tracklib
Check in the QGIS Python Console with which version of python, Qgis runs. To find out where:
import sys
sys.executable
>> '/usr/bin/python3'
Then install dependencies in linux console:
/usr/bin/pip3 install tracklib
At the end, check if the python’s site-packages directory is in the qgis path:
The location of python’s site-packages directory can be found using:
/usr/bin/python3 -m site --user-site
Open QGis desktop, then the python console
Display the QGis system path:
print (sys.path)
if the python’s site-packages directory is not in the QGis system path, add it like this:
sys.path.append('here_python's site-packages directory')
Run the example#
The example load a CSV file containing routes (geometry defined by a wkt) and display it in QGis desktop.
import tracklib as tkl
csvpath = '/home/glagaffe/tracklib/tracklib/data/lacet/ecrins.csv'
tracks = tkl.TrackReader.readFromWkt(csvpath, 0, 1, 2, ",", 1, "ENUCoords", None, True)
trace = tracks["917262","%"][0].extract(22, 180)
trace.resample(5, tkl.MODE_SPATIAL)
vqgis = tkl.QgisVisitor()
trace.plotAsMarkers(v=vqgis)
The result looks like this:
Display a track computed by tracklib in QGis#