Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »


2. Working with Vector Data in QGIS

Vector data provides a way to represent real world features within the GIS environment. A feature is anything you can see on the landscape.

QGIS can open over 60 file-based data formats (using the OGR library), including ESRI shapefile and MapInfo TAB. It can also connect to spatial database sources including PostgreSQL, SpatiaLite, Oracle, and MSSQL), to Web Feature Service (WFS) and Point Cloud data, and to Arc REST services. QGIS’s default file format is GeoPackage, a file-based database. Most QGIS functionality is available for all vector data sources, though some formats are read-only mode and need to be saved to another format for editing.

2.1. GeoPackage

GeoPackage is an OGC standard data format. It has a .gpkg file extension, and it can hold one or many layers, including non-spatial and raster data, and can also store QGIS projects.

  1. All vector data is in ...\QGIS Training\Data\vector - right-click on the Favorites icon in the Browser panel to add this location for quick access

  2. Open the project from the previous exercise

  3. Using the Data Source Manager button, add file-based vector data by clicking the Vector tab on the left and browsing to the file

  4. Add the aonb_england.gpkg GeoPackage layer

2.2. ESRI Shapefile

Shapefile is a widely-used legacy format, developed by ESRI, used on many download sites. Shapefiles comprise four or more individual files on disk - all must be available for the file to open.

  1. Use the Browser to navigate to wind_turbines_point.shp in the vector folder (it’s in D:/PhotonUser/My Files/Home Folder/QGIS Training/Data)

  2. Double-click on the file to load it into the map, then right-click > Zoom to Layer(s) to show the layer on the map

  3. Right-click on the layer in the Browser to see the other options available

2.3. MapInfo

QGIS can open both MIF and TAB files - these will appear in the browser with other file-based data. Note that MapInfo files can contain multiple geometry types, so QGIS may present a dialog with a choice of geometry types - i.e. line, polygon, point - to load.

  1. Load the aonb_wales.mif layer

2.4. Excel

QGIS will open an Excel file as vector data, and will recognise data types (for example string, integer, date). If the data includes coordinates, creating a geometry column which QGIS can use to represent the data spatially requires an extra step.

  1. Add RTC Location 2017_0.xlsx , using the Vector tab in the Data Source Manager

  2. To turn the coordinates into points, use the Search box (in the lower left corner) to find the Create points layer from table process

  3. Complete the dialogue as follows and run the process - this will create a new spatial layer on the map

2.5. Database Layers

To loading database vector layers, you first need to establish a database connection. The process is similar for all databases, but in this example we will use data in a PostgreSQL database.

  1. Create a connection to the database using Data Source Manager > PostgreSQL > New

  2. Complete the connection details as shown in the screenshot below, using the Basic tab under Authentication - note the user credentials are pgis/pgis

  3. Click Test Connection to make sure you can connect to the database - if successful, you will see a confirmation message

  4. Click OK, then Connect to open the connection

  5. Close the Data Source Manager dialog, then using the browser pane, navigate to PostGIS > QGIS 3 Training > boundaryline > county_region and click Add, then Close

2.6. Web Feature Service (WFS) Layers

Data available in OGC Web Feature Service (WFS) format can be loaded in QGIS and used in a similar way to any other vector layer, as long as you have an Internet connection is required, although the data can be saved locally once you are connected. As with database layers, first of all you need to create a connection.

  1. Create a new WFS connection using Data Source Manager > WFS > New

  2. Open Chrome in AppStream, and go to https://data.gov.uk and search for conservation areas in Carlisle, then right click on Download to copy the link, and paste to the URL field in the dialogue below  - it should be http://maps.carlisle.gov.uk/getows.ashx?mapsource=CCC/inspire&TypeName=conservation_areas&version=1.1.0&request=GetFeature&service=WFS

  3. Click OK then Connect

  4. Click on the layer you want to load, then Add and Close

  5. The layer will be added to the map

2.7. Attribute Table

Attribute tables hold the data which sits behind every layer - you can browse the attribute data for each layer by right-clicking on the layer and selecting Open Attribute Table, (or click the  icon in the toolbar). 

Manage the Layer List

Normally, layers at the top of the list in the Layers panel appear on the map in front of layers further down the list. You can change the order of layers in the list by dragging and dropping layers to a new position.

Group Layers 

Layers can be grouped to create a hierarchical layer list, or table of contents.

  1. Click the Add Group button at the top of the Layers panel 

  2. Right-click and Rename the new group

  3. Drag and drop layers into the group 

Remove Layers

To remove a layer from the list, select the layer, then Right-click > Remove. This does not delete the data, just removes it from the map. However you will lose any styling or queries you have applied to the layer.

2.8. Joining Layers

If you want to use data in your map which has no spatial references, you will need to join this to a corresponding spatial dataset. For example, you might have population data for census areas, and a polygon layer of the census areas themselves, and you want to join the two in order to show the population figures for each areas as a label.

  1. Add the non-spatial data table, and the spatial layer you are joining it to, as described earlier

  2. The new table will appear in the Layers panel, but not on the map

  3. Double-click the spatial layer to bring up the Properties dialog, and select the Joins tab

  4. Click the Add button bottom left to add a join

  5. In the Add Vector Join dialog, use the dropdowns to specify:

    1. Join layer: the layer you want to join to the current one

    2. Join field: the field in the target layer (the one you are joining to) that is going to be used for the join (this might be ID, for example, or name, or in the case below, neighbourhood)

    3. Target field: the field in the current layer (the spatial one) which is going to be used for the join - this must contain the same data as the join field

  6. Click OK and OK again, then check the attribute table of the spatial layer - it will have an expanded number of columns to include the data from the non-spatial table

Join definition

The join definition is saved in memory, and is saved in the QGIS project - it does not affect the source data. It will therefore reflect the current data each time the project is loaded. You can edit the join after it has been created - for example to exclude fields from the joined data - in the same dialog you used to create it.

2.9. Exporting Vector Data

To export a layer or part of a layer:

  1. Right-click > Export > Save Features as from the layer

  2. In the dialog, you can simply save the file as a different name - however you can also use other options:

    1. Format: save the data in a different vector format

    2. File name: browse to the location where you want the file to be saved, and give it a name

    3. Layer name: for a GeoPackage, by default this will be the same as the file name, but you can change it (GeoPackages can contain many layers)

    4. Save only selected features: save a subset of the features

    5. CRS: reproject the data on save to a different CRS

    6. Select fields to export: save a subset of fields from the attribute table

    7. Extent: save only features visible in the current extent

Exporting a joined layer

If you export a layer with a join, the exported data will include the fields in the join - this is a way of creating a permanent new dataset from a joined layer.



  • No labels