Geotools:关于SimpleFeatureTypeBuilder

时间:2018-09-25 07:54:01

标签: java geotools

我想设置一个字符串类型字段的长度,但是我看到源代码:

调用{@link #add(String,Class)}

后,

值将重置

方法的意义是什么?如何设置字符串类型字段的长度?有人可以帮助我

/**
 * Sets a restriction on the field length of the next attribute added to the feature type.
 *
 * <p>This method is the same as adding a restriction based on length( value ) < length This
 * value is reset after a call to {@link #add(String, Class)}
 *
 * @return length Used to limit the length of the next attribute created
 */
public SimpleFeatureTypeBuilder length(int length) {
    attributeBuilder.setLength(length);
    return this;
}

1 个答案:

答案 0 :(得分:0)

如果您遵循这些代码,将会看到调用add(String, Class)来将新属性添加到架构。它调用AttributeTypeBuilder对属性进行编码。 setLength在此处存储您在length中设置的长度限制。生成属性后,将调用resetTypeState以“重置”属性构建器,以准备下一个属性(这是将长度重置为null的地方)。

因此,将属性添加到架构后,JavaDoc警告是正确的长度被重置,因此,如果要对属性设置长度限制,则需要执行以下操作:

fBuilder.length(30);
fBuilder.add("myStringAttr",String.class);
schema = fBuilder.buildFeatureType();