Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
QGIS 2 Cookbook

You're reading from   QGIS 2 Cookbook Become a QGIS power user and master QGIS data management, visualization, and spatial analysis techniques

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781783984961
Length 390 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (3):
Arrow left icon
Anita Graser Anita Graser
Author Profile Icon Anita Graser
Anita Graser
Víctor Olaya Ferrero Víctor Olaya Ferrero
Author Profile Icon Víctor Olaya Ferrero
Víctor Olaya Ferrero
Alex Mandel Alex Mandel
Author Profile Icon Alex Mandel
Alex Mandel
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Data Input and Output FREE CHAPTER 2. Data Management 3. Common Data Preprocessing Steps 4. Data Exploration 5. Classic Vector Analysis 6. Network Analysis 7. Raster Analysis I 8. Raster Analysis II 9. QGIS and the Web 10. Cartography Tips 11. Extending QGIS 12. Up and Coming Index

Batch format conversion

The Save as dialog can be used to convert the format of a single layer. When several layers have to be converted, it is a better idea to use some automation. This recipe shows you how to easily convert an arbitrary number of layers.

Getting ready

No previous preparation is needed. Batch conversion is not performed based on open layers but performed directly on files, so there is no need to open layers in QGIS before converting them.

How to do it…

  1. Open the Processing Toolbox menu by selecting Toolbox in the Processing menu. The Processing Toolbox menu is the main element of the QGIS Processing framework, and it is used to call its algorithms:
    How to do it…
  2. In the filter box of the Processing Toolbox menu, type save to filter the list of available algorithms. Locate the Save selected features algorithm, right-click on it, and select Execute as batch process. The batch processing interface will be displayed, as shown in the following screenshot:
    How to do it…
  3. In the upper cell in the Input layer column, click on the ... button and select Select from filesystem. A file selector dialog will appear. Select the content of the batch_conversion folder in the dataset. It should have a total of three files. Click on OK on the file selection dialog. The batch processing interface should now have all these selected files, one in each row in the parameters table.
  4. In the Output layer column, click on the button in the first row. A dialog for saving the file will be opened. Select a file path in your filesystem where you want to save the output files and type converted.geojson as the output filename. Click on OK and a new dialog like the one shown in the following screenshot will appear:
    How to do it…
  5. Select Fill with parameter values in the first field and Input layer in the second one. Click on OK. All the rows in the table will now have an output value, which was created using the entered filename as a prefix, followed by the name of the input layer.
  6. To avoid layers being loaded after they are created, set the first cell in the Load into QGIS column to No. Then, double-click on the column header to automatically copy this value to all the rows below.
  7. With the table already complete, you can launch the batch conversion process by clicking on Run. The GeoJSON files will be created in the specified paths.

How it works…

The conversion is performed by an algorithm from the QGIS Processing framework. Processing algorithms can be run either as individual algorithms or, in this case, in a batch process.

Outputs of Processing algorithms can be created in all formats supported by QGIS. The format is selected using the corresponding extension in the filename and, unlike in the case of saving a single layer, does not have to be selected in a field or list. Using geojson as the extension for your output files, you tell processing that you want to generate a file in this format.

Although the algorithm saves only the selected features of the layer, if there is no selection, it will use all the layer features. This is the default behavior of all algorithms in processing. As there is no selection in the layers that you have converted, all of their features will have been used.

When converting files this way, the additional options from the Save as dialog are not available, and the default configuration values are used.

There's more…

You can also convert vector layers with another more complex algorithm from the Processing Toolbox menu, which allows you to enter the configuration parameters used by the underlying OGR library that takes care of the process. It's called Export vector. Find it in the toolbox, right-click on it, and select Execute as batch process:

There's more…

In this case, the output format is not controlled by the extension of the output filename as it happens with other processing algorithms according to what has been already explained.

You have been reading a chapter from
QGIS 2 Cookbook
Published in: Apr 2016
Publisher:
ISBN-13: 9781783984961
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image