Analyzing Raster Data From Vector Layer Buffer

I have satellite images of night-time lights all over earth. I also have a vector shapefile of country boundaries including the largest cities on earth. I want to use buffers to capture a certain amount of light pollution emanating from cities that is viewable from the raster image.

How do I use buffers to analyze pixels (or some aspect of the raster data) within the buffer area? I assume I will want to assign some value to a certain pixel and then total those values by using the buffer to analyze all data within the buffer.

I have attached a snip of what I am working with. I am very new to GIS still, so bear with me.

I am using QGIS 2.0.

• What GIS software and version are you using? You can use the edit button below your Question to revise it with this detail.
– PolyGeo
Commented Jan 22, 2014 at 19:28

I would recommend using the Zonal Statistics Plug-in for QGIS.

With the Zonal Statistics Plugin you can analyze the results of a thematic classification. It allows to calculate several values of the pixels of a raster layer with the help of a polygonal vector layer (see figure_zonal_statistics). You can calculate the sum, the mean value and the total count of the pixels that are within a polygon. The plugin generates output columns in the vector layer with a user-defined prefix.

Or, if you prefer R, you can use Zonal Statistics from the raster package

``````r <- raster(ncols=10, nrows=10)
r[] <- runif(ncell(r)) * 1:ncell(r)
z <- r
z[] <- rep(1:5, each=20)
# for big files, use a character value rather than a function
zonal(r, z, 'sum')

# for smaller files you can also provide a function

## Not run:
zonal(r, z, mean)
zonal(r, z, min)
## End(Not run)

# multiple layers
zonal(stack(r, r*10), z, 'sum')
[1]: http://www.qgis.org/en/docs/user_manual/plugins/plugins_zonal_statistics.html
``````
• Thanks. Is there a way to ensure that zonal statistics does not count one pixel 2, 3, or 4 times? I need to make sure that the raster data, where buffers overlap, is counted only once. Perhaps I should reduce the size of the buffer?
– ian
Commented Jan 22, 2014 at 23:46
• @Aaron how do it in python , jupyter notebook Commented May 19, 2022 at 7:45