1

I'm using the v.to.lines algorithm (GRASS algorithm) to convert a layer from polygons to lines in QGIS. The algorithm works without problems but the output layer only has an attribute called "cat", I would like to know if it is possible to inherit the attributes of the input layer.

1
  • This isn't an answer, but I want to note that v.to.lines does the same for me.
    – jac
    Commented Oct 10, 2018 at 23:22

2 Answers 2

1

The vector data model in GRASS is an arc-node type, so there's a 2-to-1 relationship between areas and outlines. To carry area data over, the algorithm would have to either choose data from one 'side' of the line, or create a doubled set of attribute columns with data from each side. It looks like doing this is left to the user as a subsequent task.

Having just run v.to.lines on a polygon dataset in GRASS 7.4.1, I see my lines output has two layers. Layer 1 just has 'cat', but layer 2 has three columns - cat, left, and right. The ID's in left and right correspond to the cat of the polygons on either side of the line. This means you can use those fields in a join to pull attribute data into the lines dataset. (e.g. join by lines.left=polygons.cat to get 'left side' polygon attributes).

You can do this via the QGIS layer properties dialog box (assuming you've got the GRASS plugin running etc). In GRASS itself, use v.db.join e.g.

v.db.join map=lines layer=2 column=left other_table=polygons other_column=cat

Repeat as many times as you need for your attributes of interest.

Note 1: I'm not sure what determines which polygon is considered 'left'.

Note 2: I'm noticing that if joins are made with v.db.join in GRASS and then that joined layer is opened in QGIS 3.2.2 (using the GRASS plugin), QGIS gets pretty crashy. It may be more stable to do your joins in QGIS and export to a new dataset, as they aren't persistent.

As jac mentions, QGIS's polygons-to-lines does transfer attributes, but it uses a simple-features data model, so there's a 1-1 parent-child relationship between polygon and line. When polygons are converted to lines, the result is two lines directly on top of each other wherever polygons abut, each with the attributes of their parent area.

2
  • This is interesting. First, I don't think QGIS loads the second layer, so this doesn't exactly help if OP is trying to work exclusively within QGIS (as the question suggests). Also, I don't really follow your join logic. You state, "[t]he ID's in left and right correspond to the cat of the polygons on either side of the line" but what I think we really need is a description of the relationship between the lines and the original polys. For example the feature/object ID from the original polygon layer as an attribute of each line. Right?
    – jac
    Commented Oct 11, 2018 at 22:58
  • No, you can see both layers in the QGIS browser if you have the GRASS plugin configured correctly. And that is a description of the relationship between the lines and the original polys. Line.left[1] refers to poly.cat[1], the ID of the polygon on the left of that line.
    – obrl_soil
    Commented Oct 11, 2018 at 23:05
0

If you are not restricted to using the GRASS tools, then try the QGIS geoalgorithm, "Polygons to lines". It pulls in the attributes from the original polygons.

1
  • That was my first choice, but when I run several nested algorithms for some reason it fails. Commented Oct 12, 2018 at 21:21

Your Answer

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

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