HowTo:  Calculate fields where some inputs are null values

相关信息
Article ID: 41414
Software:
ArcGIS - ArcEditor 10
ArcGIS - ArcInfo 10
ArcGIS - ArcView 10
ArcGIS for Desktop Advanced 10.1
ArcGIS for Desktop Standard 10.1
ArcGIS for Desktop Basic 10.1
Platforms:
Windows XP, Server 2003, Vista, Server 2008, Windows 7, Windows 8, Server 2012, Server 2008 R2

问题描述
These instructions provide examples of VBScript and Python syntax that show a way to calculate fields where some input values are null.


Be aware that the Python form of the script produces the expected results on 10.1, but on 10.0 does not return a value for null inputs. VBScript produces the correct results on both versions.

已邀请:

EsriSupport

赞同来自:

解决方案
The calculation in each case applies the source value (in this case, the field Dbl1 or Dbl2) to the target field unless the source is null, in which case the target field is assigned the value zero.


VBScript:
1) Copy and paste the following sample into a Notepad file and save it with a .cal extension.

2) Load the .cal file into the Field Calculator to calculate the desired target field, setting the parser to VBScript. Substitute the desired field data source for field ‘Dbl1’ in the sample.


Dim X
if IsNull ([Dbl1]) then
X = 0
else
X = [Dbl1]
end if
__esri_field_calculator_splitter__
X



Python:
1) Copy and paste this sample into a Notepad file with a .cal extension.

2) Load the .cal file into the Field Calculator to calculate the desired target field, setting the parser to Python or Python_9.3. Substitute the desired field data source for field ‘Dbl2’ in the sample.


def X (param):
retVal = 0
if param is not None:
retVal = param
return retVal
__esri_field_calculator_splitter__
X (!Dbl2!)


See the following illustrations of a table before and after each field calculation. In the table, field Dbl1Calc was calculated using the sample VBScript code. Field Dbl2Calc was calculated using the sample Python code.

Before



After





Related Information
  1. How to check for null values in the Field Calculator using PythonStarting at ArcGIS for Desktop 10.1, null values in an attribute table are returned as the string 'None' in the Field Calculator using Python. Knowing this, an if/elif statement can be used to find whether values are null or not. Here is an exampl...


Created: 7/18/2013 Last Modified: 9/18/2013

原文链接
http://support.esri.com/en/kno ... 41414

要回复问题请先登录注册