use raster properties value in attribut table via inline variable in model builder

3508
7
03-10-2014 02:53 AM
DorotheaHeim
New Contributor
Hello,
I have a small model that should find the maximum value of a raster and use this number to fill a field in a shapefile. For some reason the variable of the rasters max value isn't accepted in the calculation of the new field in the shapefile. I just get a general 999999 error. I've attached an image for better understanding of the problem. The field I create in the model is of type DOUBLE because I read that the tool 'get raster properties' uses this datatype as output. I also tried using the modelbuilder only tool 'collect values' to save the maximum value in and feed it then into the calculation. Obviously that didn't work, otherwise I wouldn't ask here 🙂
Can anyone please explain to me why this isn't working and how to solve the problem?

Cheers, Thea
0 Kudos
7 Replies
ThomasStanley
New Contributor III
Have you tried creating a test variable with a set value in MB?

If %Double% doesn't work, then it's not a problem with the raster table, but some other syntax. If %Double% does work, then it's a problem with how you are getting Max.
0 Kudos
curtvprice
MVP Esteemed Contributor
Collect values is for collecting a list of values when running a iterations. I don't know why I keep seeing suggestions on the forums to use it to encapsulate single values in ModelBuilder.

It would be helpful to show the ModelBuilder dialog (copy and paste the text into a post here). The messages in that dialog will show exactly how the syntax came through.

Here are three suggestions though:


  1. Use a variable name that is not a reserved word. For example: "Max Value" instead of "Max". I don't know if that will help, but it's just good practice.

  2. Connect the output of Get Raster Properties to the Calculate Field tool directly, assigning it to the 2parameter Expression.

  3. Use PYTHON_9.3, not VB for expression_type - so the tool will run in 64 bit background geoprocessing successfully. (VB is not support in 64 bit).

0 Kudos
DorotheaHeim
New Contributor

Hello,

thank you Thomas Stanley and Curtis Price, I've tried your suggestions. I'm a bit further but still can't get my

CalculateField to recognize the output of the GetRasterProperties in ModelBuilder.

I've split up the problem and made a model with just the CalculateField Tool and a model variable of type Double that is used to fill the field (see picture). So far, so good, that work's. FieldCalculator_Double.JPG

Then I try to use the Output of the GetRasterProperties Tool (Max_Value) instead of the variable %Double% in my field calculation. The model runs without error message but the field is not updated but stays empty.

FieldCalculator_GetRasterProperties.JPG

I also tried to write %Max_Value% instead of Max_Value in the expression line, but that does not make any difference to the result.

If anyone could help me with this issue I would be most grateful.

0 Kudos
curtvprice
MVP Esteemed Contributor

did you try

float(%Max_Value%)

The geoprocessing messages you get from ModelBuilder when you run the tool may be helpful - I'd look at them carefully.

One thing you can verify is that your raster does return a maximum result from the tool at all. For examples, if it's all NoData, you won't get a result.

0 Kudos
DorotheaHeim
New Contributor

Thank you very much for your suggestion. I think I'm getting closer to the core of the problem.

I checked in the geoprocessing results that I get an output from the GetRasterProperties (45,445). My ArcGIS is set up in German, therefore the comma.

Then I tried to use

float(%Max_Value%)

but got an error message stating that float can take only one argument. So I assumed that the comma in my 54,445 is the problem and it actually should be 54.445 in order to be transformed into a float variable.

I exported the whole model into a script to be able to transform the datatyp. My script runs without any error messages but still the field is not filled with my 54.445.

My script looks like this:

# -*- coding: utf-8 -*-

# ---------------------------------------------------------------------------

# GetRasterProperties.py

# Created on: 2014-11-13 14:20:41.00000

#   (generated by ArcGIS/ModelBuilder)

# Usage: GetRasterProperties <in_raster> <Table>

# Description:

# ---------------------------------------------------------------------------

# Import arcpy module

import arcpy

# Script arguments

in_raster = arcpy.GetParameterAsText(0)

Table = arcpy.GetParameterAsText(1)

# Local variables:

# Max_Value = in_raster

# TableOut = Max_Value

# Process: Raster-Eigenschaften abrufen

MaxWertResult = arcpy.GetRasterProperties_management(in_raster, "MAXIMUM", "")

# Maximum als String in Variable speichern

MaxWert = MaxWertResult.getOutput(0)

# In MaxWert Komma durch Punkt ersetzen

MaxWert2 = MaxWert.replace(",", ".")

# MaxWert2 in Float umwandeln

MaxWertFl = float(MaxWert2)

# Process: Feld berechnen

arcpy.CalculateField_management(Table, "Max2", MaxWertFl, "PYTHON_9.3", "")

0 Kudos
curtvprice
MVP Esteemed Contributor

You may want to verify the internationalization settings in Python are what they should be.

22.2. locale — Internationalization services — Python 2.7.8 documentation

0 Kudos
DorotheaHeim
New Contributor

Thank you Curtis Price, that did the trick!

First I set my ArcGIS to English, but that wasn't enough. I actually had to change the decimal sign for my whole computer to ".", now it works beautifully.

THANK YOU

0 Kudos