I'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.
I think it would help with some more explaining. An illustration may help.
From what you have written, I guess that you could
- Clip the river using the state polygon (to remove the parts of the river that are outside the state boundary) using the Clip algorithm.
- Use your grid to split the river into parts using the Intersection algorithm.
- 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.
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.