否,没有预定义的函数来将Python API中的数据类型代码映射到FME通用数据类型名称。 p>
每个功能属性都没有固定数据类型,因为它们可以在数据流中更改。例如,可以通过变压器将数值更改为字符串,反之亦然。也可以改变串的长度。“日期”,“DateTime”或'Time'被视为一个字符串。等等。 p>
您是否看到了Sementasetter自定义变压器(FME HUB)?其实现包含一个执行映射的Python脚本,但它可能不是理想的。 p>
再次感谢。您提到的文章表明FME使用的数据类型名称。我知道我必须使用这些名字。我在文档中找不到的是一种“将”数字“翻译成名称的方式。我想我可以基于我在Inspector中看到的,在其中我看到的名称和寻找这些名称来找到相应数字的映射列表。这似乎似乎并不是很有效,而且我有点惊讶地发现fmeobjects不能这样做。或者我不是在看普培的地方? p>
Addition.
由于数据功能没有可以直接用于配置模式的模式信息,因此不容易根据它们创建架构功能。 p>
如果要根据数据特征创建架构功能,从 fme hub 可能会有所帮助。 p>
I have a feeling we're getting close, so thanks a lot already. However; with keeping it dynamically I have the following code to get the attributes and their types:
attrs = []<br> san = feature.getAllAttributeNames()<br> print "SAN: ",san<br> for a in san:<br> at = feature.getAttributeType(a)<br> attrs.append(a)<br> attrs.append(at) ft = feature.getAttribute('fme_feature_type') cs = feature.getCoordSys() ge = feature.getAttribute('fme_geometry')
I use these to set the schema:
# Create a schema feature.<br> schema = fmeobjects.FMEFeature()<br> for i in range(0, len(attrs), 2):<br> # name: attribute name, value: data type name<br> schema.setAttribute(attrs[i], attrs[i+1])<br> schema.setAttribute('fme_geometry{0}', ge)<br> schema.setFeatureType(ft)<br> schema.setCoordSys(cs)
This gives me a list of all attributes, which I loop over to get their attribute types. The attribute types are represented by numbers:
ATTRS: ['SHAPE_Length', 9, 'DTB_ID', 6, 'geodb_oid', 6, 'geodb_type'
The list is longer, but this is to give an idea. When addind the schema to the writer:
# Add the schema feature to the writer.<br> ObjWriter.addSchema(schema)
This gives the error:
No geometry mapping entry found for '11' in metafile GEODATABASE_FILE.fmf'.
感谢 @takashi ,我会尝试创建列表Python,因为我不知道它是什么。使用GetSequenceAttribute和GetFeaturetype,我认为可能有可能动态获取所有内容。 p>
Since you are using FME 2015.1, this method also might be apply to your workspace : Destination Schema is Derived from a Schema Feature
The method described in this article was known as "Destination Schema is Derived from a List" before. The mechanism itself has not been changed.
If all the attribute names and their FME generic data types (fme_*), geometry type, and feature type name are known, you can create a schema feature and then set it to the writer object in a Python script. e.g.
# Pairs of Attribute Name and FME Generic Data Type Name attrs = ['attr1', 'fme_char(20)', 'attr2', 'fme_date', 'attr3', 'fme_int32'] # Create a schema feature. schema = fmeobjects.FMEFeature() for i in range(0, len(attrs), 2): # name: attribute name, value: data type name schema.setSequencedAttribute(attrs[i], attrs[i+1]) schema.setAttribute('fme_geometry{0}', 'fme_line') schema.setFeatureType('FeatureTypeName') schema.setCoordSys('LL84') # optional # Set 'schema' to the writer object with the 'addSchema' method.
Regarding FME generic data types, see this article: Destination Schema is Derived from a Lookup Table
@takashi Thanks, but we have a workflow where the user is able to make modifications to the schema prior to this writer. This means that the schema from the source data is possibly not the same as the one we're trying to write. If I would include an inspector prior to this python script, the data inspector is showing the table with the modified column and feature class names. Therefor I assumed it would be possible to derive the schema from the feature itself.
嗨 @bzwemmer ,您必须读取架构 strong>功能从源数据集中,在编写数据 strong>功能之前,将它们添加到编写器。这是一个最小的示例。 p> #pythoncaller脚本示例:动态架构[geodatabase_file] writer#destination模式来自源ESRI Shapefile DataSet。#每个架构定义名称等于读者功能类型名称。#writer覆盖现有的GDB数据集。#除“overwrite_geodb”之外的所有Writer指令和参数都留下默认值。#省略错误处理。导入fmeobjects class featureprocessor(对象):def __init __(self):gdb ='c:/fme/tmp/test.gdb'#todo:将其更改为实际目标数据集。指令= []#所有默认值。参数= ['overwrite_geodb','yes']#除“overwrite_geodb”之外的所有默认值。 self.writer = fmeobjects.FMEUniversalWriter('GEODATABASE_FILE', directives) self.writer.open(gdb, parameters) source = [] ################################################################ # TODO: Append all source Shapefile paths to the 'source' list. ################################################################ for src in source: reader = fmeobjects.FMEUniversalReader('ESRISHAPE', False) reader.open(src) self.writer.addSchema(reader.readSchema()) # Add SCHEMA feature. reader.close() def input(self, feature): feature.setFeatureType(feature.getAttribute('fme_feature_type')) self.writer.write(feature) # Write DATA feature. def close(self): self.writer.close()