评论和回答“‘-999’w的字段类型as specified" https://knowledge.safe.com/questions/28152/a-field-type-of-999-was-specified.html The latest comments and answers for the question "A field type of '-999' was specified" Comment by takashi on takashi's comment https://knowledge.safe.com/comments/28277/view.html

否,没有预定义的函数来将Python API中的数据类型代码映射到FME通用数据类型名称。

每个功能属性都没有固定数据类型,因为它们可以在数据流中更改。例如,可以通过变压器将数值更改为字符串,反之亦然。也可以改变串的长度。“日期”,“DateTime”或'Time'被视为一个字符串。等等。

您是否看到了Sementasetter自定义变压器(FME HUB)?其实现包含一个执行映射的Python脚本,但它可能不是理想的。 星期三,2016年5月4日09:09:27 GMT Takashi. Comment by bzwemmer on bzwemmer's comment https://knowledge.亚搏在线safe.com/comments/28276/view.html.

再次感谢。您提到的文章表明FME使用的数据类型名称。我知道我必须使用这些名字。我在文档中找不到的是一种“将”数字“翻译成名称的方式。我想我可以基于我在Inspector中看到的,在其中我看到的名称和寻找这些名称来找到相应数字的映射列表。这似乎似乎并不是很有效,而且我有点惊讶地发现fmeobjects不能这样做。或者我不是在看普培的地方? Wed, 04 May 2016 08:33:31 GMT bzwemmer Comment by takashi on takashi's answer https://knowledge.亚搏在线safe.com/comments/28265/view.html.

Addition.

  • You should use 'setSequencedAttribute' method to add a pair of attribute name and data type to the schema feature, rather than 'setAttribute' method.
2016年5月4日星期三01:55:21 GMT Takashi.
Comment by takashi on takashi's answer https://knowledge.亚搏在线safe.com/comments/28236/view.html.

由于数据功能没有可以直接用于配置模式的模式信息,因此不容易根据它们创建架构功能。

  • 从“getallattributenames”列表方法包含模式配置不必要的格式属性(不优选)。您应该排除它们。
  • 从“getAttributeTepy”的值是一个整数常量,它不能用作架构配置的数据类型。您应该使用FME通用数据类型名称。例如'fme_int32','fme_char(20)'等请再次查看此文章:<目标=“_空白”href =“https://knowledge.safe.com/articles/1046/dynamic-workflo亚搏在线w-tutorial-destination亚搏在线-schema-is-de-1.html“>目标模式来自查找表
  • 应该将”fme_type“的值分配给'fme_geometry {0}',而不是'fme_geometry'。

    如果要根据数据特征创建架构功能,从 fme hub 可能会有所帮助。 星期二,03年5月3日15:57:53 GMT Takashi. bzwemmer回答 https://knowledge.亚搏在线safe.com/answers/28220/view.html.

    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'. 
    星期二,2016年5月3日14:55:26 GMT bzwemmer Comment by bzwemmer on bzwemmer's comment https://knowledge.亚搏在线safe.com/comments/28210/view.html.

    感谢 @takashi ,我会尝试创建列表Python,因为我不知道它是什么。使用GetSequenceAttribute和GetFeaturetype,我认为可能有可能动态获取所有内容。 Tue, 03 May 2016 10:24:17 GMT bzwemmer Comment by takashi on takashi's answer https://knowledge.亚搏在线safe.com/comments/28206/view.html.

    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.

    星期二,2016年5月3日09:15:17 GMT Takashi.
    Comment by takashi on takashi's answer https://knowledge.亚搏在线safe.com/comments/28205/view.html

    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

    Tue, 03 May 2016 08:59:45 GMT Takashi.
    Comment by bzwemmer on bzwemmer's answer https://knowledge.safe.com/comments/28203/view.html 抱歉,我意识到了其他东西:在Pyton中是否有规范。是列表,也是dicts或什么的列表?如果是这种情况,我可以在Pyhton中重新创建它。 Tue, 03 May 2016 08:13:39 GMT bzwemmer bzwemmer回答 https://knowledge.safe.com/answers/28202/view.html

    @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.

    星期二,03年5月3日08:11:14 GMT bzwemmer
    Takashi回答 https://knowledge.亚搏在线safe.com/answers/28201/view.html.

    @bzwemmer ,您必须读取架构功能从源数据集中,在编写数据功能之前,将它们添加到编写器。这是一个最小的示例。

    #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() 
    星期二,03年5月3日08:05:32 GMT Takashi.