Automatizar Flujos de Trabajo Complejos usando el Modelador de Procesos (QGIS3)

Los Flujos de Trabajo SIG típicamente involucran varios pasos - con cada paso generando una salida intermedia que es usada por el siguiente paso. Si se cambia los datos de entrada o se quiere retocar un parámetro, necesitará correr manualmente de nuevo por todo el proceso. Afortunadamente, QGIS tiene un modeladodor gráfico incorporado que puede ayudarle a definir su flujo de trabajo y ejecutarlo en una sola llamada. Puede también ejecutar esos flujos de trabajo por lote sobre un gran número de entradas.

Vista general de la tarea

Tomaremos una capa de puntos de incidntes de piratería marítima y crearemos un modelo de proceso para producir un mapa de densidad agregándolos sobre una cuadrícula global hexagonal.

Otras habilidades que aprenderá

  • Usar una proyección global de área igual y establecer el SRC del Proyecto

  • Aplicar una simbología Graduada a una capa polígono

Obtener los datos

El portal de Información de Seguridad Marítima de la National Geospatial-Intelligence Agency provee un archivo shape de todos los incidentes de priatería marítima en la forma de Mensajes de Actividad Anti-barcos. Descargue la versión archivo Arc Shape de la base de datos.

Natural Earth tiene varias capas vectoriales globales. Descargue los Vectores Físicos 10m - Tierra que contienen los polígonos Tierra (Land).

Para su comodidad, puede descargar directamente una copia de las capas mencionadas previamente de aquí abajo:

ASAM_shp.zip

ne_10m_land.zip

Fuente de Datos: [NGA_MSI] [NATURALEARTH]

Procedimiento

  1. En el panel QGIS Explorador, ubique el directorio donde guardó sus datos descargados. Expanda ne_10m_land.zip y seleccione la capa ne_10m_land.shp. Arrastre la capa a la pantalla. A continuación, localice el archivo ASAM_shp.zip. Expándala y seleccione la capa asam_data_download/ASAM_events.shp y arrástrela a la pantalla.

../../_images/1106.png
  1. La capa ASAM_events.shp no tiene información de proyección asociada, por lo que se le pedirá elegir un SRC en el Selector del Sistema de Referencia de Coordenadas. Aquí, los puntos están en coordenadas Latitud y Longitud, así que seleccione el SRC WGS 84 y clic en Aceptar.

../../_images/259.png
  1. Una vez la capa está cargada, puede ver los puntos individuales que representan incidentes de ubicaciones de piratería. Comencemos construyendo nuestro modelo de Proceso para procesar estas capas. Vaya a Procesos ‣ Modelador Gráfico....

../../_images/337.png
  1. En el diálogo Modelador de Procesos, ubique el panel Propiedades del Modelo. Ingrese piracy hexbin para el Nombre del modelo y proyectos como Grupos. Clic en el botón Guardar.

../../_images/422.png
  1. Guarde el modelo como piracy_hexbin.

../../_images/522.png
  1. Now we can start building a graphical model of our processing pipeline. The Processing modeler dialog contains a left-hand panel and a main canvas. On he left-hand panel, locate the Inputs panel listing various types of input data types. Scroll down and select the + Vector Layer input. Drag it to the canvas.
../../_images/622.png
  1. Enter Input Points as the Parameter name and Point as the Geometry type. This input represents the piracy incidents point layer.
../../_images/721.png
  1. Next, drag another + Vector Layer input to the canvas. Enter Base Layer as the Parameter name and Polygon as the Geometry type. This input represents the natural earth global land layer.
../../_images/821.png
  1. As we are generating a global hexagonal grid, we can ask the user to supply us the grid size as an input instead of hard-coding it as part of our model. This way, the user can quickly experiment with different grid sizes without changing the model at all. select a + Number input and drag it to the canvas. Enter Grid Size as the Parameter name and click OK.
