Define data type when using calculate field

1891
17
01-14-2021 07:52 AM
Labels (3)
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
17 Replies
Robert_LeClair
Esri Frequent Contributor

Oliver - what I would do is create a new field and make it a DOUBLE.  One the field exists, then you can run the Calculate Field geoprocessing tool.

0 Kudos
Oliver_Burdekin
Occasional Contributor II

Thanks Robert. I was looking at that as a workaround. Is there no way to add optional arguments through the codeblock?

0 Kudos
Robert_LeClair
Esri Frequent Contributor

You're welcome Oliver - not sure about adding optional arguments in the codeblock as I have not done that workflow.  I'll do some digging around and get back to you.

0 Kudos
Robert_LeClair
Esri Frequent Contributor

I got it to work NOT using the CodeBlock - see attached image.calcfield.JPG

Oliver_Burdekin
Occasional Contributor II

Thanks Robert,

I'm not getting the same behaviour. I'm on ArcPro 2.7 and using the tool within modelbuilder. But as you can see the "Field Type" setting is not appearing.

OliverBurdekin2_0-1610642937221.png

The yellow warning next to field name is to inform me that the field doesn't exist and will be created.

However, I just tried it with the original input (not intermediate data) and that dropdown does appear. So it would seem for intermediate data the "add field" tool would need to be run first.

0 Kudos
DanPatterson
MVP Esteemed Contributor

field type is determined by what is calculated, you don't need to specify it.  If you need a double/float and you are afraid of getting an integer, multiply the calculation by... 1.0   .... it will become double/float aka 64 bit floating point


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

Thanks Dan,

I expected the field type to be determined by what is calculated but that doesn't seem to be happening. The expression I'm using is

!Shape.area@hectares!

Here's a gif of the the tool not providing the second dropdown (as per Robert's answer) and creating a text field when a double or float would be expected.

dPatterson.gif

0 Kudos
DanPatterson
MVP Esteemed Contributor

calc.png

Pro 2.7...   Maybe try moving your model to a conventional python script tool


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

Thanks Dan,

I'm not sure how to do that. Would that be a .pyt  toolbox? Having looked at the .pyt it's not really the desired workflow as I was hoping to use ModelBuilder for non-coders.

Cheers,

Oliver

0 Kudos