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 ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.