Book Image

QGIS 2 Cookbook

By : Alex Mandel, Víctor Olaya Ferrero, Anita Graser, Alexander Bruy
Book Image

QGIS 2 Cookbook

By: Alex Mandel, Víctor Olaya Ferrero, Anita Graser, Alexander Bruy

Overview of this book

QGIS is a user-friendly, cross-platform desktop geographic information system used to make maps and analyze spatial data. QGIS allows users to understand, question, interpret, and visualize spatial data in many ways that reveal relationships, patterns, and trends in the form of maps. This book is a collection of simple to advanced techniques that are needed in everyday geospatial work, and shows how to accomplish them with QGIS. You will begin by understanding the different types of data management techniques, as well as how data exploration works. You will then learn how to perform classic vector and raster analysis with QGIS, apart from creating time-based visualizations. Finally, you will learn how to create interactive and visually appealing maps with custom cartography. By the end of this book, you will have all the necessary knowledge to handle spatial data management, exploration, and visualization tasks in QGIS.
Table of Contents (19 chapters)
QGIS 2 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Saving a vector layer


QGIS supports multiple formats, not just to read vector layers but to also save them. This recipe shows you how to export a vector layer, converting it to a different format.

Getting ready

You will use the layer named poi_names_wake.shp in this recipe. Make sure that it is loaded in your QGIS project.

How to do it…

  1. Right-click on the name of the points layer in the QGIS table of contents and select the Save as... menu. You will see the following window:

  2. Let's suppose that you want to use this layer to create a web map. A popular format supported by libraries, such as Leaflet of OpenLayers 3, is the GeoJSON format. Select GeoJSON in the format field and enter a path and filename in the Save as field.

  3. In the Save as dialog, click on OK. The GeoJSON file will be created.

How it works…

The OGR library, which is used by QGIS to read and open files, is also used to write them. Not all of the formats that are supported for reading purposes are also supported for writing purposes.

You can export even the layers that are not originally file-based to a file, such as a layer coming from a PostGIS database or a WFS connection. Just select the layer in the table of contents and proceed as just explained.

There's more…

The Save as dialog allows additional configuration beyond what you have seen in the example in this recipe.

Fine-tuning the export operation

Depending on the format that you select to export your layer, different options are available to configure how the layer is exported.

The options are shown by clicking on the More options button. Select GeoJSON as the export format and then display the options for that particular format. The COORDINATE PRECISION option controls the number of decimal places to write in the output GeoJSON file. The default precision is too high for almost all cases, and most of the time, having three or four decimal places is more than enough. Set the precision to 4, enter a valid path and filename, and export the layer by clicking on OK. Your points layer will now be saved in a smaller GeoJSON file. You can open this with a text editor to verify that the coordinates are expressed with the selected precision or compare its size with the one created without specifying a precision value.

Opening the layer after creating it

If you want to work with the layer after it is created, check the Add saved file to map box. The output layer will be opened and added to your current QGIS project.