Table of Contents for
QGIS: Becoming a GIS Power User

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition QGIS: Becoming a GIS Power User by Alexander Bruy Published by Packt Publishing, 2017
  1. Cover
  2. Table of Contents
  3. QGIS: Becoming a GIS Power User
  4. QGIS: Becoming a GIS Power User
  5. QGIS: Becoming a GIS Power User
  6. Credits
  7. Preface
  8. What you need for this learning path
  9. Who this learning path is for
  10. Reader feedback
  11. Customer support
  12. 1. Module 1
  13. 1. Getting Started with QGIS
  14. Running QGIS for the first time
  15. Introducing the QGIS user interface
  16. Finding help and reporting issues
  17. Summary
  18. 2. Viewing Spatial Data
  19. Dealing with coordinate reference systems
  20. Loading raster files
  21. Loading data from databases
  22. Loading data from OGC web services
  23. Styling raster layers
  24. Styling vector layers
  25. Loading background maps
  26. Dealing with project files
  27. Summary
  28. 3. Data Creation and Editing
  29. Working with feature selection tools
  30. Editing vector geometries
  31. Using measuring tools
  32. Editing attributes
  33. Reprojecting and converting vector and raster data
  34. Joining tabular data
  35. Using temporary scratch layers
  36. Checking for topological errors and fixing them
  37. Adding data to spatial databases
  38. Summary
  39. 4. Spatial Analysis
  40. Combining raster and vector data
  41. Vector and raster analysis with Processing
  42. Leveraging the power of spatial databases
  43. Summary
  44. 5. Creating Great Maps
  45. Labeling
  46. Designing print maps
  47. Presenting your maps online
  48. Summary
  49. 6. Extending QGIS with Python
  50. Getting to know the Python Console
  51. Creating custom geoprocessing scripts using Python
  52. Developing your first plugin
  53. Summary
  54. 2. Module 2
  55. 1. Exploring Places – from Concept to Interface
  56. Acquiring data for geospatial applications
  57. Visualizing GIS data
  58. The basemap
  59. Summary
  60. 2. Identifying the Best Places
  61. Raster analysis
  62. Publishing the results as a web application
  63. Summary
  64. 3. Discovering Physical Relationships
  65. Spatial join for a performant operational layer interaction
  66. The CartoDB platform
  67. Leaflet and an external API: CartoDB SQL
  68. Summary
  69. 4. Finding the Best Way to Get There
  70. OpenStreetMap data for topology
  71. Database importing and topological relationships
  72. Creating the travel time isochron polygons
  73. Generating the shortest paths for all students
  74. Web applications – creating safe corridors
  75. Summary
  76. 5. Demonstrating Change
  77. TopoJSON
  78. The D3 data visualization library
  79. Summary
  80. 6. Estimating Unknown Values
  81. Interpolated model values
  82. A dynamic web application – OpenLayers AJAX with Python and SpatiaLite
  83. Summary
  84. 7. Mapping for Enterprises and Communities
  85. The cartographic rendering of geospatial data – MBTiles and UTFGrid
  86. Interacting with Mapbox services
  87. Putting it all together
  88. Going further – local MBTiles hosting with TileStream
  89. Summary
  90. 3. Module 3
  91. 1. Data Input and Output
  92. Finding geospatial data on your computer
  93. Describing data sources
  94. Importing data from text files
  95. Importing KML/KMZ files
  96. Importing DXF/DWG files
  97. Opening a NetCDF file
  98. Saving a vector layer
  99. Saving a raster layer
  100. Reprojecting a layer
  101. Batch format conversion
  102. Batch reprojection
  103. Loading vector layers into SpatiaLite
  104. Loading vector layers into PostGIS
  105. 2. Data Management
  106. Joining layer data
  107. Cleaning up the attribute table
  108. Configuring relations
  109. Joining tables in databases
  110. Creating views in SpatiaLite
  111. Creating views in PostGIS
  112. Creating spatial indexes
  113. Georeferencing rasters
  114. Georeferencing vector layers
  115. Creating raster overviews (pyramids)
  116. Building virtual rasters (catalogs)
  117. 3. Common Data Preprocessing Steps
  118. Converting points to lines to polygons and back – QGIS
  119. Converting points to lines to polygons and back – SpatiaLite
  120. Converting points to lines to polygons and back – PostGIS
  121. Cropping rasters
  122. Clipping vectors
  123. Extracting vectors
  124. Converting rasters to vectors
  125. Converting vectors to rasters
  126. Building DateTime strings
  127. Geotagging photos
  128. 4. Data Exploration
  129. Listing unique values in a column
  130. Exploring numeric value distribution in a column
  131. Exploring spatiotemporal vector data using Time Manager
  132. Creating animations using Time Manager
  133. Designing time-dependent styles
  134. Loading BaseMaps with the QuickMapServices plugin
  135. Loading BaseMaps with the OpenLayers plugin
  136. Viewing geotagged photos
  137. 5. Classic Vector Analysis
  138. Selecting optimum sites
  139. Dasymetric mapping
  140. Calculating regional statistics
  141. Estimating density heatmaps
  142. Estimating values based on samples
  143. 6. Network Analysis
  144. Creating a simple routing network
  145. Calculating the shortest paths using the Road graph plugin
  146. Routing with one-way streets in the Road graph plugin
  147. Calculating the shortest paths with the QGIS network analysis library
  148. Routing point sequences
  149. Automating multiple route computation using batch processing
  150. Matching points to the nearest line
  151. Creating a routing network for pgRouting
  152. Visualizing the pgRouting results in QGIS
  153. Using the pgRoutingLayer plugin for convenience
  154. Getting network data from the OSM
  155. 7. Raster Analysis I
  156. Using the raster calculator
  157. Preparing elevation data
  158. Calculating a slope
  159. Calculating a hillshade layer
  160. Analyzing hydrology
  161. Calculating a topographic index
  162. Automating analysis tasks using the graphical modeler
  163. 8. Raster Analysis II
  164. Calculating NDVI
  165. Handling null values
  166. Setting extents with masks
  167. Sampling a raster layer
  168. Visualizing multispectral layers
  169. Modifying and reclassifying values in raster layers
  170. Performing supervised classification of raster layers
  171. 9. QGIS and the Web
  172. Using web services
  173. Using WFS and WFS-T
  174. Searching CSW
  175. Using WMS and WMS Tiles
  176. Using WCS
  177. Using GDAL
  178. Serving web maps with the QGIS server
  179. Scale-dependent rendering
  180. Hooking up web clients
  181. Managing GeoServer from QGIS
  182. 10. Cartography Tips
  183. Using Rule Based Rendering
  184. Handling transparencies
  185. Understanding the feature and layer blending modes
  186. Saving and loading styles
  187. Configuring data-defined labels
  188. Creating custom SVG graphics
  189. Making pretty graticules in any projection
  190. Making useful graticules in printed maps
  191. Creating a map series using Atlas
  192. 11. Extending QGIS
  193. Defining custom projections
  194. Working near the dateline
  195. Working offline
  196. Using the QspatiaLite plugin
  197. Adding plugins with Python dependencies
  198. Using the Python console
  199. Writing Processing algorithms
  200. Writing QGIS plugins
  201. Using external tools
  202. 12. Up and Coming
  203. Preparing LiDAR data
  204. Opening File Geodatabases with the OpenFileGDB driver
  205. Using Geopackages
  206. The PostGIS Topology Editor plugin
  207. The Topology Checker plugin
  208. GRASS Topology tools
  209. Hunting for bugs
  210. Reporting bugs
  211. Bibliography
  212. Index

