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…
- 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:
- 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.
- 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.