Calculating values in field to round up to 1 if value is greater than 0 using ArcGIS Field Calculator?

I am prepping vector data for raster conversion and analysis. In order to prep the data I need to have a field that represents data/no data (1/0). I built a model that outputs the necessary features but I need to calculate the output field (based on Shape_Area) so that if a row value is greater than 0 (represented as a decimal number), it needs to be rounded to "1". Field type is double.

• Are you looking for math.ceil() geeksforgeeks.org/python-math-ceil-function in a python field calculation? int() performs a floor() by truncating every decimal place. To use in field calculator you will need to use the advanced dialog and start with import math so that the function loads the correct lib to use this function. – Michael Stimson Sep 19 at 4:31

Using Python in the field calculator, you could try the following expression:

1 if !myField! > 0.0 else 0

Or if you want it based on the polygon area, try:

1 if !shape.area! > 0.0 else 0

Since booleans are automatically cast to integers (1 or 0), you can do the same thing more simply as:

!myField! > 0

or

!shape.area! > 0

If there is a risk of empty (NULL) geometries when using area in a polygon feature class, then you can cater for this with:

1 if !shape! and !shape.area! > 0.0 else 0

• This assumes there are no empty geometries; often a safe assumption, but an assumption nonetheless. – Vince Sep 19 at 0:22
• !field! >0 will suffice. – FelixIP Sep 19 at 0:48
• Empty geometries manifest as None, so there would be a NoneType object does not have attribute area exception. – Vince Sep 19 at 1:03
• Looks right, though a proper polygon ought to have non-zero area. – Vince Sep 19 at 1:47
• Thank you. I ran with the above expression in my model using the field calculator. It is converting values > 0.0 to 1 BUT it is also converting values = 0 to 1 as well. Need to keep the 0 values as 0. --> Field Name = WeightValue; Expression = 1 if !Shape_Area! > 0.0 else 0 – r2dave2 Sep 19 at 17:24