Raster analysis

Raster data, by organizing the data in uniform grids, is useful to analyze continuous phenomena or find some information at the subobject level. We will use continuous elevation and proximity data in this case, and we will look at the subapplicant object level —at the 30 meter-square cell level. You would choose a cell size depending on the resolution of the data source (for example, from sensors roughly 30 meters apart), the roughness of the analysis (regional versus local), and any hardware limitations.

First, let's make a few notes about raster data:

  • Nodata refers to the cells that are included with the raster grid because a grid can't have completely undefined cells; however, these cells should really be considered off the layer.
  • QGIS's raster renderer is more limited than in its proprietary competitors. You will want to use the Identify tool as well as custom styles (Singleband Pseudocolor) to make sense of your outputs.
  • In this example, we will rely heavily on the GDAL and SAGA libraries that have been wrapped for QGIS. These are available directly through the processing framework with no additional preparation beyond the ordinary raster ETL. For additional functionality, you will want to consider the GRASS libraries. These are wrapped and provided for QGIS but require the additional preparation of a GRASS workspace.

Now that all our data is in the raster format, we can work through how to derive information from these layers and combine this information in order to select the best sites.

Map algebra

Map algebra is a useful concept to work with multiple raster layers and analysis steps, providing arithmetic operations between cells in aligned grids. These produce an output grid with the respective value of the arithmetic solution for each set of cells. We will be using map algebra in this example for additive modeling.

Additive modeling

Now that all our data is in the raster format, we can begin to model for the purpose of site selection. We want to discover which cells are best according to a set of criteria which has either been established for the domain area (for example, the agricultural conservation site selection) by convention or selected at the time of modeling. Additive modeling refers to this process of adding up all the criteria and associated weights to find the best areas, which will have the greatest value.

