I have to recreate on QGIS what you can see in the picture below. I have to draw those lines (tree lines) in my field. The rows need to be at exactly 10m far from each other and oriented North-South. I've already created the polygon of the field, but I don't know how to go further.

Could you help me with this?

enter image description here

2 Answers 2

  1. You can use the Create Grid tool for this task.
  2. Also the Clip tool can be useful for removing lines outside the polygon boundaries.

enter image description here


You can use QGIS Expressions either with Geometry Generator or Geometry by expression (see here for details) to automatically create the lines you look for. Use this expression (step-by-step explanation how it works below):

intersection (
    collect_geometries (
            generate_series (
            offset_curve (
                make_line (
                    make_point ( 
                    project (
                        make_point ( 

Screenshot: the expression applied on the polygon layer with Geometry generator. Use Geometry by expression instead to create a new layer with actual geometries: enter image description here

How this solution works:

How this solution works (see next screenshot below):

  1. Create a point (blue dot on the screenshot) at the bottom left of the extent of the polygon layer: make_point (x_min($geometry), y_min($geometry))

  2. Calculate the length of the north-south extent (=the theoretical maximum length a line can have): y_max($geometry)-y_min($geometry)

  3. Create a point (red dot) to the north of the blue dot from step 1, in the distance calculated in step 2. use the function project(point,distance,azimuth) and fill in the expression from step 1 for point and from step 2 for distance - abbreviated in what follows as [1] and [2]. The azimuth should be 0 to get lines in N/S direction. The expression looks like this: project ( [1], [2],0)

  4. Create a line connecting the point from step 1 to the point from step 3 (blue line on the screenshot). Again, replace [1] and [3] with the expressions from the respective step: make_line ( [1], [3])

  5. Shift this line for 10 meters to the right to get the orange line: offset_curve ( [4], -10)

  6. To repeat the shift, add an array_foreach() function. There are several sub-steps necessary:

  • You want to have a line all 10 meters. So start with 0 (the blue line), 10 meters (orange line), 20 meters and so on until you reacht the right corner of the polygon. Thus create an array like [0, 10, 20, 30, 40, 50 .... n], where n is the last line. To calculate n, get the maximum extent of x-coordiante values (the right-most point in your polygon) and substract from it the minimum extent of x-value (the left-most point of the polygon): x_max($geometry)-x_min($geometry). Now you can create the array with generate_series(start,stop,step=10): generate_series (0, x_max($geometry)-x_min($geometry), 10)

  • Now you can use the array created to shift the line for each value in the array: 0 meters, 10 meters, 20 meters, 30 meters .... n meters: array_foreach( [G], [5]) - [G] is to be replaced by the generate_series () expression from above and in the epxression from step 5 ([5]), replace -10 with -@element - you don't want to shift for 10 meters, but for each of the values we created in the array in the generate_series() part of the expression

  1. The output of step 6 is an array of geometries (lines). To convert this to geometries, add collect_geometries ([6]). This is the output you get:

enter image description here

  1. As you only want the lines inside the polygon, add an intersection-funtion: intersection ([7], $geometry)

And here you are with the lines you wanted:

enter image description here

  • 2
    Sometimes I think that using expression or python make it hard, while there is an easier solution :) Apr 28, 2021 at 13:04
  • Indeed... :-) Still, once the solution works, it's nice to see how you can easily change parameters like distance, angle etc.
    – Babel
    Apr 28, 2021 at 13:09
  • 1
    I agree with both opinions. In code, I usually subtract the origin, rotate the polygon by the line heading, fill horizontally with min and max line intersections, then rotate and translate back. Convex polygons are ok, otherwise you get multiple segments. Better to take the easy path in a GIS, and just clip a grid as the answer says. Having said that, next time I look at my code, I'll add in a scale factor for the line spacing, so I can use unit spacing increments :-)
    – wingnut
    Apr 30, 2021 at 8:24

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.