<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Avoiding Divide-by_Zero in Field Calculator in Model Builder in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/avoiding-divide-by-zero-in-field-calculator-in/m-p/167148#M5600</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; I tried to select only those features that aren't equal to zero, but the tool 'Select Layer By Attribute' could not be integrated in the model chain. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you pass your dataset or table to Make Feature Layer or Make Table View with a where expression you should be able to connect its output to Calculate Field with just the rows you want available to calculate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alternatively, you could use a code block with Calculate Field. This would just give you nothing in the field if the divide failed for any reason:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expr: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f(!POP_2010!,!RES_PIX!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Type: PYTHON&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def f(pop,res):
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return pop / float(res)
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:43:05 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T08:43:05Z</dc:date>
    <item>
      <title>Avoiding Divide-by_Zero in Field Calculator in Model Builder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/avoiding-divide-by-zero-in-field-calculator-in/m-p/167147#M5599</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm having a problem when using the tool Calculate Field in Model Builder:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My calculation formula is [pop_per_pixel] = [POP_2010] / [RES_PIX] * [proportion].&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since some of the features have [RES_PIX]=0, the model stops and indicates an error. I tried to select only those features that aren't equal to zero, but the tool 'Select Layer By Attribute' could not be integrated in the model chain. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a VB code I can put in the Code Block window?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What would be the Python code for that?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How else would you overcome this issue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Aug 2012 17:22:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/avoiding-divide-by-zero-in-field-calculator-in/m-p/167147#M5599</guid>
      <dc:creator>EladMokadi</dc:creator>
      <dc:date>2012-08-24T17:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Avoiding Divide-by_Zero in Field Calculator in Model Builder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/avoiding-divide-by-zero-in-field-calculator-in/m-p/167148#M5600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; I tried to select only those features that aren't equal to zero, but the tool 'Select Layer By Attribute' could not be integrated in the model chain. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you pass your dataset or table to Make Feature Layer or Make Table View with a where expression you should be able to connect its output to Calculate Field with just the rows you want available to calculate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alternatively, you could use a code block with Calculate Field. This would just give you nothing in the field if the divide failed for any reason:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expr: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f(!POP_2010!,!RES_PIX!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Type: PYTHON&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def f(pop,res):
&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return pop / float(res)
&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:43:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/avoiding-divide-by-zero-in-field-calculator-in/m-p/167148#M5600</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T08:43:05Z</dc:date>
    </item>
  </channel>
</rss>

