Filtering a layer by geometry

In this recipe, we'll perform a spatial operation to select the subset of a point layer based on the points contained in an overlapping polygon layer. We'll use shapefiles in both the cases, with one being a point layer and the other a polygon. This kind of subset is one of the most common GIS operations.

Getting ready

We will need two new shapefiles that have not been used in the previous recipes. You can download the point layer from https://github.com/GeospatialPython/Learn/raw/master/MSCities_Geo_Pts.zip.

Similarly, you can download the geometry layer from https://github.com/GeospatialPython/Learn/raw/master/GIS_CensusTract.zip.

Unzip these shapefiles and place them in a directory named ms within your qgis_data directory, ...

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.