第8页
斯潘4
注:内容已更新为FME 2018.1,但视频仍然显示2016.1,略有不同的示例。
存储在数据库中的信息不太可能保持不变。当这些更改的来源是其他地方的数据集时,必须进行批量更新。
此示例执行更新的混合 - 首先是插入,然后更新和删除操作 - 使用更改检测来确定要执行的操作。
注:尽管本例使用了PostGIS数据库,但同样的技术也适用于其他数据库。
源数据是温哥华市的公园数据集:
地图瓷砖雄蕊设计, 在下面CC-BY-3.0.Data byOpenStreetMap, 在下面cc-by-sa.
首先必须将数据上传到PostGIS database (a workspace already exists for this). Then an updated dataset becomes available because of various updates and reassessments. The updates must then be applied to the PostGIS table.
1.创建数据库连接
如果还没有准备好数据库连接(如本教程中其他几个练习中所使用的),则必须立即创建它。
启动FME工作台。从菜单栏中选择“工具”>“FME选项”,然后从选项列表中选择“数据库连接”。
如果您已经有一个名为PostGIS Training Database的连接,则可以跳到步骤2。否则,请单击+按钮添加新连接:
In the dialog that opens, enter the connection parameters:
…然后单击“保存”保存新连接。
2.打开工作区
Start FME Workbench and open the attached template for data loading.
注:如果“导航器”窗口的“数据库连接”部分高亮显示为红色,则可能跳过了第1部分,或者连接的名称不正确:
If you don't have a connection at all, be sure to carry out step 1. If you did create a connection, but it has a different name, then you can double-click this parameter to choose the different version.
3. Run Workspace
工作区如下所示:
请注意,它只是从MapInfo选项卡格式读取公园数据(对于市中心区域)并将其加载到Postgis上的数据库表中。表处理处于删除和创建模式(即它将被删除并完全由此新数据集替换)。
运行工作区。一旦完成 - 并检查数据以确保它是正确的 - 可以关闭工作区。
4.生成工作区
使用Generate选项(快捷方式Ctrl+G)生成新的工作区。使用以下参数:
因为我们要写入的表已经存在,我们应该将其模式(数据模型)导入工作区。所以还要检查按钮导入要素类型定义:
Click OK to close the dialog and generate the workspace. The Import option will cause you to be prompted to choose a table to import. Set the format to帖子并选择先前定义的数据库连接。然后单击“参数”按钮。选择fmedemo公司模式和市中心公园桌子:
单击“确定”并再次确定以关闭对话框并完成工作区生成过程。
5. Add PostGIS Reader
根据需要执行的操作,我们需要将每个传入功能标记为更新,删除或插入。要确定动作,我们必须将记录与原始数据库表进行比较,并且我们需要一个Partgis读者。
所以从菜单栏中选择Readers>addreader。
就像在上一步中所做的那样,将格式设置为帖子并选择先前定义的数据库连接。然后单击“参数”按钮。选择fmedemo公司模式和市中心公园桌子。
现在,当您关闭这些对话框时,此表将作为读取器添加到工作区。出于最佳实践目的,您可能希望在其周围添加书签,或扩展现有书签:
6.添加更新的检测变压器
To detect changes, add an UpdateDetector transformer.
注:该变形器是转换器的扩展。虽然它存储在FME集线器上,但它仍然可以使用快速添加添加。对于FME2019,ChangeTetector已更新为包括所需功能。
Connect the PostGIS reader feature type to the UpdateDetector:Original input port, and the MapInfo ParksUpdate feature type to the UpdateDetector:Revised input port:
请注意,在上面的屏幕截图中,修改后的/原始端口已反转,以避免连接重叠。
7.设置UpdateDetector参数
现在检查更新的特定参数。应将关键属性参数设置为ParkID。匹配的属性是可能已更改的属性。在本练习中,访问者数量已更新使用新信息,并且种植了更多的树木,因此选择VisitorCount和Trecount:
同时确保“匹配几何体”设置为“二维”。
UpdateDetector现在将根据所做的更改来分隔数据。您现在可以运行工作区并在数据检查器中检查结果-但请确保没有连接writer功能类型!
您现在可以看到新数据集中已更新的14个功能,1已被删除,4个不变。
请注意fme_db_operation属性已设置在这些功能上!因此,我们不需要担心为自己设置:
当然,如果使用另一个转换器来检测变化,那么每个输出端口都可以连接到AttributeManager,然后fme_db_operation手动设置。
8.更新Postgis作家
Now connect the UpdatedDetector:Updated and UpdateDetector:Deleted output ports to the PostGIS writer feature type. Note there is no need to connect the Unchanged output port, since these features do not need updating in the database table. In fact, if this was connected then the result would be a set of duplicate features:
现在检查writer特性类型参数。将功能操作设置为fme_db_operation,并确保表处理设置为Use Existing.
选择ParkId作为更新的匹配列:
将功能操作设置为fme_db_operation意味着属性值fme_db_operationon the feature will guide whether the feature is updated or deleted in the database table. Match Columns is a form of在哪里子句用于确保在数据库表中更新或删除相应的行。
9. Inspect Data and Run Workspace
Before running the workspace, inspect the current contents of the市中心公园桌子。记下visitorcountand树计数多个记录的字段。这将确保我们可以比较结果来证明更新过程是成功的。
Now run the workspace. Re-inspect the data. You will see that where a帕基德比赛,这匹配树计数andvisitorcount字段可能已更新:
还请注意,在修改后的表中少了一个停车场。大教堂广场公园已被拆除。
The procedure outlined above was demonstrated on PostGIS. However the exact same process applies to most major database formats, which have been协调.
如果您的数据库格式具有不协调的接口,则必须应用以下内容。
fme_where属性是等效设置统一GUI中的匹配列参数。它应该是[数据库字段] [运算符] [属性](即数据库字段第一个)的格式。操作员通常是等于操作(=)。
如果工作区更新失败,那么修复错误并重新运行工作区将比平常更困难,因为数据库现在已经部分更新。
因此,第一步是重置它。最简单的方法是重新打开数据加载模板并重新运行它。这将将表重置为原始状态。
要解决更新过程中的问题,请检查以下各项:
It's important to not connect the Unchanged port because these features already exist and this data would just get added to the table.
The data used here originates from open data made available by the City of Vancouver, British Columbia (data.vancouver.ca.). It contains information licensed under the Open Government License - Vancouver.
© 2019安亚搏在线全软件公司|法律