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?

1 Answer 1


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.

  • Both the shapefile and the DEM use CRS EPSG 26919. I tried your Rasterize ideas, but the result is NAN for both a white subsection and black subsection of the raster. I've looked at this video (time 8:40) for manually inspecting DEM pixel size. I found the DEM pixels to be slightly different in size than what's reported in the metadata. I tried using this slightly different pixel size too. My DEM is not a square; it's an irregular shape. Must the GDAL -te extent values match the underlying DEM exactly? If so, could this be my issue?
    – Sam
    Commented Mar 9, 2017 at 13:12
  • I'm afraid it's not clear where you are seeing the NaN values. If it if in the rasterized point file, then that is to be expected. If it is the result of the distance calculation then you'll need to supply samples. Also, you can't have an irregular raster as it is a grid of pixels with n columns and m rows. It may contain NoData (as will your rasterized point). The point about matching extents is to end up with a distance matrix that is big enough to cover your other raster (the one you want to measure distance from the point on). You run the distance calculation on the point-raster. Commented Mar 9, 2017 at 13:49
  • Sorry for the lack of clarity. I've updated my question. Hopefully that helps!
    – Sam
    Commented Mar 9, 2017 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.