QGIS:Becoming a GIS Power User
上QQ阅读APP看书,第一时间看更新

Creating new vector layers

In this exercise, we'll create a new layer from scratch. QGIS offers a wide range of functionalities to create different layers. The New menu under Layer lists the functions needed to create new Shapefile and SpatiaLite layers, but we can also create new database tables using the DB Manager plugin. The interfaces differ slightly in order to accommodate the features supported by each format.

Let's create some new Shapefiles to see how it works:

  1. New Shapefile layer, which can be accessed by going to Layer | Create Layer or by pressing Ctrl + Shift + N, opens the New Vector Layer dialog with options for different geometry types, CRS, and attributes.
    • Creating a new Shapefile is really fast because all the mandatory fields already have default values. By default, the tool will create a new point layer in WGS84 (EPSG:4326) CRS (unless specified otherwise in Settings | Options | CRS) and one integer field called id.
  2. Leaving everything at the default values, we can simply click on OK and specify a filename. This creates a new Shapefile, and the new point layer appears in the layer list.
  3. Next, we also create one line and one polygon layer. We'll add some extra fields to these layers. Besides integer fields (for whole numbers only), Shapefiles also support strings (for text), decimal numbers (also referred to as real), and dates (in ISO 8601 format, that is, 2016-12-24 for Christmas eve 2016).
  4. To add a field, we only need to insert a name, select a type and width, and click on Add to fields list.

    Tip

    For decimal numbers, we also have to define the Precision value, which determines the number of digits after the comma. A Length value of 3 with a Precision value of 1 will allow a value range from -99.9 to +99.9.

  5. The left-hand side of the following screenshot shows the New Vector Layer dialog that was used to create my example polygon layer, which I called new_polygons:
  6. All the new layers are empty so far, but we will create some features now. If we want to add features to a layer, we first have to enable editing for that particular layer. Editing can be turned on and off by any one of these ways: going to Layer | Toggle editing, using Toggle editing in the layer name context menu, or clicking on the Toggle editing button in the Digitizing toolbar.

    Tip

    You will notice that the layer's icon in the layer list changes to reflect whether editing is on or off. When we turn on editing for a layer, QGIS automatically enables the digitizing tools suitable for the layer's geometry type.

  7. Now, we can use the Add Feature tool in the editing toolbar to create new features. To place a point, we can simply click on the map. We are then prompted to fill in the attribute form, which you can see on the right-hand side of the previous screenshot, and once we click on OK, the new feature is created.
  8. As with points, we can create new lines and polygons by placing nodes on the map. To finish a line or polygon, we simply right-click on the map. Create some features in each layer and then save your changes. We can reuse these test layers in upcoming exercises.
    Note

    New features and feature edits are saved permanently only after we've clicked on the Save Layer Edits button in the Digitizing toolbar, or once we have finished editing and confirmed that we want to save the changes.