[GIS] Receiving NULL values from Point Sampling Tool in QGIS

qgisqgis-pluginsrastersampling

I am using QGIS 2.8.2. My project includes a raster layer of flow depth representing the output from a flood simulation (.DAT file). It also includes a vector layer of points representing the centroids of buildings within the inundated area. I am simply trying to query the raster pixel values (flow depth) at the building centroid locations using Point Sampling Tool, but am receiving NULL values for every entry.

I cannot attach the project files, as it is private data, but a screengrab is here:

enter image description here

  • The CRS is the same for both the raster layer and point layer (EPSG:2452. This is also set as the CRS for the project, seen bottom-right of the raster layer). The CRSs were set and checked using the "Coordinate Reference System Selector" form accessed by right-clicking the layers and selecting "Set Layer CRS".

  • The two layers definitely overlap (see screengrab, the black points show the building centroids).

  • The raster layer is correctly selected using the point selection tool form (see screen grab. There is only one raster layer and one point layer, so no possibility of error).

  • The raster .DAT file imports fine (using Layer -> Add Layer -> Add Raster Layer), and visualizes correctly (pixel values are correct, band rendering displays the pixel values correctly-see screengrab-, the properties histogram for the layer shows the correct distribution of pixel values).

  • The output layer from the Point Sampling Tool has the correct number of entries (19,814) so the layer containing the sampling points (building centroids) appears to be correctly used.

Previous queries regarding this problem have all been solved by checking that the CRS is the same for both layers. They are the same in my case, and so my question is:

If the CRS is the same for the sampling point layer and raster layer, and the layers are shown to overlap, why is the point sampling tool returning NULL values for every point?

Best Answer

In your (excellent) description of the problem, one thing worries me: your use of the "Set Layer CRS". This should almost never be used, and often causes trouble. THis option has only one (rarely needed) purpose: If you load a layer which:

  1. Is lacking a CRS definition AND
  2. You know in advance what the correct CRS is

then you can attach the correct CRS definition to the layer.

But, if both data layers were from the start in the same CRS you should NOT need to "Set Layer CRS".

Can you verify if "On the Fly" reprojection is active? If not, activate it, then check if the layers still overlap.

=== Continuation ===

The next thing I would try: do the same procedure using GRASS. Here are the steps:

  1. Start GRASS and create a new LOCATION based on the EPSG:2452 CRS
  2. Import both your flood depth raster and the building centroids into this LOCATION using the modules r.in.gdal and v.in.ogr
  3. Get the raster values at each point location. First add a column to hold the raster values: v.db.addcol map=<centroids> column="flood_depth DOUBLE PRECISION" or alternatively, if there is no database yet for the centoids v.db.addtable map=<centroids> column="flood_depth DOUBLE PRECISION"
  4. Now run v.what.rast vector=<centroids> raster=<flood_depth_raster> column=flood_depth

You should now have an attribute column in the centoids vector with flood depths at each location.

Related Question