1

I have a dozen single band raster layers in the same CRS overlapping perfectly. I would like to 'stack them one on the other' and extract values at point locations (from a CSV).

After that the values of the single rasters should be added to a new generated point shapefile (or CSV).

In QGIS I would use the Point samplint tool plug-in for that purpose but I need to develop an automated process.

A similar question was asked here Point Sampling Tool pyQGIS with no satisfying answer for my task.

I have started as follows but I can't go beyond it now; my coding skills are exhausted.

### Path to raster folder ###

os.chdir('Path_to_folder_with_Raster_Layers')
rast = os.listdir(os.getcwd()) 



##### Loop over folder for .tif files ###

for ras in rast:
    if '.tif' in ras:
        if 'aux' not in ras:
            print(ras)



###### Load Points ####

pts = "file:///Path_to_folder.csv?delimiter=,&crs=epsg:4326&xField=decimalLongitude&yField=decimalLatitude"
vlayer = QgsVectorLayer(pts,'Points','delimitedtext')

I also tried to create a VRT out of the rasters:

gdal.BuildVRT('VRT_Raster.vrt', ras)

but what I got is just a single band VRT with the sum of all raster cell values.

How can I extract the raster values of multiple rasters at point locations and write that information to a new created point shapefile (or CSV)?

Your Answer

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

Browse other questions tagged or ask your own question.