Select to view content in your preferred language

Save raster statistics in a table using GIS model builder

1975
1
Jump to solution
04-10-2021 12:45 PM
RupayanSaha
New Contributor

I have a set of 50 raster and and a polygon. I am trying to build a model which will input each raster and calculate raster statistics such as mean, max, min as per the polygon zone and create output in a table. So the output table will have 50 rows (each row for each raster) and 3 columns (mean, max, min). Any guidelines are welcome. I am new to model builder and only able to iterate raster as input and calculate the statistics but unable to save it in table. Thanks.

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

First, you need to create the desired schema for the target table. To do this, run the Zonal Statistics as Table tool, using one raster and a zonal feature class. Keep Statistics Type as "ALL". From the output table delete the undesired fields, and add any desired field (e.g. RASTER Name).

You can truncate the table, if required. It will remove the row, as the row will be added again when you run the model.

Here is how my example table schema looks like.

Jayanta_Poddar_0-1618138101413.png

RASTER is a text field which will be filled with the name of corresponding Raster file.

__________________________________________________________________________________________________

My Model looks like this

Jayanta_Poddar_1-1618138227052.png

In Model Builder,

1. Used Iterate Rasters to go through all raster files within a workspace (Filtered with Raster Format).

2. Zonal Statistics as Table. Added the Zone Feature Class, and linked the above raster(s) as Input Value Raster.

3. (Optional) I have added a field for Raster Name. You may use this step, if you want to add the Raster names to their corresponding rows. Else skip the step.

Use Add field to add an additional field for the Raster Name. The Field Name and Field Type should be same as your corresponding Field Name in Target Table. In my example, the Field Name is RASTER and Field Type is TEXT.

Use Calculate Field to add the value (Raster Name) to the field.

Jayanta_Poddar_2-1618138864617.png

Field Name: RASTER

Expression Type: PYTHON 3

Expression: "%Name%"

 

4. Use Append. The previously created table would be your target dataset. And link the output table of Calculate Field, as your input datasets.

Change Field Matching Type to "Use the Field Map to reconcile schema differences"

Jayanta_Poddar_3-1618139177036.png

Validate and Run the model. 

You may truncate the target table before rerunning the model.

Here is how my target table looks like, after running the model.

Jayanta_Poddar_4-1618139390224.png



Think Location

View solution in original post

1 Reply
JayantaPoddar
MVP Esteemed Contributor

First, you need to create the desired schema for the target table. To do this, run the Zonal Statistics as Table tool, using one raster and a zonal feature class. Keep Statistics Type as "ALL". From the output table delete the undesired fields, and add any desired field (e.g. RASTER Name).

You can truncate the table, if required. It will remove the row, as the row will be added again when you run the model.

Here is how my example table schema looks like.

Jayanta_Poddar_0-1618138101413.png

RASTER is a text field which will be filled with the name of corresponding Raster file.

__________________________________________________________________________________________________

My Model looks like this

Jayanta_Poddar_1-1618138227052.png

In Model Builder,

1. Used Iterate Rasters to go through all raster files within a workspace (Filtered with Raster Format).

2. Zonal Statistics as Table. Added the Zone Feature Class, and linked the above raster(s) as Input Value Raster.

3. (Optional) I have added a field for Raster Name. You may use this step, if you want to add the Raster names to their corresponding rows. Else skip the step.

Use Add field to add an additional field for the Raster Name. The Field Name and Field Type should be same as your corresponding Field Name in Target Table. In my example, the Field Name is RASTER and Field Type is TEXT.

Use Calculate Field to add the value (Raster Name) to the field.

Jayanta_Poddar_2-1618138864617.png

Field Name: RASTER

Expression Type: PYTHON 3

Expression: "%Name%"

 

4. Use Append. The previously created table would be your target dataset. And link the output table of Calculate Field, as your input datasets.

Change Field Matching Type to "Use the Field Map to reconcile schema differences"

Jayanta_Poddar_3-1618139177036.png

Validate and Run the model. 

You may truncate the target table before rerunning the model.

Here is how my target table looks like, after running the model.

Jayanta_Poddar_4-1618139390224.png



Think Location