Generating points along a line
You can generate points within a polygon fairly simply using a point in polygon method. But sometimes, you may want to generate points along a line. You can randomly place points inside the polygon's extent, which is essentially just a rectangular polygon, or you can place points at random locations along the line as random distances. In this recipe, we'll demonstrate both of these methods.
Getting ready
You will need to download the following zipped shapefile and place it in a directory named shapes
in your qgis_data
directory:
https://github.com/GeospatialPython/Learn/raw/master/path.zip
How to do it...
First, we will generate random points along a line using a grass function in the Processing Toolbox. We'll then generate points within the line's extent using a native QGIS processing function:
- First, we need to import the processing module:
import processing
- Then, we'll load the line layer onto the map:
line = QgsVectorLayer...