Python scripting allows us to enhance the data management and spatial analysis in QGIS. Most times, spatial data comes from a variety of data providers in a sort of formats and data types that we have to be adapted to the GIS standard. Big data and continuos monitoring create large datasets that have to indexed, sorted and manipulated in a effective way.
QGIS has a Python console and the capability to install external Python packages that run on QGIS session. This time we have installed Pandas in QGIS to handle the data from a sensing device for air quality monitoring made on a Raspberry Pi 3 and then we have defined the path as a succession of points with PyQGIS scripting.
You can read the whole description on the sensing device on this post:
This is the final Python code:
import os import pandas as pd os.chdir('C:\Users\Saul\Documents\Ih_CreateLineFromPointswithPyQGIS') lista = os.listdir(os.getcwd()) print(lista) datos = pd.read_csv(lista,parse_dates=True,index_col=1) datos.sort_index(inplace=True) print(datos.head()) PointList =  for index, row in datos.iterrows(): termino = QgsPoint(float(row['longitude']),float(row['latitude'])) PointList.append(termino) print(PointList) linea = iface.addVectorLayer("LineString?crs=epsg:4326&field=id:integer&index=yes","Linea","memory") linea.startEditing() feature = QgsFeature() feature.setGeometry(QgsGeometry.fromPolyline(PointList)) feature.setAttributes() linea.addFeature(feature,True) linea.commitChanges() iface.zoomToActiveLayer()
You can download the input data on this link.