Here is my example:

(1) I creat the grid line layer using MMQGIS plugin
(2) I use line intersection function to get the intersection points.

I want to calculate the distance sum within each grid and save the grid line layer into raster data.

I'm using QGIS 2.8.3.


Sorry for my bad expression.
The polyline represent the road network.
And I want to calculate the distance of road network within the grid which present the road length in this area.

  • Please make your question more clear. You intersect your grid with what? a Road Network? You want the sum distance of what? The road network inside each grid? Dec 30, 2015 at 15:48

2 Answers 2


I suppose you had better to change your grid layer into a polygon layer. You can use the processing toolbox for this purpose. Using the simplified interface select Geoalgorithms/Vector/Create/Create graticule. The grid type should be Rectangle (polygon) and set up the other parameters. enter image description here

Add a new unique column to the polygons of the grid layer using the Field calculator from the toolbar of the attribute table. enter image description here

Intersect your line layer with the grid polygon, again from the processing toolbox: Geoalgorithms/Vector/Overlay/Intersection. enter image description here

Now you have a new layer where your lines are cut by the grid polygons and the lines got the attributes of the grid, too.

Add a new field to the intersection layer with the length of the line segments, again using the Field calculator. enter image description here

Finally sum up the length of the lines having the same id (inside the same grid cell) using the processing toolbox Geoalgorithms/Vector/Statistics/Statistics by category. enter image description here

You find the answer to your question in the "sum" column.

Values in the dialogs should be changed considering your data!


Your grid cells must be polygons first to get lines length in it, there is no way around that.

  1. You should be able to replicate your grid as polygons through Vector / Research Tools / Vector Grid...
  2. To get lines length within each cell, use Vector / Analysis Tools / Sum Line Lengths...
  3. To Rasterize the polygons use Raster / Conversion / Rasterize (Vector to Raster)...

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.