Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
QGIS 2 Cookbook
QGIS 2 Cookbook

QGIS 2 Cookbook: Become a QGIS power user and master QGIS data management, visualization, and spatial analysis techniques

Arrow left icon
Profile Icon Olaya Ferrero Profile Icon Mandel Profile Icon Anita Graser
Arrow right icon
€22.99 €32.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Apr 2016 390 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Olaya Ferrero Profile Icon Mandel Profile Icon Anita Graser
Arrow right icon
€22.99 €32.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Apr 2016 390 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

QGIS 2 Cookbook

Chapter 2. Data Management

In this chapter, we will cover the following recipes:

  • Joining layer data
  • Cleaning up the attribute table
  • Configuring relations
  • Joining tables in databases
  • Creating views in SpatiaLite
  • Creating views in PostGIS
  • Creating spatial indexes
  • Georeferencing rasters
  • Georeferencing vector layers
  • Creating raster overviews (pyramids)
  • Building virtual rasters (catalogs)

Introduction

One of the reasons to use QGIS is its many features that enable management and analysis preparation of spatial data in a visual manner. This chapter focuses on common operations that users need to perform to get data ready for other uses, such as analysis, cartography, or input into other programs.

In this chapter, you will find recipes to manage vector as well as raster data. These recipes cover the handling of data from both file and database sources.

Joining layer data

We often get data in different formats and information spread over multiple files. Therefore, one important skill to know is how to join attribute data from different layers. Joining data is a way to combine data from multiple tables based on common values, such as IDs or categories.

This exercise shows you how to use the join functionality in Layer Properties to join geographic census tract data to tabular population data and how to save the results to a new file.

Getting ready

To follow this exercise, load the census tracts in census_wake2000.shp using Add Vector Layer (you can also drag and drop the shapefile from the file browser to QGIS) and population data in census_wake2000_pop.csv using Add Delimited Text Layer.

Tip

You can also load the .csv text file using Add Vector Layer, but this will load all data as text columns because the .csv file does not come with a .csvt file to specify data types. Instead, the Add Delimited Text Layer tool will scan the data and determine...

Cleaning up the attribute table

There are many reasons why we need to clean up attribute tables every now and then. These may be because we receive badly structured or named data from external sources, or because data processing, such as the layer joins that we performed in the previous exercise, require some post processing. This recipe shows us how to use attribute table and the Table Manager plugin to rename, delete, and reorder columns, as well as how to convert between different data types using Field Calculator.

Getting ready

If you performed the previous recipe, just save the joined layer to a new shapefile; otherwise, load census_wake2000_pop.shp. In any case, you will notice that the dataset contains a lot of duplicate information, and the column names could use some love as well. To follow this recipe, you should also install and enable the Table Manager plugin by navigating to Plugins | Manage and Install Plugins.

How to do it…

  1. Our first step to clean up this dataset is to...

Configuring relations

In the Joining layer data recipe, we discussed that joins only append additional columns to existing features (1:1 or n:1 relationships). Using joins, it is, therefore, not possible to model 1:n relationships, such as "one zip code area containing n schools". These kinds of relationships can instead be modeled using relations. This recipe introduces the concept of relations and shows how you can put them to use.

Getting ready

To follow this exercise, load zip code areas and schools from zipcodes_wake.shp and schools_wake.shp.

How to do it…

Relations are configured in Project Properties. The dialog is very similar to the join dialog:

  1. Define the two layers (Referencing/Child and Referenced/Parent), as well as the fields containing the common values/IDs. As you want to model "one zip code area contains n schools," the zip code dataset is the parent layer and the school dataset is the child layer. The connection between both datasets is established...

Joining tables in databases

If you use a database (SpatiaLite or PostGIS) to store your data, vector and nonspatial, then you also have the option of using the database and SQL to perform tables joins. The primary advantages of this method include being able to filter data before loading in the map, perform multitable joins (three or more), and have full control over the details of the join via queries.

Getting ready

You'll need at least two layers in either a SpatiaLite or PostGIS database. These two layers need at least one column in common, and the column in common should contain unique values in at least one table. In this case, our example uses the census_wake_2000 polygon layer and census_wake_2000_pop.csv.

How to do it…

  1. Open the DB Manager plugin that comes with QGIS. You can find this in the Database menu.
  2. Select your database from the tree on the left-hand side, use cookbook.db in SpatiaLite (which was created in Chapter 1, Data Input and Output).

    Tip

    If you don't see...

