Procesamiento por Lotes usando el Marco de Procesamiento (QGIS3)

El Marco de Procesamiento en QGIS provee un ambiente dentro de QGIS para ejecutar algoritmos nativos y de terceros para el procesamiento de datos. Contiene un agradable interfaz de procesamiento que le permite a uno ejecutar un algoritmo fácilmente sobre varias capas. Le procesamiento por lotes es una herramienta útil que puede ahorrar esfuerzo manual y ayudarle a automatizar tareas repetitivas.

Vista general de la tarea

Tomaremos varias capas capas globales vector para recortarlas a la extensión de África en un solo comando por lotes.

Otras habilidades que aprenderá

  • Cree un Filtro que eliminará las entidades no deseadas de una capa sin crear una nueva capa.

  • Fusione múltiples capas en un solo archivo Geopackage.

Obtener los datos

Natural Earth tiene varias capas globales vector. Descargue las siguientes capas

Para su comodidad, puede descargar directamente un geopackage que contiene las capas de arriba de aquí abajo:

ne_global.gpkg

Fuente de Datos: [NATURALEARTH]

Procedimiento

  1. En el Panel Navegador QGIS, localice el directorio donde guardó sus datos descargados. Expanda el zip o la entrada gpkg y seleccione la capa ne_10m_admin_0_countries. Arrastre la capa a la pantalla.

../../_images/116.png
  1. Verá la capa cargada en el panel Capas. Como nuestra tarea es recortar las capas globales al límite de África, necesitamos primero preparar una capa que contiene entidades sólo de ese continente. Miremos en la tabla de atributos para ver que columna puede ser usada para consultar las entidades que pertenecen a un continente particular. Haga clic-derecho a la capa ne_10m_admin_0_countries y seleccione Abrir Tabla de Atributos.

Nota

Consejo: Puede también usar el atajo de teclado F6 para abrir la tabla de atributos de la capa seleccionada.

../../_images/215.png
  1. In the Attribute Table window, as you scroll horizontally, you will see that the data contains an attribute called CONTINENT. We can use this attribute to filter features.
../../_images/313.png
  1. Close the attribute table and return to the main QGIS window. Right-click the ne_10m_admin_0_countries layer and select Filter.
../../_images/45.png
  1. In the Query Builder window, select the CONTINENT field and click Sample. This will populate the Values panel with the a subset of values of that attribute from features. This step is useful to get an understanding of what type of values are present in your dataset. We can see that our dataset contains contains a value called Africa among others.
../../_images/55.png
  1. Now enter the expression in the Provider specific filter expression textbox. You can click the CONTINENT label, followed by = button and Africa label. Or you can type the following expression in the textbox. Click OK after entering the expression.
"CONTINENT" = 'Africa'
../../_images/65.png
  1. You will see that the map canvas now contains only the countries from Africa. Note the filter icon next to the layer name indicating that that layer a filter applied to it. If you wanted to see and use all the features from the layer, you can click the filter icon and clear the expression. For now, we will keep the filter so we can clip other layers to Africa.
../../_images/75.png
  1. We are now ready to run the batch process to clip the layers. Locate the natural earth global layers ne_10m_railroads, ne_10m_ports and ne_10m_urban_areas in the QGIS Browser panel. Hold the Ctrl key and click each layer to select them. Once selected, drag them to the canvas.
../../_images/85.png
  1. Once the layers are loaded, you will notice that they are global layers and have features spanning all the countries. Now, it’s time to start our batch clip process to clip these layers to Africa. Open Processing ‣ Toolbox.
../../_images/95.png
  1. Browse all available algorithms and find the Clip tool from Vector overlay ‣ Clip. You may also use the Search box to easily find the algorithm as well.
../../_images/105.png
  1. Right-click the Clip algorithm and select Execute as Batch Process.
../../_images/117.png
  1. In the Batch Processing dialog, the first tab is Parameters where we define our inputs. Each row in the table represents 1 processing task. Click Add row button to add a new row. As our task involves 3 layers, add 3 rows.
../../_images/125.png
  1. Click the ... next to the first row in the Input layers column. Select Select from Open Layers.
../../_images/135.png
  1. In the Multiple selection dialog, check the 3 layers that we want to clip and click OK.
../../_images/145.png
  1. You will notice that the Input layer columns will be auto-populated with all layers you had selected. Next, we need to select the layer containing the boundary to clip our input layers. Click the ... button for the first row under Overlay layer column and select Select form Open Layers.
../../_images/155.png
  1. In the Multiple selection dialog, check ne_10m_admin_0_countries and click OK.
../../_images/165.png
  1. Since the clip layer is the same for all our inputs, a handy shortcut is to double-click the column header Overlay layer and the same layer will be auto-filled for all the rows.
../../_images/175.png
  1. Next, we need to define our outputs. Click the ... buton next to the first row in the Clipped column.
../../_images/184.png
  1. Browse the the directory where you want your output layers. Type the filename as clipped_ and click Save.
../../_images/194.png
  1. You will see a new Autofill settings dialog pop up. Select Fill with parameter values as the Autofill mode. Select Input layer as the Parameter to use. This setting will add the input file name to the output along with the specified clipped_ filename. This is important to ensure all the output files have unique names and they do not overwrite each other.
../../_images/203.png
  1. Now we are ready to start the batch procesing. Make sure to check Load layers on completion and click Run.
../../_images/216.png
  1. The clip algorithm will run for each of the inputs and create output files are we have specified. Once the batch process finishes, click Close to return to QGIS.

Nota

Tip: QGIS can now run Processing tasks in the background without blocking the user interface. So if your batch process is taking long, you can close the dialog and continue to work on other tasks in QGIS while the process keeps running in the background.

../../_images/223.png
  1. Back in the main QGIS window, you will see the layers added to QGIS canvas. As you will notice, all the global layers are properly clipped to the continent boundary that we had specified.
../../_images/232.png
  1. We have accomplished the task of clipping multiple layers in a batch. But QGIS3 has another handy feature that will help you save and deliver the result in a more efficient way. If you wanted to deliver the clipped layers to someone, you would zip the individual files outside of QGIS. A better option to to package the output layers in a single Geopackage. In the QGIS Browser, locate the clipped output layers. You may have to click the Refresh button to see the newly added files.
../../_images/242.png
  1. Hold Ctrl key and select the layers. Drag them to the canvas to load them in QGIS.
../../_images/252.png
  1. In Processing Toolbox, locate the Database ‣ Package layers tool.
../../_images/262.png
  1. In the Package layers dialog, click the ... button next to Input layers.
../../_images/272.png
  1. In the Multiple selection dialog, check the clipped_ne_10m_ports, clipped_ne_10m_railroads and clipped_ne_10m_urban_areas layers. Click OK.
../../_images/282.png
  1. Once the input layers are selected, click the ... next to Destination Geopackage and choose Save To File.
../../_images/291.png
  1. Enter the output file name as clipped_layers.
../../_images/301.png
  1. Click Run to start the packaging process.
../../_images/314.png
  1. Once the process finishes, you will see a new geopackage file in your QGIS Browser containing all the clipped output layers. This is a single file on your computer that contains all the output layers.
../../_images/322.png
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