QGIS – Adding Attribute to Polygon Layer with Average of Contained Polylines

attribute-tableaveragelinepolygonqgis

I Have two layers, one is a polygon and the other is a polyline. I would like the solution to be using QGIS.

enter image description here

I want to create a new attribute in the polygon layer that take the average of the attribute (e.g., slope) from all of the polyline segments that cross the border &/or lie within the polygon segment.

For example, in the red selected polygon, there may be 10 different polyline segments that either cross it's border or lie completely within the polygon. I want to create a new attribute, slope, in the polygon that is the average of all of the slope attribute values for all of the polyline segments.

Best Answer

You can use Join attributes by location (summary) to join the polygon layer with the line layer and take the average of the slope values stored in the line attribute table into each polygon in the polygon layer.

Here is an example:

enter image description here

Here is the output:

enter image description here

As you can see above, the selected polygon appended the average slope of the two lines that intersected that polygon.

Related Question