GIS Workflows typically involve many steps - with each step generating intermediate output that is used by the next step. If you change the input data or want to tweak a parameter, you will need to run through the entire process again manually. Fortunately, QGIS has a graphical modeler built-in that can help you define your workflow and run it with a single invocation. You can also run these workflows as a batch over a large number of inputs.
We will take a point layer of maritime piracy incidents and create a processing model to produce a density map by aggregating them over a global hexagonal grid.
National Geospatial-Intelligence Agency’s Maritime Safety Information portal provides a shapefile of all incidencts of maritine piracy in the form on Anti-shipping Activity Messages. Download the Arc Shape file version of the database.
Natural Earth has several global vector layers. Download the 10m Physical Vectors - Land containing Land polygons.
For convenience, you may directly download a copy of the above layers from below:
Data Source: [NGA_MSI] [NATURALEARTH]
ne_10m_land.zip and select the ne_10m_land.shp layer. Drag the layer to the canvas. Next, locate the ASAM_shp.zip file. Expand it and select the ASAM 11 OCT 18.shp layer and drag it on to the canvas.
ASAM 11 OCT 18.shp layer does not have projection information associated with it, so you will be prompted to select a CRS in the Coordinate Reference System Selector. Here, the points are in the Latitude and Longitude coordinates, so select the WGS 84 CRS and click OK.
piracy hexbin as the Name of the model and projects as the Groups. Click the Save button.
piracy_hexbin.
Input Points as the Parameter name and Point as the Geometry type. This input represents the piracy incidents point layer.
Base Layer as the Parameter name and Polygon as the Geometry type. This input represents the natural earth global land layer.
Grid Size as the Parameter name and click OK.
Reproject layer algorithm and drag it to the canvas.Note
The necessity of this reprojection step will become clear shortly. The grid generation algorithm requires us to specify the extent of the grid in the unit of the Project CRS. We can supply this reprojected layer to compute this extent.
Base Layer as the Input layer. Check the Use project CRS as the Target CRS. Click OK.
Create grid algorithm and drag it to the canvas.
Hexagon (polygon) as the Grid type. Select Extent of 'Reprojected' from algorithm 'Reproject Layer' as the Grid extent. Click the 123 button under the Horizonal spacing label and choose Model input.
Grid Size input for Using model input. Repeat the same process for Vertical Spacing. Click OK.
Extract by location algorithm and drag it to the canvas.
'Grid' from algorithm 'Generate Grid', Where the features (geometric predicate) as Intersect and By compating to the features from as Input points. Click OK.
Count points in polygon algorithm. Search and drag it to the canvas.
'Extracted (location)' from algorithm 'Extract by location' as the value for Polygons. The Points layer would be Input Points. At the bottom, name the Count output layer as Aggregated. Click OK.
Mollweide in the Filter box and select World_Mollweide EPSG:54009 as the CRS. Click OK.
piracy_hexbin model in the Processing Toolbox and double-click it.
ne_10m_land and the Input Points layer is ASAM 11 OCT 18. The Grid Size needs to be specified in the units of the selected CRS. The World_Mollweide CRS unit is meters, so we specify 100000 m (100 Kms) as the Grid Size. Click Run to start the processing pipeline. Once the process finishes, click Close.
Aggregated loaded as the result of the model. As you explore, you will notice the layer contains an attribute called NUMPOINTS containing the number of piracy incidents points contained within that grid feature. Let’s style this layer to display this information better. Right-click the Aggregated layer and select Properties.
Graduated symbology and NUMPOINTS as the Column. Click Change.. next to Symbol label.
Viridis ramp. Click the dropdown again and select Invert Color Ramp to reverse the order of color.
Natural Breaks (Jenks) as the Mode and click Classify and click OK.Note
see Basic Vector Styling for a detailed explanation of different modes.
ASAM 11 OCT 18 layer. You will see a nice visualization of piracy hotspots across the globe.
Now that you have encoded the full data pipeline in the model, it is easy to reproduce your results. A model also allows you to experiment quickly without manually repeating each intermediate step every time. If your inputs change over time, say an updated database of piracy is released after a few months, you can run your model on that input to generate a similar visualization without having to remember each step.
This work is licensed under a Creative Commons Attribution 4.0 International License