There are multiple ways to get to your LINESTRINGZMs. Two of those are:
ogr2ogr (not in QGIS)
Since I find it most straight forward here, I suggest a one-step solution using ogr2ogr, hoping that you are familiar with the general idea of command line tools.
In the Terminal/Shell of your choice*, run:
ogr2ogr -f "PostgreSQL" PG:"host=<your_host> port=<your_port> user=<user_with_create_rights> password=<your_password> dbname=<your_db_name>" "<path>/<to>/<shapefile>/<file_name>.shp" -nlt LINESTRINGZM -nln <new_table_name> -sql "SELECT road_code, MakeLine(MakePointZM(ST_X(GEOMETRY), ST_Y(GEOMETRY), elevation, distance)) AS geom FROM <file_name> GROUP BY road_code ORDER BY distance" -dialect sqlite
This will read the shapefile from disk, applies the
-sql query on the shapefile data and imports the results (LINESTRINGZMs) into PostgreSQL/PostGIS (new table
<new_table_name> with columns
This will connect the points by the
distance attribute in ascending order, grouped by the
Don´t forget to fill in all parts in
<>. Note especially the use of
<file_name> as name of your shapefile and name of the table to select from in the
Simply add that table to your QGIS project afterwards, e.g. via Browser Panel.
* On Windows, the necessary ogr2ogr.exe comes shipped with your QGIS installation and can be found in the '/bin' folder; open a Terminal in that folder and run the command from there.
Virtual Layers (in QGIS)
Create a temporary Virtual Layer with similar SQL and results:
- Layers -> Add Layer -> Add/Edit Virtual Layer
- Import -> choose point layer
- Query ->
SELECT road_code, MakeLine(MakePointZM(ST_X(geometry), ST_Y(geometry), elevation, distance)) AS geometry FROM <local_name_of_layer> GROUP BY road_code ORDER BY distance
- click Test to verify, and if all is good, Ok -> done
Import created layer into PostGIS via Browser Panel or DB Manager
or save to file.
Hope that helps; get back with any errors you encounter.