[GIS] Calculating Distance from Vector Point to Raster Points

distancegdalgdal-rasterizeqgis

I am using QGIS 2.18.2. I would like to calculate the Euclidean distance from the pixels in a raster to a single Shapefile GPS point. My raster is a Geotiff DEM with a pixel size of 3.856 meters by 3.856 meters. My Shapefile point contains just spatial coordinates and no other attribute information.

I am aware that this type of problem is not new. I've reviewed a number of posts on this topic, and one would think that this would be a no-brainer for me, but unfortunately, I'm still unable to work out the problem(s) in my workflow.

This post summarizes the workflow that I am attempting to do: Calculating distance to points in QGIS. My understanding is that I need to:

  1. Add a new field to the attributes table of the Shapefile point (I call this new field "Value" and set it to 1), then go Raster–>Conversion–>Rasterize to convert the Shapefile point to a raster.
  2. Using the result of step 1 as the input, go Raster–>Analysis–>Proximity to generate a raster of distances from the point.

I get stuck on step 1. I have tried a multitude of GDAL command sequences for Rasterize (with reference to http://www.gdal.org/gdal_rasterize.html), but output from this program either includes NAN or is not generated at all.

Here is my DEM and my GPS point at the start:
enter image description here

My (latest) GDAL command line code for Rasterize is as follows:

gdal_rasterize -burn 1 -tr 3.856 3.856 -te 317595 4903986 328357 4911219 -l point E:/point.shp E:/point.tif

After running this Rasterize command , which reportedly finishes without error, I end up with this:
enter image description here

The result is called RasterTx in the Layers Panel on the left. Note that the lower threshold is NaN (black) and the upper threshold is 0 (white). This result doesn't make sense to me, because I would expect to have NaN for all pixels in the square except for the one pixel in which I have my point, which should be assigned a value of 1, per the "burn" command I gave in the GDAL code above. Furthermore, when I proceed to step 2 and attempt to run the Proximity program, the result yields only NaN, so my suspicion is that I'm still missing something wit the Rasterize step.

Where might I be going astray?

Best Answer

You say you have only one point. So the extent of your raster is going to be rather small. You need to do two things:

  1. Ensure your shapefile is in the same SRS as the raster you are going to measure against. Reprojecting on the fly can give uncertain results.
  2. Set the extent of the rasterize operation to the same as the raster you want to measure against using the the -te option (you can get this from checking the metadata in your raster layer or using gdal_info).

Note you don't really need the value field as you can use -burn to specify a value for all features. You should end up with a raster that is mostly NoData, covers the raster you want to measure against exactly and has a single cell of value 1 (representing your GPS point). When you run proximity analysis make sure you check the values option and set it to 1. You may need to explicitly tell Proximity Analysis what your NoData value is if this is still giving you trouble.

Related Question