I have a few raster datasets and I created a fishnet (polygon). I tried to add the values which the rasters have in the grid cells to the attribute Table from the polygon.
-
1Can you give us some idea of what the rasters are and how you want to assign the values to your fishnet? A polygon potentially can contain many cell values, are you after the most popular value, average value, minimum, maximum etc.. do you have https://docs.qgis.org/2.2/en/docs/user_manual/plugins/plugins_zonal_statistics.html ? – Michael Stimson Nov 21 '17 at 23:08
-
hey thx for your answer... i have a surface elevation raster and a groundwater head raster. They both have a field with float values of their hight like 311.21. I need to get this values into the attribute table of an fishnet (polygon). All datasets have the same extend and cell size of 50x50 m. – till Kadabra Nov 21 '17 at 23:38
-
and in the second case i have an polygon file with some attributes i also want to join the fishnet table. The polygon hasent the same geometry as the fishnet. – till Kadabra Nov 21 '17 at 23:40
-
1Joining, spatially, your rasters to your polygons is achieved by Zonal Statistics but you wont get all the attributes in the raster, just a statistic of them. To spatially join polygons to polygons you can use an overlay https://gis.stackexchange.com/questions/179602/in-qgis-combine-multiple-polygon-parts-of-a-single-feature but that will change the geometry of your fishnet. – Michael Stimson Nov 21 '17 at 23:50
2 Answers
With QGIS one possible workaround is as follows. First, I created a polygon fishnet from raster layer for the following image (50 % of transparency for visualization purpose):
Afterward, with the Polygon centroids Processing tool, I created a centroids layer corresponding to the fishnet; as can be observed in following image.
Next I used the v.sample Processing tool for sampling raster values corresponding to centroids for each feature of fishnet. Sampled raster values can be observed in the Attributes Table of following image for Sampled memory layer produced.
After creating an id field in the Sampled layer, I used a Spatial join to the fishnet layer, using id as join and target field. Finally, fishnet is saved with another name and unnecessary fields (different to raster values) were deleted; as it can be observed at following image:
- 551
- 5
- 16
- 29,891
- 4
- 41
- 80
-
1This is a great answer. If others are looking for something like this, I would also recommend checking out the "Point Sampling Tool" plugin. I found it very fast and straightforward to use for extracting data from multiple rasters, while v.sample was awkward. – EcologyTom Oct 03 '18 at 10:59
I could get the value from a raster using the Field Calculator, and the raster_value function. The description below takes the value from raster 'topo', band 1, at the centroid of the polygon.
Open Field Calculator
Create a new field with a suitable type (or update an existing field)
Use the expression:
raster_value('topo', 1, centroid($geometry))
- 11
- 2