../../_images/921.png
  1. Now that we have our user inputs defined, we are ready to add processing steps. All of the processing algorithms are available to you under the Algorithms tab. The first step in our pipeline will be to reproject the base layer to the Project CRS. Search for Reproject layer algorithm and drag it to the canvas.

Nota

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.

../../_images/1021.png
  1. In the Reproject layer dialog, select Base Layer as the Input layer. Check the Use project CRS as the Target CRS. Click OK.
../../_images/1124.png
  1. In the Processing Modeler canvas, you will notice a connection appear between the + Base Layer input and the Reproject layer algorithm. This connection indicates the flow of our processing pipeline. Next step is to create a hexagonal grid. Search for the Create grid algorithm and drag it to the canvas.
../../_images/1221.png
  1. In the Generate grid dialog, choose 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.
../../_images/1320.png
  1. Select Grid Size input for Using model input. Repeat the same process for Vertical Spacing. Click OK.
../../_images/1420.png
  1. At this point, we have a global hexagonal grid. The grid spans the full extent of the base layer, including land areas and places where there are no points. Let’s filter out those grid polygons where there are no input points. Search for Extract by location algorithm and drag it to the canvas.
../../_images/1519.png
  1. For Extract features from, select 'Grid' from algorithm 'Generate Grid', Where the features (geometric predicate) as Intersect and By compating to the features from as Input points. Click OK.
../../_images/1617.png
  1. Now we have only those grid polygons that contain some input points. To aggregate these points, we will use Count points in polygon algorithm. Search and drag it to the canvas.
../../_images/1718.png
  1. Select '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.
../../_images/1817.png
  1. The model is now complete. Click the Save button.
../../_images/1914.png
  1. Switch to the main QGIS window. You can find your newly created model in the Processing Toolbox under Models ‣ projects ‣ piracy_hexbin. Now it is time to run and test the model. As our goal is to aggregate the input points over hexagonal grids, it is important that the grids are generated using a equal-area projection. This will ensure that regardless of the location of the grid, it will cover exactly the same area. Our model doesn’t explicitely ask for a CRS, but uses whatever CRS is set as the Project CRS. Let’s choose a global equal area projection as the Project CRS. Go to Project ‣ Properties.
../../_images/2011.png
  1. In the Project Properties dialog, switch to the CRS tab. We will use a global Mollweide projection for this exercise which is a equal area projection. Search for Mollweide in the Filter box and select World_Mollweide EPSG:54009 as the CRS. Click OK.
../../_images/2116.png
  1. You will see the layers getting reprojected on-the-fly to the selected CRS. Locate the piracy_hexbin model in the Processing Toolbox and double-click it.
../../_images/2214.png
  1. Our Base Layer is the ne_10m_land and the Input Points layer is ASAM_events. 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.
../../_images/2312.png
  1. You will see a new layer 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.
../../_images/2410.png
  1. Switch to the Symbology tab. Select Graduated symbology and NUMPOINTS as the Column. Click Change.. next to Symbol label.
../../_images/2510.png
  1. Select Simple fill symbol and check the Transparent Stroke button under Stroke color. This is to make the hexagon edges transparent.
../../_images/267.png
  1. Click the dropdown next to Color ramp and select the Viridis ramp. Click the dropdown again and select Invert Color Ramp to reverse the order of color.
../../_images/277.png
  1. The Graduated symbology will divide the values in the selected column into distinct classes and assign a different color to each of the classes. Select Natural Breaks (Jenks) as the Mode and click Classify and click OK.

Nota

see Estilos vectoriales básicos for a detailed explanation of different modes.

../../_images/287.png
  1. Back in the main QGIS window, turn off the ASAM_events layer. You will see a nice visualization of piracy hotspots across the globe.
../../_images/296.png

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.

If you liked tutorials on this site and do check out spatialthoughts.com for more free resources.
comments powered by Disqus

This work is licensed under a Creative Commons Attribution 4.0 International License