Vector Data in QGISVector 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. GeoPackageGeoPackage 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. Load GeoPackage 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 Open the project from the previous exercise Using the Data Source Manager button, add file-based vector data by clicking the Vector tab on the left and browsing to the file Click Add to load the aonb_england.gpkg GeoPackage layer Click Close to close the dialog and view the layer
ESRI ShapefileShapefile 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. Load ShapefileUse 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 ) Double-click on the file to load it into the Layers panel, then right-click > Zoom to Layer(s) to show the layer on the map Right-click on the layer in the Browser to see the other options available
MapInfoQGIS 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. Load MapInfoLoad the aonb_wales.mif file
ExcelQGIS will open an Excel file as vector data, and will normally recognise data types (for example string, integer, date). If the data includes coordinates, there is an extra step you need to create a geometry column which QGIS can use to represent the data spatially. Load ExcelAdd RTC Location 2017_0.xlsx , using the Vector tab in the Data Source Manager Note that the data appears as a table in the Layers panel at this point - nothing is on the map To turn the coordinates into points, use the Search box (in the lower left corner) to find the Create points layer from table process Complete the dialog as follows and run the process - this will create a new spatial layer on the map
Database LayersTo load vector layers from a database, 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. Create a connection to the training_qgis database on the appstream_data.astuntechnology.com server using Data Source Manager > PostgreSQL > New Complete the connection details as shown in the screenshot below, using the Basic tab under Authentication - note the user credentials are qgis/qgis (click Store)
Click Test Connection to make sure you can connect to the database - if successful, you will see a confirmation message Click OK, then Connect to open the connection Close the Data Source Manager dialog, then using the Browser pane, navigate to PostGIS > QGIS Training > boundaryline > county_region and double-click on the layer to add to the map
Web Feature Service (WFS) LayersData 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, although the data can be saved locally once you are connected. So first of all you need to create a connection. Load WFSCreate a new WFS connection using Data Source Manager > WFS > New 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 (you can also paste from here)
Click OK then Connect Click on the layer you want to load, then Add and Close The layer will be added to the map
Attribute TableAttribute tables hold the data which sits behind every layer. Open Attribute TablesRight-click > Open Attribute Table on one of the layers you have open, and see how the data in the attribute tables relates to the features on the map (you may need to use the Panel Switcher to find the table) Select an feature in the attribute table by clicking on the row number on the left - it will be highlighted ('selected') in the table, and will also be selected in yellow on the map When you have a feature selected, use the Zoom to Selection button in the attribute table toolbar to navigate to the feature on the map Click on a column header to sort the table using that column
Join Layer to Non-Spatial dataIf you want to use data which has no spatial references in the map, you will need to join this to a corresponding spatial dataset. In this example, we have Index of Multiple Deprivation (IMD) data for census areas (LLSOAs), and a polygon layer of the LLSOAs themselves - we will join the two in order to show the IMD figures for each areas as a label. Join LayersOpen IMD2019_Index_of_Multiple_Deprivation.xlsx selecting the IMD2019 sheet If it’s not already loaded, load the llsoa_dec_2011_england_wales_ne layer from the LLSOA_Dec_2011_England_Wales GeoPackage Open the attribute tables for both IMD2019 and llsoa_dec_2011_england_wales_ne and compare the data Notice that LSOA code (2011) in the the spreadsheet layer uses the same data as code in the spatial layer Select llsoa_dec_2011_england_wales_ne and right-click > Properties > Joins, and press the green + button to add a join Select the target spreadsheet layer and the correct columns to match the two layers, then click OK Open the attribute table of llsoa_dec_2011_england_wales_ne to ensure the data has been joined correctly If you have time and you know how, add the IMD Rank as a label to each LLSOA, and apply a Graduated style to the joined data using the Rank attribute, or a Categorised style using the Decile attribute (this will be covered in more detail in a later module) Save the project
The join you have just created is saved in memory, and is saved in the QGIS project - it does not affect the source data, but it will be updated with the current data each time the project is loaded. Exporting Vector DataAny of the vector formats you have been using can be exported into most other formats, including CSV and GeoPackage. Export DataClick on the layer to be exported, then right-click > Export > Save Features as In the dialog, options include: Format: save the data in a different vector format File name: browse to the location where you want the file to be saved, and give it a name 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) CRS: reproject the data on save to a different CRS Save only selected features: save a subset of the features based on a selection you have already made Select fields to export: save a subset of fields from the attribute table Extent: save only features visible in the current extent
Use the remaining time in the exercise to try a few of these optionoptions
Note that 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, although from this point on it won’t be updated if the source layers change.
|