span8
span4
Note:在很多情况下,使用FME阅读器读取表列表,然后特技演员变压器读取数据可能比下面描述的方法更好。
用户经常询问如何将特性类型列表传递给FME阅读器。For example,有人可能会给你一个文本文件,列出他们想要翻译的所有SDE表。FME中的每个读者都有一个Feature Types to Read参数,which accepts a list of tables or layers to read.But you want the workspace to read the list from a file or database table.Below are two examples of how we can do this.
Also attached is a simple text file that lists the tables we want to read,calledFeatureTypesToRead.txt.表如下所示:
支持.国家子部门
Support.city_parks
Scripted parameters are a powerful way to set a parameter dynamically for FME with Python or TCL code.在这里,我们将使用脚本从文本文件中读取此表列表,并返回Feature Types to Read参数。在示例工作区geodatabase2shape.fmw中,look in the Navigator pane on the left and expand the private parameters.您将看到一个名为特征类型where the script opens the file and adds each line to thefeatureTypesvariable.下面是脚本:
# Get the file from a published parameter
ListFile = (FME_MacroValues['FeatureClassList'])
f = open(ListFile,'r')
featureTypes='
# Read the file and add each line to the featureTypes Variable
对于f.read().split(“\n”)中的行:
featureTypes += (line + " ")
f.close()
#Return this list to the parameter
返回特征类型
请注意,文件名来自已发布的参数。The workspace has a published parameter already set up to prompt the user for the text file they want to supply.
脚本返回我们想要读取的功能类型列表,but we need to link this to the reader.我们将私有脚本参数链接到Feature Types to Read导航窗格中读卡器上的参数,as shown below.
Rather than reading the list of tables from a text file,在本例中,我们从另一个Oracle表中读取Oracle空间读取器的表列表。否则,此示例与示例1非常相似。Here again we useDynamic Schemamode in the reader and writer,我们使用一个python脚本参数来读取阅读器的特性类型列表。
工作区包含已发布的参数以提示用户进行Oracle连接设置,对于表名,which contains the list of tables for the Oracle reader.脚本中使用Oracle连接参数连接到Oracle,Oracle Reader中使用相同的参数。
The scripted parameter is again called特征类型and is linked to theFeature Types to ReadOracle空间读取器的参数。This time,the Python script needs the Python moduleCXI Oracle,它包含在由FME安装的python版本中。Below is the script used to read the Oracle table.Note where we get the FME published parameter values for the Oracle connection using theFME_MacroValues[]dictionary.Also note that we use the尝试:syntax to give the user some help if the Oracle connection fails or if the table is not found.
导入cx_Oracle
import fmeobjects
#从FME中获取参数
User = FME_MacroValues['User']
Pass = FME_MacroValues['Pass']
Service = FME_MacroValues['Service']
TableName = FME_MacroValues['TableName']
featureTypes = ""
#Set Up Oracle Connection String
ConnectionString = User + '/' + Pass + '@' + Service
#Set Up Oracle Query
query = 'select * from ' + TableName
# Connect to Oracle and Query the table
尝试:
connection = cx_Oracle.connect(ConnectionString)
cursor = connection.cursor()
cursor.arraysize = 250 cursor.execute(query)
#Loop through records and add first field to featureTypes string
for row in cursor:
FeatureTypes=FeatureTypes+''+行[0]
cursor.close()
连接。关闭()
except: print 'Could not connect to database or table.'
# Sets the parameter
返回特征类型
传递功能类列表的一个选项是使用模式(任何格式)阅读器提取功能类,并将它们传递给FeatureReader。More explanation and a video showing this against a set of Esri File Geodatabases is available in如何从多个ESRI地理数据库中读取所有要素类.
Setting up a workspace to deploy in production,分段和本地
Extracting a schema subset for dynamic schemas
Can I pass a variable to FME to replace a fixed value within a workspace
Create Spatial Index after loading to ArcSDE - using Load only mode
Using a Python Startup/Shutdown Script or PythonCaller to Perform Geoprocessing with Arcpy
How to extract and use log information in Workbench
Passing a Published Parameter to a Workspace from the Command Line
© 2019 亚搏在线Safe Software Inc |Legal