3

enter image description hereI'm trying to create random points on a line within a grid cell. I have a river layer within a state boundary. I have placed a grid over the state boundary. I would like to assign 5 random points along the river line with each grid cell in the state layer.

  • Hi Christine, What software are you using? – Gabriel De Luca Feb 15 at 2:01
  • Hi Gabriel, I’m using QGIS – Christine Feb 15 at 23:17
1

I think it would help with some more explaining. An illustration may help.

From what you have written, I guess that you could

  1. Clip the river using the state polygon (to remove the parts of the river that are outside the state boundary) using the Clip algorithm.
  2. Use your grid to split the river into parts using the Intersection algorithm.
  3. Generate points on the lines using the Random points along line algorithm. Only problem is that this algorithm does not do what it is supposed to do... See comments below.

Update

After learning about the behaviour of the Random points along line algorithm, I made a new QGIS Processing algorithm (Random points on lines) that will create random points on each feature of a line dataset (see PR: https://github.com/qgis/QGIS/pull/34631). It supports multi-geometries, so if your river crosses a grid boundary more than two times, you can still generate the specified number of points distributed over the river parts within that grid cell.

  • Random points along line tool doesn't work in that way. See: Incorrect short help for "Random points along line" algorithm. – Gabriel De Luca Feb 16 at 0:38
  • From the documentation: This algorithm creates a new point layer, with points placed in the lines of another layer. For each line in the input layer, a given number of points is added to the resulting layer. A minimum distance can be specified to avoid point being too close to each other. – Håvard Tveite Feb 16 at 0:39
  • The documentation must be fixed. – Gabriel De Luca Feb 16 at 0:41
  • That seems to be the case, yes! – Håvard Tveite Feb 16 at 0:44
  • Thank you so much for your help! I've tried many methods and am just not getting what I need. I'm sorry if it wasn't clear. I have attached a picture.I need 5 random points on the rivers per grid cell so that each individual grid cell has 5 points within it. I have been able to assign points to the river layer and the state separately but not combining them to get the individual cells. – Christine Feb 18 at 21:33

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.