Attributes describe the features of elements and store them in tables. When creating a new attribute table or adding fields to an existing Attribute Table, you must specify the data type and field attribute, such as precision or length ). Data Type Selection and related settings affect storage and display, and are of great significance to the accuracy and efficiency of the background database.
In ArcGIS, you can store attribute values of elements as one of the seven data types, namely, short integer, long integer, and float) double, text, date, and blob ). The Attribute Table also contains predefined fields, saving the geometric properties (SHAPE) and element ID (FID) of the data ). Float and double-precision data are real values, which are usually used for measurement or calculation of continuous data. The values of short and long integer data are usually used to count or specify a coded value for a category ). Text data can also store encoded values or text that describes feature features, such as names. Data storage in terms of factor time is date type, such as the final detection time of the valve. Blob can be integrated with other media, such as videos, images, or sounds. The following table summarizes the data types.
Data Type
Description
Float)
1 Symbol bit, 7 exponent bits, and 24 decimal places
Double)
1 Symbol bit, 7 exponent bits, and 56 decimal places
Short integer)
1 Symbol bit and 15 binary digits, about-32000 ~ 32000
Long Integer)
1 Symbol bit and 31 binary digits, about-2000000000 ~ 2000000000
Text)
The numeric characters are stored as bytes.
Date)
Date value is stored in Standard Time Format
Blob
Complex objects, such as images and videos
Add a new field to the table using ArcMAP
Before editing the shapefile attribute table, you can check the data types and settings of existing fields.
1. Start ArcMAP, load a shapefile to be modified, right-click the shapefile in the directory table (TOC), and select Properties from the Environment menu.
2. In the Layer Properties dialog box, click the fields tag. Each field in the Attribute Table is listed here, and the data type and features are displayed. Click OK to close the Layer Properties dialog box.
3. To add a field, click shapefile in the directory table and select Open attribute table from the Environment menu.
4. Click the Options button and select Add field.
5. In the add field dialog box, name the new field and select the data type. Set field properties in field properties.
6. Click OK to close the dialog box.
Precision is an important setting. The precision value reflects the details of data storage, not necessarily its precision. Determine the actual precision value because higher precision requires more disk space. Scale refers to the number of digits on the right of the decimal point.
Create a new shapefile in arccatalog
You can add fields in the table view of arccatalog (same method as above). Here we will discuss how to create a new shapefile. When creating a new shapefile, the FID and shape fields can be automatically generated, but the data types of other fields you add must be specified by yourself.
1. Start arccatalog and select a folder (location) to store the new shapefile ).
2. Select File> New> shapefile from the main menu. In the create new shapefile dialog box, name the shapefile, select the element type, and set the coordinate system. To store m and Z values, select the check boxes. Click OK.
3. Right-click the newly created shapefile and select Properties from the Environment menu.
4. In the shapefile Properties dialog box, click the fields tag.
5. To create a new field, click on the first valid blank line. Enter the attribute name under field name. Click data type and select the appropriate data type from the drop-down list box.
6. Once the data type is selected, you can set the field features. After setting the field properties, click Apply or OK.
You can add, edit, or delete fields in the shapefile Attribute Table in arccatalog. The value of a new field is calculated by other fields in the table, or the value of the selected element is stored.
Add a field in the code
We can use ArcMap and arccatalog to add fields. Of course, we can also use code to do this. The following code can easily add a field.
Public sub addfield ()
Dim pmxdoc as imxdocument
Set pmxdoc = thisdocument
Dim pfeaturelayer as ifeaturelayer
Set pfeaturelayer = pmxdoc. selectedlayer
Dim pmyfield as ifieldedit
Set pmyfield = new field
With pmyfield
. Name = "myfield"
. Type = esrifieldtypestring
. Length = 16
End
Dim ptable as itable
Set ptable = pfeaturelayer
Ptable. addfield pmyfield
End sub
For convenience, we use selectedlayer to obtain a element layer (shapefile of course ). Then define a new field, including the name, type, and length. These are the most basic settings. After defining a field, we need to add it to the table. Featureclass is also a type of table, but it is a special table (including space information), which can be easily seen in the OMD diagram. Therefore, we use the itable interface when adding fields. Note that the ifieldsedit interface is not used here. Why? Because we do not want to create a new table here, we just need to add a new field to an existing table.
Note: ArcObjects (hereinafter referred to as AO) is the cornerstone of ArcGIS Desktop. From the examples above, we can also see that many operations In ArcMap or arccatalog can be completed using the corresponding code, because ArcMap and arccatalog use similar code to complete these tasks. Therefore, when learning about the development of AO, the first thing we need to learn is the basic operations of desktop. You can have an intuitive understanding only when you are familiar with the basic operations, understand the hierarchical relationship between objects and know what Ao can do, so that you can be targeted when writing your own code.