1

I have several raster files (raster_1, raster_2, [...], raster_n) and a point shapefile. The point shapefile (point.shp) was created using "generatepointspixelcentroidsinsidepolygons" so my points are located at the center of each raster pixel.

processing.runalg('qgis:generatepointspixelcentroidsinsidepolygons',".../raster_1.tif","input.shp", "point.shp")

My goal is to extract raster_n value to each point. This is possible using the point sampling tool plugin. However I want to use the python command on QGIS.

There must be a solution similar to:

processing.runald('qgis:pointsamplingtool',"raster_1","raster_2","raster_n","point.shp","output.shp"
2

In QGIS >= 3.4 you can use the "qgis:rastersampling" algorithm.

  • Hi thanks a lot, however I am using QGIS 2.18.15. I found an efficient solution using R. See response. – Marcel Campion Jan 16 at 9:10
1

I found a very efficient solution using R. Please find it attached below.

library(raster)
raster1 <- raster("/path/input1.tif")
raster2 <- raster("/path/input2.tif")
raster3 <- raster("/path/input3.tif")
rastern <- raster("/path/inputn.tif")
rasStack = stack(raster1, raster2, raster3, rastern)
pointCoordinates=read.csv("/path/point.csv")
coordinates(pointCoordinates)=~lat+lon
rasValue=extract(rasStack,pointCoordinates)
combinePointValue=cbind(pointCoordinates,rasValue)
write.table(combinePointValue,file="output.csv",append=FALSE, sep=",", row.names=FALSE,col.names=TRUE)

Hope that will help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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