Define data type when using calculate field

3663
18
01-14-2021 07:52 AM
Oliver_Burdekin
Occasional Contributor II

I'm using ArcGIS pro 2.7 and building a model that uses the "Calculate field" tool. I'd like the field to be a new field and it needs to be of the data type "double".

When inputting the parameters there is no option to select data type of the output field. The documentation says this is an optional parameter. However, where and how should this be entered into the dialog box?

Below is an example of what I have so far (calculating area in hectares). Currently this creates the output field as "text" data type.

OliverBurdekin2_0-1610639303835.png

 

Cheers,

 

Oliver

0 Kudos
18 Replies
DanPatterson
MVP Esteemed Contributor

not the pyt

What is a script tool?—ArcGIS Pro | Documentation

You can establish your parameters through a dialog... much easier for the novice


... sort of retired...
0 Kudos
Oliver_Burdekin
Occasional Contributor II

Thanks Dan. I think it might be easier to include the "add field" as a work around in the original model.

0 Kudos
DavidPike
MVP Frequent Contributor

The tool should then add a new dropdown of field type if its not in the table.  I hate to ask, but does the field name already exist in the table?  Also what is the error icon beside the field?

0 Kudos
Oliver_Burdekin
Occasional Contributor II

Thanks David, the new dropdown is not appearing. The tool is being used in Modelbuilder and connected to an intermediate datasource. I've deleted all intermediate data and the yellow warning is to inform me that the field does not exist.

On further testing the dropdown doesn't appear when using the tool on intermediate data within Modelbuilder. It does appear if I use it on the original input feature class.
The workaround for intermediate data is to use the "add field" tool first within the model and then "calculate field"

JoshuaBixby
MVP Esteemed Contributor

So this appears to be more of a Model Builder issue than a Calculate Field issue.

In terms of Model Builder and an intermediate data source, I am guessing Model Builder isn't allowing the option because it has no idea what the schema will look like when the model is run.  When you are pointing to an existing/original data set, Model Builder can lookup the schema of the data set and determine what fields do and don't exist, and hence give you the option to create a new field and set the data type.  When working with intermediate data, it is derived and the schema won't be known until runtime so Model Builder isn't allowing that parameter to be set.

Oliver_Burdekin
Occasional Contributor II

This makes a lot of sense. Thanks Joshua.

0 Kudos
DanPatterson
MVP Esteemed Contributor

If memory serves this produces the field and allows you to do a calculation at once.

Calculate Fields (multiple) (Data Management)—ArcGIS Pro | Documentation

Even though it says "multiple" that includes one.  The data type is determined from the calculation


... sort of retired...
0 Kudos
GrahamWood-HWC
New Contributor III

I've got the same issue in Model Builder in Pro 2.8.2

I've found a workaround:

  1. create the Calculate field in Pro
  2. run it once and
  3. drag it into your model from the GP history tab.
  4. reconfigure to your model.

is this a bug?? Has it been submitted?

0 Kudos
DanielGamboa
New Contributor

Same issue with Python the Field Type seems to vanish as a selection. I switch to Arcade which has helped.

For your distinct issue, I used Add Field so that I can be specific of the Field Name, Field Alias, and Type, before I ran the next Calculate Field.

DanielGamboa_1-1713297788032.png

 

 

0 Kudos