0

I have two layers in QGIS; one points and one simple lines. Each have an attribute, community, which I'd like to serve as the category variable for assigning color. But I can't figure out any way to make these color-variable assignments identical between the two layers. I can't copy/paste styles, nor can I export a QML and apply it to the other layer, because of their different GeometryType.

Is there any way to do this short of exporting two QML files, one for each layer, and writing some sort of Python script to interchange the <prop k="color" v=" ... "/> in the points style definition, and <prop k="line_color" v=" ... "/> in the lines style definition?

The community variable in both layers has >50 possible values, so it's too cumbersome to do this by hand.

  • Try creating a simple 1 or 2 classification QML for both line and point layer and open them up with a text editor. There may be a tag in there that defines the geometry type which you might be able to do a find and replace on to switch the geometry so you do not have to spend time created the full QML for both layer geom types. – artwork21 Apr 25 '18 at 13:12
1

I'm not sure if anyone has better ideas on how to solve this, but here's one workaround which I found worked OK:

  • Create a new CSV file with two columns, community and color
  • Write in 50 community, color pairs into that CSV, using "r,g,b" as the color format. (I used this online color generator to auto-generate 50 distinct colors.)
  • Import that CSV into QGIS as an attribute-only layer
  • Join that new layer to both my points layer and my lines layer using the community field as the join
  • In each geometry layer, use the newly-joined color field as a data-defined variable for either point color or line color

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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