GIS Tutorials >> Quantum GIS >> Beginner Quantum GIS Tutorials >> How to sample raster datasets using points in Quantum GIS (QGIS)

GIS Programming Tutorials

GIS Theoretical Tutorials

GISTutor Newsletter



GISTutor Poll

How did you hear about us?
 

GISTutor Users Online

We have 29 guests online
How to sample raster datasets using points in Quantum GIS (QGIS)
( 4 Votes )

This beginner Quantum GIS tutorial explains how you can create a regular grid of points and sample a raster dataset to extract the individual pixel values.  This is a very basic form of raster to vector point conversion which can be useful when trying to generate contours. 

 

Quantum GIS does offer a Contour plugin, however the plugin requires a points dataset as the input to the tool.  Therefore, this tutorial is part 1 of a 2 part tutorial, which will explain how to use raster elevation data as input, and analyze the data in order to produce vector contour lines.

 

Raster Elevation Data

 

To start off, download the sample raster elevation data here.  This data is a small square clip of raster elevation data which has been saved in the GeoTiff format.  Save the file in a well known location, and extract the data.  Open QGIS and select Add Raster Layer, navigate to the location of your data and select dem_clip.tif, click Open.  Once the data is open in QGIS you should see some lighter white pixels (representing high elevation) and some darker black pixels (representing low elevation).  Note: If your dataset looks completely black, right click dem_clip and select Properties.  Then in the style section, in the bottom right hand corner change the Contrast Enhancement dropdown to ‘Stretch To MixMax’ and click Apply.

 

raster_elevation_data_in_qgis

 

To learn more about the dataset, right click on dem_clip in the Table of Contents and select Properties.  Select Metadata, then read through the included Metadata information, taking particular note of the pixel size of 30,-30.  Looking at the Layer Spatial Reference System, you can see that raster dataset is using a UTM projection which uses meters as the units.  Therefore we can gather that each pixel in the raster dataset is representative of 30 meters.  Close the Properties/Metadata window.

 

Generating Regular Points

 

Now that we have gathered the pixel size and unit information, we can continue on to the next process where we will generate a grid of regular points.  In QGIS select Vector > Research Tools > Regular Points.  Leave the Input Boundary Layer set to dem_clip.  In the Grid Spacing section set the point spacing value to 30, as that is the size of our raster pixels.  In order to make the regular points fall within the center of each pixel we will add an offset of half our pixel size, ie (30 / 2) = 15.  Set the Initial inset from corner (LH side) value to 15.  

 

qgis_regular_points_tool

 

Note: If you have different raster datasets make sure to use the pixel size and half of the pixel size for the regular points tool to ensure your grid of points lines up with the center of every pixel. Click the Browse button for Output Shapefile, navigate to the location of your raster dataset and save the file as regular_points.shp, click OK.

 

qgis_regular_points_output

Sampling Raster Dataset using Points

 

Before we can sample the raster data using this points set, we must install the Point sampling tool plugin for QGIS.  In QGIS select Plugins > Fetch Python Plugins, search for ‘samp’ select Point sampling tool and click Install/upgrade plugin.  Once it is installed close the Fetch Python Plugins window.  Then select Plugins > Analyses > Point sampling tool.  Set the Layer containing sampling points to use regular_points.  In the Layers with fields/bands to get values from click dem_clip so that it is highlighted.  For Output point vector layer click the Browse button, navigate to the location of your raster dataset and save the file as point_sampling.shp.  You can leave a checkbox to Add created layer to the TOC, click OK. 

 

qgis_point_sampling_tool

 

Once the tool is complete, right click on point_sampling in the TOC and select Open attribute table.  As you can see each row represents an individual point object, and they should all have the elevation value of the pixel underneath the point in the column called dem_clip.  Now that we have a points dataset with elevation values, this concludes the first part of this tutorial.  Continue on to part 2 to learn ‘How to generate contours using point data in Quantum GIS (QGIS)’.

 

Comments  

 
0 #3 2012-11-03 05:30
Andrew, they started doing things differently with QGIS. The third party plugins now have to be added manually. Go to Plugins, fetch plugins, repositories tab, then Add... on bottom. Add the Contributed repository: pyqgis.org/repo/contributed.

Taken from: hub.qgis.org/.../...
Quote
 
 
0 #2 2012-09-18 19:45
Thank you for the nice and easy tutorial.
Quote
 
 
0 #1 2012-09-12 21:36
I just started using qGIS. I have been pretty impressed so far. Nice looking tutorial, but for some reason, I cannot find the Point sampling tool. It does not show up in the repositories. I am using version 1.8.0-Lisboa on a Windows 7 pro machine. Thanks.
Quote
 

Add comment


Security code
Refresh