官术网_书友最值得收藏!

  • QGIS 2 Cookbook
  • Alex Mandel Víctor Olaya Ferrero Anita Graser Alexander Bruy
  • 447字
  • 2021-07-16 11:12:37

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:
    How to do it…
  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.

主站蜘蛛池模板: 吴川市| 比如县| 庆云县| 荆州市| 克东县| 泰宁县| 翼城县| 定日县| 临沂市| 上饶市| 赤水市| 襄城县| 凉城县| 昌乐县| 德保县| 丰宁| 晋城| 右玉县| 宜春市| 河南省| 温州市| 崇信县| 隆尧县| 广平县| 祁连县| 咸丰县| 定兴县| 灵台县| 来安县| 唐海县| 咸宁市| 永春县| 泸定县| 锡林郭勒盟| 辽阳市| 阿鲁科尔沁旗| 壤塘县| 准格尔旗| 永善县| 喀喇沁旗| 蒙城县|