I have multiple raster files (i.e. elevation in the United States) and over 300 points in a separate point shapefile. Each point lies in only one raster file. I'd like to be able to find out the name of the raster file that each point lies in.

Ultimately I'm trying to do a batch run over all the points, but to be able to do that I need an input raster file for each point hence why I need a way to associate the name of a raster file to each point

Does anyone know an easy way to do this in QGIS?

1 Answer 1


you can use the following python script to do the job. In this example the names of each raster will be stored in the layer points with the field 'layer'. You should adjust this to your belongings:

group =QgsProject.instance().layerTreeRoot().children()
layers = [ item.layer() for item in group ] #list of all layers
vlayer = QgsProject.instance().mapLayersByName("points")[0] #get the point layer
for f in vlayer.getFeatures():
    geom = f.geometry()
    for layer in layers:
        if layer.type()==1: #check if it is a raster
            extent = layer.extent()
            if geom.intersects(extent):
                print (layer.name())
                f['layer'] = layer.name() # set layername in field 'layer'layer of point

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.