qgis essentials - download.astuntechnology.com · qgis can open excel files, but you can also use...

Post on 29-Oct-2019

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

QGIS Essentials

Antony ScottAstun Technologyantonyscott@astuntechnology.com

www.astuntechnology.com

About the course

● Introductions● Housekeeping● Expectations● Schedule● Course Notes● Exercises

www.astuntechnology.com

Schedule

1. Getting Started with QGIS

2. Working with Vector Data

3. Selecting and Querying Data

4. Styling

5. Web Services

6. Loading Raster Data

7. Data Capture and Editing

8. Vector Analysis

9. Print Composer

10.Databases

Module 1: Getting Started with QGIS

www.astuntechnology.com

Contents

● Introduction to QGIS

● Interface, including menus, settings and toolbars

● Managing layers

● QGIS Browser

● Projects

● Coordinate Reference Systems

● Plugins

www.astuntechnology.com

Introduction to QGIS

● The leading open source desktop GIS

● Free and open source

● Official project of OSGeo (Open Source Geospatial Foundation)

● Supports a wide range of proprietary and open spatial formats

● Visualise, manage, edit, analyse, compose printable maps

● Uses plugin functionality as core component of architecture

● Runs on (pretty much) any platform – Windows, Mac, Linux

www.astuntechnology.com

QGIS Interface

Panels

www.astuntechnology.com

Information Bar

www.astuntechnology.com

Navigation Tool Bar

Can also use mouse wheel to zoom in and out

● These tools control what happens when you use the cursor

www.astuntechnology.com

QGIS Browser

www.astuntechnology.com

Plugins

QGIS relies on plugins for its evolution – and the best become part of the product

Separate plugin

Part of core

Embedded plugin

www.astuntechnology.com

Managing Plugins

www.astuntechnology.com

Versions

● Current LTR: 2.18

● Next LTR: 3.2 (Summer 2018)

www.astuntechnology.com

QGIS Projects

● QGIS files are called projects - XML with a .qgs extension

● They contain:

– References to data

– Styles

– Print Composers (map layouts)

– Queries

● They don't contain:

– Data!

● Open a .qgs file (from the data folder) in a text editor and review

