HowTo: Update a table with the changes made to a related table
【相关信息】
Article ID: 41940
Software:
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows Server 2008, Windows 7, Windows 8, Server 2008 R2
【问题描述】
ArcGIS for Desktop does not have a geoprocessing tool that automatically updates a table when a change is made to a related table; however, this can be accomplished with a model or a Python script.
Article ID: 41940
Software:
ArcGIS for Desktop Advanced 10.1, 10.2
ArcGIS for Desktop Standard 10.1, 10.2
ArcGIS for Desktop Basic 10.1, 10.2
Platforms:
Windows Server 2008, Windows 7, Windows 8, Server 2008 R2
【问题描述】
ArcGIS for Desktop does not have a geoprocessing tool that automatically updates a table when a change is made to a related table; however, this can be accomplished with a model or a Python script.
1 个回复
易智瑞技术支持
赞同来自:
The following examples describe two possible workflows using ModelBuilder and Python.
Consider a scenario where a group of professionals are tasked to find closed venues and to update the appropriate records from 'Open' to 'Closed'. After bringing this data into the lab, a secondary table must be updated according to the changes made in the first table. There are thousands of records to parse through, and an automated process is needed to update the records in the secondary table.
The requirements for the following procedures are two feature classes, knowledge of either ModelBuilder or Python, and each dataset must have a key field, which in an ArcMap session is used to relate one dataset to the other. For example:
The first feature class ("fc1") has:
- a key field "KeyFC1"
- a field ("NotesFC1") where the values are 'Open'
The second feature class ("fc2") has:
- a key field "KeyFC2"
- a field ("NotesFC2") where the values start off as 'Open'
In this scenario, selected records in "fc1" are manually changed to 'Closed'. The below model and script updates all related entries in "fc2" to 'Closed' as well.
Method 1: Update a table when changes are made to a related table using ModelBuilder
1. Add the two feature classes to the model. Right-click each feature class and choose 'Model Parameter' so that this model prompts for the two input tables when run as a tool.
2. Add 'Make Feature Layer' to the model. Connect "fc2" (the feature class that is updated as a result of running the model) as the Input Feature to Make Feature Layer. The output is a layer ("fc2_Layer").
3. Add 'Add Join' to the model, which is a temporary join. Connect "fc1" (the feature class that is updated before running the model) as the Join Table. Connect "fc2_Layer" as the ‘Layer Name or Table View’. The output is another layer ("fc2_Layer (2)").
4. Add 'Calculate Field', which calculates the values of a field for a feature class, feature layer, or raster catalog. Have the following inputs:
a. Input Table: the latest layer ("fc2_Layer (2)")
b. Field Name: fc2.NotesFC2
c. Expression: change(!fc1.NotesFC1!, !fc2.NotesFC2!)
d. Expression Type: Python_9.3
e. Code Block:
Method 2: Update a table when changes are made to a related table using Python. This is a stand-alone script that can be run outside of the ArcMap process.
Starting with the 'for' loop, this code reads: For each record (row) in the first feature class, first create a new cursor to use to update the records in the second feature class (cur2). Second, search every record in the second feature class (for row2 in cur2). If the keys match (if row[1] == row2[1] , which translates to if "KeyFC1" == "KeyFC2"), then check if the first table has been updated (if row[0] == fc1_value, which translates to if "NotesFC1" == "Closed"). If the table has been updated, then update the table associated with the second table (row2[0] = fc2_value, which translates to "NotesFC2" = "Closed").
【其它相关参考】
【创建及修改时间】
Created: 12/19/2013
Last Modified: 1/9/2014
【原文链接】
http://support.esri.com/en/kno ... 41940
要回复问题请先登录或注册