ArcGIS字段计算器帮助文档
TextID ="p"+cstr( [ID] )
Specifying a calculation expression
This dialog lets you calculate the values of a field by specifying a calculation expression. If any records are currently selected in the table, a check box in the dialog lets you choose between applying the calculation only to the selected records (the default) or to all the records. You can type the expression directly into the box or add fields, functions and operators into the box by clicking on them in the dialog.
In field calculation expressions:
- fields are enclosed in square brackets [ ].
These brackets are not shown in the Fields listing in the Field Calculator dialog, but when you double-click a field to add it into the expression, they will be added around the field name automatically in the expression.
- text strings are enclosed in double quotes: "text".
How to use Visual Basic functions in a calculation expression
You can include any Visual Basic Number, String or Date functions in the calculation expression you define. Commonly used functions are listed in the dialog for the current choice of data Type.
For example, the following calculation expression uses the INT ( ) function on a number field to return the integer portion of the number in a number field called DIST_MILES:
INT([DIST_MILES])
And the following calculation expression uses the LEFT ( ) function on a string field to return the left-most three characters of the string in a text field called CODE: LEFT ([CODE],3)
The text concatenation operator, &, can be used with text fields and string functions. For ex
ample, the following expression takes the string in a text field called Name and concatenates it with the left-most three characters of the string in a text field called CODE:
[NAME] & Left ([CODE],3)
To find the usage of the Visual Basic functions listed in this dialog, refer to the Visual Basic help in the Visual Basic editor included with ArcGIS. To access this help, go to the Tools pulldown menu and choose the Visual Basic Editor command from the
Macros pullright. In the Visual Basic Editor, go the Help menu and choose Microsoft Visual Basic Help. In the Help, click the Index tab and select the function you want to find out about.
For additional information, search for the topic called 'Making field calculations' in the Desktop Help by entering that name in the Desktop Help Search tab.
For a list of common conversion constants, search for the topic called 'About setting distance units' by entering that name in the Desktop Help Search tab and then look for the l
ink that topic that launches a table of conversion constants.
How to use Visual Basic code in a calculation expression
Check the Advanced box to enter Visual Basic For Applications (VBA) code that will be processed before the calculation expression executes. This can be used in various ways to prepare or pre-process the data ready for the calculation.
Calculating fields to be geometric measurements such as the area or length of features
The attribute tables for geodatabase feature classes have area (Shape_Area), length (Shape_Length) and perimeter (Shape_Length) fields that are maintained automatically by ArcGIS. You don't need to create or update these fields manually. However you may want to add additional fields into the attribute table for a feature class showing these measurements in different units. Or you may be working with a non-geodatabase data source such as a shapefile, SDC feature class or CAD feature class that does not contain measurements like area, length and perimeter as fields in its attribute table. To calculate a f
ield to be the area, perimeter, length, x y location, or xy centroid location of the feature that the record represents, use the Calculate Geometry dialog instead of the Field Calculator dialog to perform the calculation. The Calculate Geometry dialog, which is new in ArcGIS 9.2, makes it easy to calculate fields to be geometric measurements in the units of your choice. After calculating a field's values using the Calculate Geometry dialog, you may then use that field in the Field Calculator dialog to calculate values for a different field, such as using an area field to calculate density value or a price per square acre, etc. To launch the Calculate Geometry dialog, right-click the field you want to calculate in the table window and choose the Calculate Geometry command. Fields that you calculate using the Calculate Geometry dialog don't automatically get updated if the features are edited. So for example, if you calculate a field in a polygon shapefile's attribute table to be the area of the polygons, and you then edit the polygons or add new polygons, the area field that you added will be out of date. You can use the Calculate Geometry dialog to update the field by recalculating it. Remember that you don't have to do this in the case of the Shape_Area and Shape_Length fields in the attribute tables of feature classes stored in a
geodatabase, because those Shape fields are maintained and updated automatically.
How to use Visual Basic code to calculate fields based on area, length, perimeter, etc.
You can use Visual Basic code in the Advanced box in the Field Calculator dialog to calculate fields using geometric measurements. Although the easiest way to perform these calculations is to use the Calculate Geometry dialog described above, there may be situations where you want to use Visual Basic code to perform these calculations in the Field Calculator instead. These examples show how to do this.
1. These code examples return a value of type 'double', so use them to calculate
either an existing field of type 'double' or a new field of type 'double' you've added to the table.
2. Check Advanced. You'll see two empty text entry boxes.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论