In this case, we have selected some criteria that are loosely known to affect the agricultural conservation site selection, as shown in the following table:

Layer

Criteria

Rule

applicants

Is applicant

 

easements

Proximity

< 2000 m

landuse (agriculture)

Land use, proximity

< 100 m

dem

Slope

=> 2 and <= 5, average

landuse (developed)

Land use, proximity

> 500 m

roads

Proximity

> 100m

Proximity

The Proximity grid tool will generate a layer of cells with each cell having a value equal to its distance from the nearest non-nodata cell in another grid. The distance value is given in the CRS units of the other grid. It also generates direction and allocation grids with the direction and ID of the nearest nodata cell.

Creating a proximity to the easements grid

Perform the following steps:

  1. Navigate to Processing Toolbox.
  2. Search for proximity in this toolbox. Ensure that you have the Advanced Interface selected.
  3. Once you've located the Proximity grid tool under SAGA, double-click on it to run it.
  4. Select easements for the Features field.
  5. Specify an output file for Distance at c2/data/output/easements_prox.tif.
  6. Uncheck Open output file after running algorithm for the other two outputs, as shown in the following screenshot:
    Creating a proximity to the easements grid

    The resulting grid is of the distance to the closest easement cell.

  7. Repeat these steps to create proximity grids for agriculture, developed, and roads. Finally, you will see the following output:
    Creating a proximity to the easements grid

Slope

The Slope command creates a grid where the value of each cell is equal to the upgradient slope in percent terms. In other words, it is equal to how steep the terrain is at the current cell in the percentage of rise in elevation unit per horizontal distance unit. Perform the following steps:

  1. Install and activate the Raster Terrain Analysis plugin if you have not already done so.
  2. Navigate to Raster | Terrain Analysis | Slope.
  3. Select dem, the Digital Elevation Model, for the Elevation layer field.
  4. Save your output in c2/data/output. You can keep the other inputs as default.
    Slope
  5. The output will be the steepness of each cell in the percentage of of vertical elevation over horizontal distance ("rise over run").
    Slope

Combining the criteria with Map Calculator

  1. Ensure that all the criteria grids (proximity, agriculture, developed, road, and slope) appear in the Layers panel. If they don't, add them.
  2. Bring up the Raster calculator dialog.
    1. Navigate to Raster | Raster calculator
  3. Enter the map algebra expression.
    • Add the raster layers by double-clicking on them in the Raster bands selection area
    • Add the operators by typing them out or clicking on the buttons in the operators area
    • The expression entered should be as follows:
      ("slope@1" < 8) + ("applicants@1" = 1) + ("easement_prox@1"<2000) + ("roads_prox@1">100) + ("developed_prox@1" > 500) + ("agriculture@1" < 100)

      Tip

      @1 refers to the first and only band of the raster.

    Combining the criteria with Map Calculator
  4. Add a name and path for the output file and hit Enter.
  5. You may need to set a style if it seems like nothing happened. By default, the nonzero value is set to display in white (the same color as our background).
    Combining the criteria with Map Calculator

Here's a close up of the preceding map image so that you can see the variability in suitability:

Combining the criteria with Map Calculator

In the preceding screenshot, cells are scored as follows:

  • Green = 5 (high)
  • Yellow = 4 (middle)
  • Red = 3 (low)

Zonal statistics

Zonal statistics are calculated from the cells that fall within polygons. Using zonal statistics, we can get a better idea of what the raster data tells us about a particular cell group, geographic object, or polygon. In this case, zonal statistics will give us an average score for a particular applicant. Perform the following steps:

  1. Install and activate the Zonal Statistics plugin.
  2. Navigate to Raster | Zonal Statistics | Zonal statistics, as shown in the following image:
    Zonal statistics
  3. Input a raster layer for the values used to calculate a statistic and a polygon layer that are used to define the boundaries of the cells used. Here, we will use the applicants and land use to count the number of cells in each applicant cell group.
    Zonal statistics
  4. Create a rank field, editing each value manually according to the _mean field created by the zonal statistics step. This is a measure of the mean suitability per cell. We will use this field for a label to communicate the relative suitability to a general audience; so, we want a rank instead of the rough mean value.
  5. Now, label the layer.
    1. Under Layer Properties, activate the Labels tab.
    2. Choose the rank field as the field to label.
    3. Add any other formatting, such as label placement and buffer (halo) using the inner tabs within the label tab dialog, as shown in the following screenshot:
    Zonal statistics
  6. Add a style to the layer.
    1. Select the Graduated style.
    2. Select a suitable color ramp, number of classes, and classification type.
    3. Click on the Classify button, as shown in the following screenshot:
    Zonal statistics

After you've completed these steps, your map will look something similar to this:

Zonal statistics