Docs in progress for ‘QGIS testing’. Visit https://docs.qgis.org/2.18 for QGIS 2.18 docs and translations.

3.1. Lesson: Working with Vector Data

Vector data is arguably the most common kind of data you will find in the daily use of GIS. It describes geographic data in terms of points, that may be connected into lines and polygons. Every object in a vector dataset is called a feature, and is associated with data that describes that feature.

The goal for this lesson: To learn about the structure of vector data, and how to load vector datasets into a map.

3.1.1. basic Follow Along: Viewing Layer Attributes

It’s important to know that the data you will be working with does not only represent where objects are in space, but also tells you what those objects are.

From the previous exercise, you should have the roads layer loaded in your map. What you can see right now is merely the position of the roads.

To see all the data available to you, with the roads layer selected in the Layers panel, click on this button: openTable

It will show you a table with more data about the roads layer. This extra data is called attribute data. The lines that you can see on your map represent where the roads go; this is the spatial data.

These definitions are commonly used in GIS, so it’s essential to remember them!

You may now close the attribute table.

Vector data represents features in terms of points, lines and polygons on a coordinate plane. It is usually used to store discrete features, like roads and city blocks.

3.1.2. basic Follow Along: Loading Vector Data From GeoPackage

The GeoPackage is a database container that allows you to store GIS data (layers) in a single file. A single GeoPackage file can contain both vector and raster data also in different coordinate reference systems: all these features allow you to easily share data and to avoid file duplication in your computer.

Refer back to the introductory exercise in the previous section for instructions on how to add vector layers.

Load the data sets from the training_data.gpkg file into your map following the same method:

  • buildings
  • places
  • rivers
  • water

Check your results

3.1.3. basic Follow Along: Loading Vector Data From a Database

Databases allow you to store a large volume of associated data in one file. You may already be familiar with a database management system (DBMS) such as Libreoffice Base or MS Access. GIS applications can also make use of databases. GIS-specific DBMSes (such as PostGIS) have extra functions, because they need to handle spatial data.

Adding a layer from a SpatiaLite database or from a GeoPackage archive is not so different: in fact, both are spatial extension of the SQLite library.

Let’s add some layer from a SpatiaLite database.

  1. Click the icon dataSourceManager to open the Data Source Manager window (If you’re sure you can’t see it at all, check that the Data Source Manager toolbar is enabled.)

  2. Click on the addSpatiaLiteLayer SpatiaLite tab.

  3. In this tab you can see all the connections to existing databases or set up new connections.

  4. Click the New button.

  5. In the main folder of the Training Data, you should find the file landuse.sqlite. Select it and click Open.

    Notice that the drop-down above the three buttons now reads “landuse.sqlite@…”, followed by the path of the database file on your computer.

  6. Click the Connect button. You should see this in the previously empty box:

    ../../../_images/spatiallite_dialog_connected.png
  7. Click on the landuse layer to select it, then click Add

Tip

Once you have set up a connection to a database you can see this connection and load all the layers contained into it also in the QGIS Browser. We will repeat this forever: the QGIS Browser is the quickest and best way to handle your data!

Note

Remember to save the map often! The map file doesn’t contain any of the data directly, but it remembers which layers you loaded into your map.

3.1.4. Follow Along: Reordering the Layers

The layers in your Layers list are drawn on the map in a certain order. The layer at the bottom of the list is drawn first, and the layer at the top is drawn last. By changing the order that they are shown on the list, you can change the order they are drawn in.

Note

You can alter this behavior using the Control rendering order checkbox beneath the Layer Order panel. We will however not discuss this feature yet.

The order in which the layers have been loaded into the map is probably not logical at this stage. It’s possible that the road layer is completely hidden because other layers are on top of it.

For example, this layer order…

../../../_images/incorrect_layer_order.png

… would result in roads and places being hidden as they run underneath urban areas.

To resolve this problem:

  1. Click and drag on a layer in the Layers list.
  2. Reorder them to look like this:
../../../_images/correct_layer_order.png

You’ll see that the map now makes more sense visually, with roads and buildings appearing above the land use regions.

3.1.5. In Conclusion

Now you’ve added all the layers you need from several different sources.

3.1.6. What’s Next?

Using the random palette automatically assigned when loading the layers, your current map is probably not easy to read. It would be preferable to assign your own choice of colors and symbols. This is what you’ll learn to do in the next lesson.