● Save often - there is no autosave (though there's a plugin...)

www.astuntechnology.com

QGIS Project File

www.astuntechnology.com

Coordinate Reference Systems (CRS)

● We need a CRS to tell our GIS how to represent spherical (or Geoid) data on a flat plane...

www.astuntechnology.com

There are lots of map projections...

https://imgs.xkcd.com/comics/map_projections.png

www.astuntechnology.com

CRS in QGIS● All CRS have an SRID (Spatial

Reference System Identifier)

● QGIS uses the EPSG (European Petroleum Survey Group) SRID

● To remember:

– EPSG: 27700 – British National Grid

– EPSG: 4326 – WGS 84 (Lat/Lon)

– EPSG: 3857 – Web Mercator

www.astuntechnology.com

Managing CRS

1. Set default CRS for new projects

2. Set default CRS for creating new layers

3. After that - QGIS will do the translation work for you

www.astuntechnology.com

Exercise 11.1: Getting Started

Objective: Familiarisation

Module 2: Working with Vector Data

www.astuntechnology.com

Contents

● Types of data – vector, raster

● Vector data formats (e.g. MapInfo,ESRI shapefile, PostgreSQL, KML)

● Excel and CSV data

● Layer properties and attributes

● Joins

● Exporting

● Measuring

www.astuntechnology.com

Vector and raster data

● Vector data has discrete features constructed from vertices

● Raster data is a digital image made up of pixels - the shapes represented don’t exist as separate objects.

www.astuntechnology.com

Geometry Types of Vector Data

Line PolygonPoint

www.astuntechnology.com

Vector formats

QGIS can read most GIS data, including over 20 vector formats:

● ESRI shapefile: default format

● Postgres/PostGIS: e.g. corporate data store

● MapInfo: only TAB editable

● AutoCAD: not editable

● CSV: with or without coords

● KML: Google Earth/Maps

Most functionality works with all formats

www.astuntechnology.com

Shapefiles

● ESRI proprietary format – currently the de facto GIS data standard

● .shp extension – with additional files

● The default format for QGIS (but changing to GeoPackage in v 3.0...)

www.astuntechnology.com

Loading a vector layer

● Click on the Add Vector Layer toolbar button

● Or type Ctrl-Shift-V.

● Or use the QGIS Browser

● Or browse to the file in Windows Explorer and drag and drop into QGIS

www.astuntechnology.com

Attribute tables

● Every vector layer has an attribute table, holding the data behind the layer

● Each row in the table corresponds to a feature in the layer

● To see the attribute table, select the layer then Right-click > Open Attribute Table (or click the toolbar button)

www.astuntechnology.com

Loading text files

● Any delimited text file (e.g. CSV) can be loaded into QGIS, whether it is spatial (vector) data or not

● QGIS can open Excel files, but you can also use CSV as an intermediate format

● When you open the a CSV file, you will see the dialogue on the next slide

● You can usually just accept the defaults, but you must specify the CRS if prompted

www.astuntechnology.com

Loading delimited text

www.astuntechnology.com

Joining data

● Joins are often needed to bring non-spatial (for example from CSV) data into a QGIS spatial layer

● This is equivalent to a database table join or view, or using VLOOKUP in Excel

● The target spatial layer and the source data layer (the join layer in QGIS) must have a data column containing the same data (Join field/target field)

www.astuntechnology.com

Creating a join

● Select the target layer – where the data needs to go

● Properties > Joins > [Add join]

● Complete the dialogue below, matching the fields in the two tables

www.astuntechnology.com

QGIS as a translation hub

● QGIS will save and open pretty much anything (using ogr2ogr)

● This includes:

– CSV

– MapInfo

– KML

– GPX

– Shapefile

– Excel

● Right-click > Save As

www.astuntechnology.com

Save options

When saving, you can:

● Save a selection: only save selected features

● Change CRS: convert to another CRS on save

● Add to map: see your saved file

● Save extent: crop the saved file to the current view

● Save symbology: include the symbology in the fileset

● Drop attributes: just save the spatial elements

www.astuntechnology.com

Measuring

Measure a line or area directly in the map window

www.astuntechnology.com

The measuring tool

● For a quick measurement

– Use the measuring tool for areas and lengths

● To add areas/ lengths/ perimeters to the attribute table for all features

– Vector > Geometry Tools > Export/Add Geometry Columns

● For a statistical summary of a single field

– Vector > Analysis Tools > Basic Statistics

www.astuntechnology.com

Exercise 11.2: Working with Vector Data

Objective: Learn loading, viewing and joining

Module 3: Selecting and Querying Data

www.astuntechnology.com

Selecting and Querying

● Toolbars

● Identify, Select, Query and Filter

● Attribute queries

● Spatial queries

www.astuntechnology.com

Query and Selection Tools

● These tools control what happens when you use the cursor

www.astuntechnology.com

Identify, Select and Filter

Action Why? What? How? Also...

Identify Show data (attribute values) for a feature

Click on feature

Can show form for editing

Select Create a subset of features (but show all)

Select manually (with mouse) or by query

Selected features are highlighted in map and attribute table

Filter Show a subset of features (and hide the rest)

Select by query

Layer > Filter Further selection can be made on subset

www.astuntechnology.com

Identify

● Get information about a feature or small group of features

Use to:

Note that:

● This does not select or filter

www.astuntechnology.com

Identify tool

The Identify tool is used to display the attributes and properties of map features

1. Select the layer of interest in the left-hand list

2. Select the tool and the cursor will turn into arrow with an ‘i’

3. Click on a map feature

Note that the 'Identify Results' panel may look different depending on your configuration

www.astuntechnology.com

Identify – Multiple features

www.astuntechnology.com

Identify – Derived data

On the third level of the identity tree you can see derived data – i.e. measurements

www.astuntechnology.com

Select

Use to:

● Tag a feature or set of features for further action

Note that:● Selections remain in place until removed

● Selected features are highlighted in the map and the attribute table

● You can run a query to make a selection, or select manually

● Selections can be made in more than one layer

www.astuntechnology.com

Selection ToolsThere are tools for selecting map features from the map in a drop-down list under Select

And tools for clearing a selection (left) and for selecting using an expression (right)

And tools for clearing a selection (left) and for selecting using an expression (right)

www.astuntechnology.com

Select by Rectangle

● Clicking on a feature to select it

● Selecting this tool and drag a box over the features - any features that intersect the box will be selected

www.astuntechnology.com

Polygon

Freehand

Select by Polygon or Freehand

www.astuntechnology.com

Additional Select tools

● Having selected a feature there are two ways to navigate to it:

– Pan to selection centres the map on the feature

– Zoom to selection sets the map extents to that of the feature.

● You can also remove all the selections

– Remove selections

www.astuntechnology.com

Filter

Use to:

● Only show a subset of features

Note that:

● Attribute table and map may be out of sync

● Map (menu) filter and Attribute Table filter are different

www.astuntechnology.com

Filter map from menu

● Right-click > Filter

● Write query

● Only features returned by query are shown on map and attribute table

www.astuntechnology.com

Filter from attribute table

● From attribute table, Advanced Filter

● Write query and apply

● Filtered rows are shown in attribute table, but all features are shown on map

www.astuntechnology.com

Spatial queries

● Spatial queries allow you to select features based on where they are and how they interact with other features, e.g.:

– Points inside a polygon

– Lines which cross other lines

● If you don't already have the Spatial Query plugin installed, enable it in the Plugins Manager

● Use this dialogue to create a spatial relationship between two spatial layers, resulting in a new selection

www.astuntechnology.com

Spatial query example

● Select all the settlements which fall inside the parish which is already selected

● Create a new selection with the result

www.astuntechnology.com

The expression builder

www.astuntechnology.com

Query tips

● Use the query builder tool to put together a query step by step

● Use IS NULL or ='' to look for blank values

● Use AND to link query clauses together

● Use single quotes around text strings like 'this'

● Use % as a wild card

● Use ILIKE to match text (case-insensitive)

● Use the help window in the query builder for more tips

www.astuntechnology.com

Exercise 11.3: Selecting and Querying

Objectives: Understand select, query, filter; learn some queries

Module 4. Styling

www.astuntechnology.com

What is styling?

+

=

www.astuntechnology.com

What are styles?

Styles are the rules which determine how data is visualised

● They can be fixed

– colour all polygons red

● Or driven by the data

– Set polygon colours according to population

● One layer = one style(but you can always copy a layer)

www.astuntechnology.com

Types of styles

● Single symbol

● Categorised

● Graduated

www.astuntechnology.com

OpenStreetMap styling

www.astuntechnology.com

Styles can have many components

Component 1

Component 2Result

www.astuntechnology.com

Style toolsTo make a style, you can combine:

● Symbols

● Colours

● Fills

www.astuntechnology.com

Style optionsYou can choose:

● Single Symbol

– Every feature is treated the same

● Categorised styles

– One setting for each unique attribute value

● Graduated styles

– Based on bandings of a numeric attribute value

● Rule-based styles

– Driven by user-defined rules

www.astuntechnology.com

Labelling – the dark art of GIS

● Use the labels tab on the properties dialogue to set a label for a layer

● Label content can be an attribute value, or the result of an expression

● Good placement is difficult, and gets more difficult if you add more layers

● If automatic labelling is not working for you – try annotations

www.astuntechnology.com

Managing Styles

● Export/Import in QML: allows sharing within QGIS

● Copy/paste: between layers

● Save to database: as a stored and shared resource

● Set as default: to be applied whenever the layer is opened

● Saved with a shapefile (like a LYR file): so the style stays with the data

● Export/Import in SLD: for use in other programmes (e.g. GeoServer, iShare)

*SLD – Styled Layer Descriptor

www.astuntechnology.com

Annotations

● Use annotations to add labels to maps which are independent of the data – but not of the map

● Symbols, text, background and frame can be styled

● Point marker is geo-located

www.astuntechnology.com

Exercise 11.4: Styling

Objective: Practice styling

Module 5: Web Services

www.astuntechnology.com

Contents

● What are web services?

● Web Map Service (WMS)

● Web Feature Service (WFS)

● Saving and sharing service connection settings

www.astuntechnology.com

Web Services

● Web Map Service (WMS) is a protocol for serving map images over the Internet. These can be generated by a map server tools such as GeoServer and MapServer. WMS can be considered as Internet-sourced raster data.

● Web Feature Service (WFS) is a protocol for requesting and providing data on geographical features over the Internet. WFS is Internet-sourced vector data. WFS features can be selected, queried and copied like any other vector layer.

● In both cases:

– A URL is needed to reference the service

– Authentication may be needed

– The service is XML-based, and platform-independent

www.astuntechnology.com

Getting WMS layers

1. Connect to end-point 2. Get catalogue(GetCapabilities)

www.astuntechnology.com

Exercise 11.5: Web Services

Objective: Load and use web services

Module 6: Loading Raster Data

www.astuntechnology.com

Raster Layers

● Introduction to raster data

● Georeference files

● Adding raster Files

● Creating a virtual raster

www.astuntechnology.com

Vector and raster data (reminder)

● Vector data has discrete features constructed from vertices

● Raster data is a digital image made up of pixels - the shapes represented don’t exist as separate objects.

www.astuntechnology.com

GeoReference files

● Some image files come with embedded spatial information so the GIS knows where to put the image on the map – e.g. ECW, GeoTIFF

● Others require associated georeference files. These have the same name as the image file, are in the same folder, and normally have extensions:

– TFW format (ESRI World file)

– TAB (MapInfo file)

● Both formats are supplied with Ordnance Survey tiled raster data files

● Other image suppliers may provide similar files

www.astuntechnology.com

Pyramids

● Pyramids speed up the display of raster data by retrieving only the data at a specified resolution that is required for the display

● A lower-resolution copy of the data displays quickly when drawing the entire dataset.

● As you zoom in, levels with finer resolutions are drawn.

www.astuntechnology.com

Virtual Rasters

● Raster images can be loaded individually – however this can be laborious if there are lots of them

● QGIS provides a means of loading all the images from a folder at once, stitching them together in a single layer

● This is a Virtual Raster

www.astuntechnology.com

Virtual Raster dialogue

www.astuntechnology.com

Exercise 11.6: Loading Rasters

Objective: Learn raster loading and managing techniques

Module 7: Data Capture and Editing

www.astuntechnology.com

Editing tasks

● Create a new layer

● Modify a layer

● Add features (points, lines, polygons)

● Move features

● Edit nodes

● Edit data

www.astuntechnology.com

Digitising toolbar

www.astuntechnology.com

Editing existing data

1.Select a layer

2.Click the edit button to enable editing

3.Add, modify or delete features and/or

4.Edit attribute values

5.Save changes

6.Click the edit button to disable editing

Notice that the editing toolbar changes according to the geometry type of the data

www.astuntechnology.com

Creating new data

1.Create a layer – normally a shapefile

2.Select the geometry type

3.Create attributes

4.Click the edit button to enable editing

5.Add features

6.Save changes

7.Click the edit button to disable editing

www.astuntechnology.com

Attribute Editing and the Field Calculator

www.astuntechnology.com

Snapping● Snapping helps to digitise based on existing vector data

● Settings > Options > Digitizing > Snapping

www.astuntechnology.com

Advanced Digitising (Edit Menu)

● Undo

● Rotate Feature(s)

● Add Ring

● Fill Ring

● Delete Part

● Offset Curve

● Split Parts

● Merge Attributes of selected features

● Redo

● Simplify Feature

● Add Part

● Delete Ring

● Reshape Features

● Split Features

● Merge Selected Features

● Rotate Point Symbol

www.astuntechnology.com

Productivity tools

● Reshape features

– change the geometry of existing shape by extending the shape

● Add Part

– add a new shape to an object in a multi-geometry

● Add ring

– add a new shape inside a polygon geometry to create a hole

www.astuntechnology.com

Reshape tool

Right click to finishLeft Click for nodes

www.astuntechnology.com

www.astuntechnology.com

www.astuntechnology.com

www.astuntechnology.com

Line Features

www.astuntechnology.com

Exercise 12.7: Data Editing

Objective: Become confident in basic editing

Module 8: Vector Analysis

www.astuntechnology.com

Analysis examples

● Buffers

● Intersect

● Difference

www.astuntechnology.com

Buffers

www.astuntechnology.com

Buffer options

www.astuntechnology.com

Intersect

www.astuntechnology.com

Intersect options

www.astuntechnology.com

Difference

www.astuntechnology.com

Difference options

www.astuntechnology.com

Exercise 12.8: Vector Analysis

Module 9: Print Composer

www.astuntechnology.com

Building a Print Composer

● Create a new print composer

● Set paper and quality

● Set snapping

● Add a map

● Set map properties (Grid, extents)

● Add map Furniture

● Create an inset map

● Print

● Save

● Create a template

www.astuntechnology.com

Print Composer layout

www.astuntechnology.com

Exercise 12.9: Print Composer

Module 10: Working with Databases

www.astuntechnology.com

Loading PostgreSQL/PostGIS data● PostgreSQL: open source database

● PostGIS: extension functions to spatially enable

● Supports spatial indexing, filtering and query

● Connect to the database, then load a table

● Holds spatial and non-spatial tables

● PgAdmin: admin UI for Postgres

www.astuntechnology.com

Connecting to Postgres

Server

Check for non-spatial tables

www.astuntechnology.com

Saving to Postgres● QGIS and Postgres/PostGIS work seamlessly together

● Use the Browser and the DB Manager to manage migration between your Postgres and file-based layers

www.astuntechnology.com

Postgres Parameters

www.astuntechnology.com

Exercise 12.10: Working with PostGIS

● Load data from Postgres

● Save data to Postgres

● Save a style to Postgres

● Use PgAdmin to view/query the data you saved

www.astuntechnology.com

Finally...● QGIS site:

– https://www.qgis.org/en/site/index.html

● Mailing lists:

– https://www.qgis.org/en/site/getinvolved/mailinglists.html

● UK QGIS User Group (Google+):

– https://plus.google.com/u/0/communities/113949150549951715823

● Anita Graser

– https://anitagraser.com/

● Alisdair Rae

– http://www.undertheraedar.com/

● Nathan Woodrow

– https://nathanw.net/

top related