06-30-2016 03:19 AM
This may be a silly question, but I am building a complex model and need help.
My model creates a shapefile of polygons (segments), and a raster image of meaningful values. What I'd like to do is populate the polygons with the MEAN statistical value of the raster image values, within a new column in the attribute table.
Manually I can go to the Raster Tab -> Thematic -> Zonal Attributes to do the said analysis, however I'd like to find out if there is an approach to do this in the Spatial Modeler (through different operators), so that I can complete this analysis as part of my complex model?
Thanks in advance!
Solved! Go to Solution.
07-05-2016 04:04 AM
Below you can find an illustration of how you can add the MEAN statistical value of the raster image values within a new column in the attribute table.
Also attaching the model.
Hope this will help.
07-07-2016 12:26 PM - edited 07-07-2016 12:27 PM
07-07-2016 10:19 PM
Hi Marina and Ian,
Marina thanks for the awesome response, I have implemented the suggested model and it has really helped! So thank you!
Ian, I am glad you added the workflow (ERDAS 2016), because I was having trouble with the background row being included into the attribute transfer, so the "Remove Background Row" is exactly what I needed. Thanks.
My 2 cents, if the zones exist in raster as an input, the process is 10x faster inputing the raster zones than shapefile zones, and then adding the zonal attribute to the raster and then converting the raster to shapefile.
Also, the zonal mean attribute's accuracy is higher when analysing zonal raster to class raster, than zonal shapefile to class raster (which is understandable since the shapefile has to be converted to a raster cell before the zonal statistic processing can take place). This is only the case if the zones are available as raster and shapefile.
Anyways thanks guys, you are flippin awesome.
06-15-2020 01:57 AM
Did you manage to change "ZonalMean" to reflect the input image name and band? I am trying rename attributes but am getting the same old ZonalMean attribute name and green check marks in the modeller.
3 weeks ago - last edited 3 weeks ago
I like the simplicity of this model. However, it's not working for me (Imagine 2016) -- it just seem to run forever, with no error messages in the session log. Ditto Ian's version. The process is taking up a lot of CPU clicks, with the laptop's fan on continuously, so it seems to be doing something. There's nothing odd about the shapefile (about 600 features) and raster (continuous). I can post them to a Google Drive for testing if that helps. The only thing I can think of is that perhaps the shapefile has geographic coordinates while the raster is in Albers -- but since the vector layer is rasterized before zonal operations, I wouldn't have thought this would be an issue. Any ideas? It's such a fundamental operation: query raster values under vector-specified features.
p.s., I just saw that the messages box says "No cell size specified. Using default size of 1 X 1 m.". Maybe that's the issue: the map area is the western US.
3 weeks ago
Update: Success! After the vector was reprojected to Albers, the vector input units were set to 30 m (the spatial resolution of the imagery from which it was vectorized), and a boundary set for the raster using the inquire box. I'm not sure where to find the set window/cell size/projection/AOI for the new spatial modeler, maybe it has be to done via the operators now.
2 weeks ago
Define Processing Area is the Operator you need for settign common processing area, etc.
2 weeks ago - last edited 2 weeks ago
Hi Ian, Thanks. I am still having issues with this. Applying the model (below, right) to the polygon shapefile to extract statistics from a binary (1-bit) thematic raster (forest/non-forest) I am getting strange values. For example, see the Rodeo-Chediski fire perimeter (below, left, selected polygon). The zonal mean model results in a value of 0.499 (about 50% forest vs non-forest) for this polygon. However, the interior is mostly forested (green) and remains so if you zoom in (this is not an artefact of interpolation in the view). Similar values are obtained for other features. I need to have confidence in these calculations, so I would be very grateful if you -- or anyone -- has any ideas on why this is happening, or what I am doing wrong. I can stage the files if necessary (I have attached the screen shot PNG since the inline image is probably unreadable). Thanks. --Mark
2 weeks ago
Other than this thread it has been a long time since we last talked. A long way from Cambridge and Nottingham!
Might be easiest to send me your data to play with. But one thing to check first - you have a Boundary set on the Vector Input as Raster operator. Are you sure that's not limiting the processing to a sub-area that might be 50-50 forest/non-forest? Or did you use the Inquire Box to try to put a limiting rectangle around the fire extent polygon?