斯潘8
span4
Note:文章更新至2018.1。Demo video still shows 2016.1
Simply writing data into a new table in a database is not much more complex than writing to a file format.每个功能类型(表)都有许多参数,允许用户控制对该表的写入。
Feature Operation
Operations are controlled through a parameter called Feature Operation.This parameter informs FME what action to carry out on the database.Its three values are INSERT,UPDATE,and DELETE.
工作台处理
存在多个表处理参数以帮助创建或更新现有数据库表。
以下示例加载公共艺术数据,创建新表.It then shows how to replace a table using a Table Handling parameter.
Note:Although using PostGIS,this example is also applicable to both PostgreSQL and any other FME format with a harmonized dialog.
The source is a dataset of Vancouver public art in CSV (Comma-Separated) format.Although CSV data is non-spatial,the CSV reader in FME can create point features if columns containing x/y coordinates exist.
使用数据检查器查看公共艺术数据
1。添加csv阅读器
Start FME Workbench and begin with a blank canvas.
添加读卡器以读取csv数据。最简单的方法是从Windows资源管理器中将downtown.csv文件拖到工作台画布上。
弹出的添加读卡器对话框会自动填充格式和数据集。
单击参数按钮。In the dialog that opens change the Attribute Definition parameter to Manual.Set the field types for Longitude and Latitude to x_coordinate and y_coordinate:
这告诉读者在读取文件时从csv数据创建点。Click OK to close the parameters dialog.
Back in the Add Reader dialog,将坐标系设置为LL84:
Each point will be tagged with this coordinate system as it's read.Click OK to close the Add Reader dialog.
2。添加Postgis编写器
现在添加一个Postgis编写器。最简单的方法是从菜单栏中选择“编写器>添加编写器”。在“添加编写器”对话框中,将格式设置为Postgis。
For Dataset,选择在中创建的PostGIS培训数据库连接查看和检查PostGIS.如果没有此命名数据库连接,选择添加数据库连接参数的选项,然后,in the dialog that opens,输入连接参数:
…然后单击“保存”保存新连接。
Back in the Add Writer dialog,对于表定义,选择从读卡器复制,因此,源模式用于定义PostGIS表:
Click OK to close the Add Writer dialog.
三。定义表
After closing the Add Writer dialog,特性类型(表)将添加到工作台画布中。单击齿轮图标以访问此对象的参数对话框。
将表名从csv更改为downtown\u publicart。将表限定符设置为fmedemo。
The Table Qualifier is the same as the Schema for Table Listing in the PostGIS Reader parameters.每个数据库表都指定了它,因为可以使用同一个数据库编写器写入多个架构。
下面是定义如何处理表的对话框部分:
As we are creating a new table in the PostGIS database and adding data to it,Feature Operation is left as Insert and Table Handling as Create If Needed.
Note:
If were updating the table instead of creating it - for example the table already existed and these CSV records are to replace its content - then we might choose Drop and Create (if the fields/attributes were also changing) or Truncate Existing (if the fields/attributes were not going to change):
事实上,因为这是在共享数据库实例上运行的,选择Drop和Create可能更安亚搏在线全,如果此教程的另一个读者已经创建了表!
单击“确定”关闭对话框。
4.Map Attributes
The attributes currently are not connected in this workspace;主要是因为源属性有一个标题库名称,而writer属性有小写。
幸运的是,这个自动连接属性andReplace Link with AttributeManagerfunctions can resolve this issue very quickly.
First right-click on the connection and select Auto Connect Attributes:
Then right-click again and choose Replace Link with AttributeManager:
5.运行工作区
单击工具栏上的绿色“播放”按钮以运行工作区。The data will be read,mapped,并写入输出数据库表。
在FME数据检查器中打开市中心的“PublicArt Postgis”表以查看结果:
To替换表的全部内容,the Table Handling parameters to use are "Drop and Create" and "Truncate Existing".
“截断现有”is used when the table needs to be emptied of existing data,但不需要对其模式进行更新。“删除并创建”is used when the table needs to be emptied AND an update is to be made to the database schema.For example,如果希望用新内容更新表并要求向表中添加新列,请使用此选项。
When using either of these,你想设置Feature Operation要插入的参数。UPDATE and DELETE will be of no use when the existing table has been emptied first.
If you came to this page from the更新数据库tutorial:
这里使用的数据来源于温哥华市提供的开放数据,不列颠哥伦比亚(数据.couver.ca)It contains information licensed under the Open Government License - Vancouver.
© 2019 亚搏在线Safe Software Inc |合法的