Create Your Own Processing Tools in QGIS

5. Test the NDVI Tool

Now we're ready to test the new NDVI tool.

First we need to download the red and near infrared band from a satellite sensor.

We can do that in different ways, but here we'll use the STAC API Browser plugin and download Sentinel 2A bands for Florence, Italy.

Let's get the extent of Florence in the map canvas.

1. Go to the Browser panel, expand XYZ Tiles and drag the OpenStreetMap layer to the map canvas.

2. In the Locator Bar in the lower left of the screen type

> Florence

The Locator Bar uses the Nominatim Geocoder to search for the location of Florence.

3. Choose the first option. QGIS will zoom to the location.

Now let's use the STAC API Browser plugin to find a recent Sentinel 2A image.

4. Install the STAC API Browser plugin from the Plugins Manager.


5. After installing, click the Open STAC API Browser button that has been added to the Toolbar.

6. In the Search tab, choose Microsoft Planteray Computer STAC API under Connections.

7. Click Fetch collections.

8. Select Sentinel-2 Level-2A.

9. Expand the Filter by date section, check the box and select a recent date range.

10. Expand Extent section and click Map Canvas Extent.

11. Scroll down and click Search.

The results will be shown under the Results tab:

12. Click View assets of the result that you want to use.

13. For Band 4 (Red) and Band 8 (NIR) check the box to Select to add as layer.

14. Click Add selected assets as layers to add them to the map canvas.

15. Close the dialogs.

16. Use the Convert to PCRaster Format tool to convert both layers to scalar rasters.

17. Run the Calculate NDVI tool with the two PCRaster scalar layers.

The output ends up somewhere in the ocean (aka NULL island), because PCRaster doesn't store projection information.

18. Click to set the CRS to same projection as the Sentinel 2 rasters.

19. In the Layers panel, right-click on the NDVI layer and choose Zoom to layer(s) from the context menu. Check if the raster shows up at the correct location.

20. Style the raster with a color ramp that reflects well the NDVI values.

Next you'll learn how to share your tool.