I have output from a geophysical technique that produces X,Y,Z and scalar value for millions of points, which have been stitched together appropriately (by networkx if it matters) into multilinestringzm format, then inserted into a PostGIS DB by my own (homebrewed) geophysical code.

There is one multilinestring per Z value (roughly 10-20% of the ~12 million points all share the same Z values), and each of the 10 or so Z values and their corresponding multilinestringzm geometries are in a separate row of the table.

What I'd like to be able to do is color each point in a multilinestring according to its M value, but have been struggling for quite some time in how to accomplish this. (Even better would be to have a color gradient on the line segment between two points.)

I really need to have this work in QGIS (or ARCscene?) because there is a whole lot of other normal 2D GIS info to integrate. My earlier trials outputting my data in VTK format and using VisIt from LLNL to read both the VTK and GIS files, while successful, is too heavyweight to share with my colleagues in joint projects.

Any hints on how to color-by-m-value?

1 Answer 1


QGIS does not colour individual vertices of a geometry, but the entire feature (in this case, one of the 10 or so rows in your table). Likewise you can't colour the individual line segments connecting the vertices. This is a problem on how your data is modeled.

To colour the points, you'd need to work with a point layer. Since you generated your multilinestrings from points that already had an M-coordinate, you can work with those. Alternatively, you can extract all vertices with ST_DumpPoints and feed them to a new table. To colour the line segments, you'd need each to be a separate feature. You can achieve that by creating the aforementioned vertex-extracted point layer and using ST_Split on your multilinestring.

The second problem is the colouring itself. QGIS has a limited access to geometry parameters when styling, and no access to the M-index. You'll have to pass the M-coordinates to a new column in your table (as a float or string, though float would be better, for styling with graduates).

If working with the points approach this is easily done with ST_M, which extracts the M-value and can be inserted in the new column for each point feature. If working with line segments, you'll have two different measurements for each line, one from the first vertex, which you can get with ST_StartPoint and one from the last, which would be ST_EndPoint. You can choose to pass the measurement from each of these, or a mean of the values, or even create two columns (one of starting measure and one of end measure) and style from those.

There could be a way to style directly from the M-coords using PyQGIS, though this is just conjecture.

  • You could style based on the geometry using an expression however QGIS doesn't have access to the M value anyway so that isn't going to save you much.
    – Nathan W
    Mar 25, 2015 at 0:04
  • The simple answer is to wrap your point extract logic in a view and open that in QGIS.
    – Nathan W
    Mar 25, 2015 at 0:05
  • Well reminded, Nathan, I stand corrected. QGIS can style with rules-based expressions accessing some geometric properties (though indeed no M). Edited my answer to include this. Mar 25, 2015 at 11:45
  • I already wound up doing something similar to what you suggested. Basically, I had a many-to-many relationship (layers to points) and I built an association table in PostGIS for that. Each entry in the association table also has an attribute for the mean of the values at the bounding points, and it is straightforward to color on those attributes in QGIS. Bottom line, it would have been better for me to ignore the "M" value of a geometric point in the first place, and just place the value into an attribute. (Damnit Jim! I'm a geophysicist, not a database guru! ;-) Thanks for the help! Mar 26, 2015 at 1:13

Your Answer

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

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