Creating views in SpatiaLite

In a database, view is a stored query. Every time you open it, the query is run and fresh results are generated. To use views as layers in QGIS takes a couple of steps.

Getting ready

For this recipe, you'll need a query that returns results containing a geometry. The example that we'll use is the query from the Joining tables in databases recipe (the previous recipe) where attributes were joined 1:1 between the census polygons and the population CSV. The QSpatiaLite plugin is recommended for this recipe.

How to do it…

The GUI method is described as follows:

  1. Using the QspatiaLite plugin (which is in the Database menu, if you've activated it) place the following in the query:
    SELECT *
    FROM census_wake2000 as a
    JOIN census_wake2000_pop as b
    ON a.stfid = b.stfid;
  2. From the Option dropdown, select the last choice, Create Spatial View & Load in QGIS, and set the Geometry field box value to the name of your geometry field from your spatial layer....

Introduction


One of the reasons to use QGIS is its many features that enable management and analysis preparation of spatial data in a visual manner. This chapter focuses on common operations that users need to perform to get data ready for other uses, such as analysis, cartography, or input into other programs.

In this chapter, you will find recipes to manage vector as well as raster data. These recipes cover the handling of data from both file and database sources.

Joining layer data


We often get data in different formats and information spread over multiple files. Therefore, one important skill to know is how to join attribute data from different layers. Joining data is a way to combine data from multiple tables based on common values, such as IDs or categories.

This exercise shows you how to use the join functionality in Layer Properties to join geographic census tract data to tabular population data and how to save the results to a new file.

Getting ready

To follow this exercise, load the census tracts in census_wake2000.shp using Add Vector Layer (you can also drag and drop the shapefile from the file browser to QGIS) and population data in census_wake2000_pop.csv using Add Delimited Text Layer.

Tip

You can also load the .csv text file using Add Vector Layer, but this will load all data as text columns because the .csv file does not come with a .csvt file to specify data types. Instead, the Add Delimited Text Layer tool will scan the data and determine...

Cleaning up the attribute table


There are many reasons why we need to clean up attribute tables every now and then. These may be because we receive badly structured or named data from external sources, or because data processing, such as the layer joins that we performed in the previous exercise, require some post processing. This recipe shows us how to use attribute table and the Table Manager plugin to rename, delete, and reorder columns, as well as how to convert between different data types using Field Calculator.

Getting ready

If you performed the previous recipe, just save the joined layer to a new shapefile; otherwise, load census_wake2000_pop.shp. In any case, you will notice that the dataset contains a lot of duplicate information, and the column names could use some love as well. To follow this recipe, you should also install and enable the Table Manager plugin by navigating to Plugins | Manage and Install Plugins.

How to do it…

  1. Our first step to clean up this dataset is to delete...

Configuring relations


In the Joining layer data recipe, we discussed that joins only append additional columns to existing features (1:1 or n:1 relationships). Using joins, it is, therefore, not possible to model 1:n relationships, such as "one zip code area containing n schools". These kinds of relationships can instead be modeled using relations. This recipe introduces the concept of relations and shows how you can put them to use.

Getting ready

To follow this exercise, load zip code areas and schools from zipcodes_wake.shp and schools_wake.shp.

How to do it…

Relations are configured in Project Properties. The dialog is very similar to the join dialog:

  1. Define the two layers (Referencing/Child and Referenced/Parent), as well as the fields containing the common values/IDs. As you want to model "one zip code area contains n schools," the zip code dataset is the parent layer and the school dataset is the child layer. The connection between both datasets is established based on the zip code fields...

Joining tables in databases


If you use a database (SpatiaLite or PostGIS) to store your data, vector and nonspatial, then you also have the option of using the database and SQL to perform tables joins. The primary advantages of this method include being able to filter data before loading in the map, perform multitable joins (three or more), and have full control over the details of the join via queries.

Getting ready

You'll need at least two layers in either a SpatiaLite or PostGIS database. These two layers need at least one column in common, and the column in common should contain unique values in at least one table. In this case, our example uses the census_wake_2000 polygon layer and census_wake_2000_pop.csv.

How to do it…

  1. Open the DB Manager plugin that comes with QGIS. You can find this in the Database menu.

  2. Select your database from the tree on the left-hand side, use cookbook.db in SpatiaLite (which was created in Chapter 1, Data Input and Output).

    Tip

    If you don't see this database listed...

Creating views in SpatiaLite


In a database, view is a stored query. Every time you open it, the query is run and fresh results are generated. To use views as layers in QGIS takes a couple of steps.

Getting ready

For this recipe, you'll need a query that returns results containing a geometry. The example that we'll use is the query from the Joining tables in databases recipe (the previous recipe) where attributes were joined 1:1 between the census polygons and the population CSV. The QSpatiaLite plugin is recommended for this recipe.

How to do it…

The GUI method is described as follows:

  1. Using the QspatiaLite plugin (which is in the Database menu, if you've activated it) place the following in the query:

    SELECT *
    FROM census_wake2000 as a
    JOIN census_wake2000_pop as b
    ON a.stfid = b.stfid;
  2. From the Option dropdown, select the last choice, Create Spatial View & Load in QGIS, and set the Geometry field box value to the name of your geometry field from your spatial layer. In this example, this is...

Left arrow icon Right arrow icon

Key benefits

  • Explore and create time-based visualizations and build interactive maps
  • Maximize your use of the QGIS features, plugins and toolbox automation
  • Packed with lots of sample datasets to enable a better understanding of the code

Description

QGIS is a user-friendly, cross-platform desktop geographic information system used to make maps and analyze spatial data. QGIS allows users to understand, question, interpret, and visualize spatial data in many ways that reveal relationships, patterns, and trends in the form of maps. This book is a collection of simple to advanced techniques that are needed in everyday geospatial work, and shows how to accomplish them with QGIS. You will begin by understanding the different types of data management techniques, as well as how data exploration works. You will then learn how to perform classic vector and raster analysis with QGIS, apart from creating time-based visualizations. Finally, you will learn how to create interactive and visually appealing maps with custom cartography. By the end of this book, you will have all the necessary knowledge to handle spatial data management, exploration, and visualization tasks in QGIS.

Who is this book for?

If you are an intermediate GIS user, with either previous experience in QGIS or any other GIS application, this is the book for you. The recipes can be used to learn more advanced techniques in QGIS or to replicate the functionalities equivalent to other GIS platforms. This book assumes that you already have a working QGIS system in place.

What you will learn

  • Import and export common tricky spatial data formats
  • Perform classic vector and raster analysis with QGIS
  • Utilize spatial databases and data management tools
  • Use and create geographic web services and maps
  • Explore and create time-based visualizations
  • Perform network building and routing analysis
  • Extend QGIS capabilities with popular plugins and toolbox automation
  • Make beautiful and unique maps with customized cartography

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 29, 2016
Length: 390 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984978
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 29, 2016
Length: 390 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984978
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 117.97
Mastering  QGIS
€45.99
QGIS 2 Cookbook
€41.99
Learning QGIS, Third Edition
€29.99
Total 117.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Data Input and Output Chevron down icon Chevron up icon
2. Data Management Chevron down icon Chevron up icon
3. Common Data Preprocessing Steps Chevron down icon Chevron up icon
4. Data Exploration Chevron down icon Chevron up icon
5. Classic Vector Analysis Chevron down icon Chevron up icon
6. Network Analysis Chevron down icon Chevron up icon
7. Raster Analysis I Chevron down icon Chevron up icon
8. Raster Analysis II Chevron down icon Chevron up icon
9. QGIS and the Web Chevron down icon Chevron up icon
10. Cartography Tips Chevron down icon Chevron up icon
11. Extending QGIS Chevron down icon Chevron up icon
12. Up and Coming Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Jorge Arévalo Jun 19, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was given this book to review, as I am a software developer with a GIS background. So, I spent a respectable amount of time with it.This is an amazing book about QGIS. It really covers almost anything you can do with the software. Maybe beginners can find it too hard, but recipes are clear and easy to follow. And if you're also a user of software like GDAL, GRASS or PostGIS, this book is a perfect fit for your skills. You will master QGIS really fast.Chapters about raster analysis and web related technologies (WMS family) are my favorite ones, as I have a raster and web background, regarding the GIS field. But all the chapters are really comprehensive and full of useful recipes.So, if you love QGIS, you'll also love this book, in my opinion. Great buy.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.