span8
span4
span8
span4
A scenario that one may encounter when working with file geodatabase is that one wishes to write data to an existing feature class while altering its schema without having to drop the existing feature class table.This would allow a user to maintain the field names of their existing feature class while adding new fields either manually or from that of a source dataset.While we do recommend that any schema alterations to existing feature classes be handled by your ArcGIS client, the following example will show how to use both FME and ArcGIS Python modules in FME to add fields to an existing geodatabase feature class.
The Python interpreter MUST be设置解释installed by ArcGIS.See:无模块命名ArcPy中:导入ESRI公司ArcPy中为使用FME
ArcGIS installed on the same machine as FME
In the above image, we see a visualization of the source Esri shapefile containing the new field "Truck" of which we want to add to an existing feature class.
In the above image, we see a visualization of the destination feature class.As one can see, the data is essentially identical except for that the shapefile has an additional attribute field.
1。阅读源数据和Expose属性
Garbage Schedule geometry is read from the shapefile source file with the Esri shapefile reader.This shapefile contains an attribute field that does not appear on the corresponding feature class to which we will write the data.Once the shapefile reader has been added to the workspace, open the reader parameters dialogue and click on the format parameters tab.Expose the following attributes (i.e.check the box):
fme_feature_type
fme_geometry
SHAPE_GEOMETRY
fme_type
* Note - The attributes required to be exposed will vary from dataset to dataset, format to format.
2。重命名/删除属性
The AttributeManager will be used used to rename and remove various attributes from the source shapefile dataset.Connect the shapefile reader to the AttributeManager and in the AttributeManager properties, change the Output Attribute "NumAddress" to "NumAddresses".In addition, change the Action for fme_geometry, fme_type, fme_feature_type and SHAPE_GEOMETRY (i.e.the attributes exposed in the previous step) to "Remove".
* Note - The exposed format attributes are being removed so that they do not get appended to our destination feature class via our upcoming Python code.
3。添加字段到目标要素类
为了包含在源shape文件的新领域获得包括到我们现有的目标要素类,则必须以编程方式添加。这将允许架构更改生效,而不必放弃现有的特征类表格。该PythonCaller用于通过调用两个FME的功能(fmeobjects)和ArcGIS(ArcPy中)做出这些改变。
首先,对于两个FME和ArcGIS Python模块被导入其中,所述目的地地理数据库路径,然后从对应FME宏读取。然后,我们硬编码了我们的目的地要素类与地理数据库的路径名。在ArcPy中的功能“列表字段”,然后用于获取当前包含在目标要素类的字段名称的单独字符串。然后创建一个空的列表变量,从我们的列表字段调用字符串被追加到空列表。
其次,fmeobjects feature.getAllAttributeNames()函数来获取对源数据集的字段列表。然后,我们比较包含在源属性目标属性列表中的值,从那里源属性的目标数据集已经存在的源属性列表中删除实例。
最后,我们循环源属性列表中,其余值字段添加到基于问题的属性的数据类型的目标要素类。
下面包含将出现在PythonCaller整个代码定义:
进口FME进口fmeobjects导入ArcPy中#模板函数接口:#使用此功能时,请确保它的名称设置为#的价值“类或函数来处理功能”变压器参数高清processFeature(功能):#获取的位置 the Destination GDB from the FME Macro value.Dest_GDB = fme.macroValues [“DestDataset_GEODATABASE_FILE”]#调用从目标地理数据库和#目标要素类得到目标要素类的字段名称的列表。dest_featureclass = Dest_GDB + '\\ GarbageSchedule' dest_attr = arcpy.ListFields(dest_featureclass)#创建目标要素类空列表并添加字段名。dest_list = []用于在dest_attr:从源文件dest_list.append(a.name)#获取属性名称。source_attr = feature.getAllAttributeNames()#比较在dest_list的值中的值的列表中source_attr和#删除重复用于VAL在dest_list:如果val在source_attr:source_attr.remove(VAL)#对于剩余的属性(即源中不存在目标),#添加相应的#字段与适当的数据类型。用户可如果#数据类型的语句作为其数据需要添加更多。在source_attr值:如果类型(值)== STR:arcpy.AddField_management(dest_featureclass,值, “TEXT”)如果类型(值)== INT:arcpy.AddField_management(dest_featureclass,值, “LONG”)
请务必将类或函数改变工艺特点为“processFeature”,使正常功能将被执行。
4。写数据
ESRI的地理数据库(文件地理数据库)的作家加入到工作区。对于作家的数据集,导航到地理数据库提供(请参阅add_fields.zip在下载部分)。要素类或表定义,选择“导入从数据集”。选择从数据集导入选项,因为要素类已在地理数据库存在,我们将数据写入并改变其架构。
出现提示时,设置的格式,然后选择文件地理数据库中上段提到(它可能 - 应该 - 已经由FME设置)。FME将扫描的地理数据库,以确认哪些表存在。当用类列表提示,选择GarbageSchedule。
一旦作家已经被添加到画布上,对作家特征类型双击进入专题类型属性对话框。单击格式参数选项卡,并设置截断表“是”。
保存并运行工作区和从shape文件检查数据,而且目前拥有“卡车”领域,同时保持从要素类的原始属性字段名称添加。
数据归属
这里使用源自从公开数据中的数据由提供温哥华市, 不列颠哥伦比亚省。它包含了开放政府许可协议进行许可信息 - 温哥华。
Converting to Geodatabase Format
Comparison of FME readers and writers for SDE and Geodatabase
Working with Geodatabase Domains: Writing A Coded Domain
Election Results for Local Government
Working with Geodatabase Subtypes: Writing A Subtype
Introduction to Working with Geodatabase Relationship Classes
Writing Geodatabase Relationship Classes
Attribute Table in ArcGIS: "Could Not Load Data"
© 2020 Safe Software Inc |Legal