5

I am attempting to do zonal statistics for multiple images and I need to add an extra field that will have the name of each raster file in each row to the finally appended file. I have added a field before appending but when I run the model it fails to do this. I get the following error:

General error executing calculator. ERROR 999999: Error executing function. Expected end of statement Failed to execute (Calculate Field).

The expression in the calculate field is %Name%. I have followed the instructions on Iterate through multiple Raster files and compute statistics using Zonal Statistics and Iterate zonal statistics table model builder - add field and name each row by raster

The raster files are tiff files with long names e.g. MCD43B3.A2002001.h21v09.005.2007114212806.hdf.tif and I am interested in the name because it has the datestamp "A2002001". I need this included in the final appended Table so I can know for which date the zonal statistics belong.

In calculate field, under the expression I typed %Name% and choose the calculate field that was added in the file bsa_20021. This follows the advice given in the threads Iterate through multiple Raster files and compute statistics using Zonal Statistics and Iterate zonal statistics table model builder - add field and name each row by raster

For some reason, it is not clear how this is supposed to work.

See attached image

8

The issue is in the interpretation:

%Name%

Expands out to the name of the feature class so the field calculation is looking for a field that matches the name of the feature class, is unable to find one, then returns an error as no field called MCD43B3.A2002001.h21v09.005.2007114212806.hdf.tif exists in the feature class.

To use the name of the feature class as a string calculation it is necessary to quote it, this informs field calculation tool that you want to calculate a string and not a field:

"%Name%"

Expands to "MCD43B3.A2002001.h21v09.005.2007114212806.hdf.tif" which is a string and the field calculation tool will put that string into the field - provided the field is long enough to store the data.

That is a very long file name... the default string length is 50 and there's less than 50 characters there but if your file names become longer then be aware of that; shapefiles can have up to 250 characters in the string fields, databases it's over 4 billion (the entire text of a medium library, we calculated it during a power outage) so it's unlikely to overflow that!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.