/// <summary>
/// 向图层添加字段
/// </summary>
/// <param name="layer">图层对象</param>
/// <param name="name">字段名称</param>
/// <param name="alias">字段别名</param>
/// <param name="type">字段类型</param>
public static void AddField(ILayer layer, string name, string alias, esriFieldType type)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = (IFeatureLayer)layer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向图层添加字段
/// </summary>
/// <param name="layer">图层对象</param>
/// <param name="name">字段名称</param>
/// <param name="alias">字段别名</param>
/// <param name="type">字段类型</param>
/// <param name="length">字段长度</param>
public static void AddField(ILayer layer, string name, string alias, esriFieldType type, int length)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = (IFeatureLayer)layer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fieldEdit.Length_2 = length;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向图层添加字段
/// </summary>
/// <param name="featureLayer">图层对象</param>
/// <param name="name">字段名称</param>
/// <param name="alias">字段别名</param>
/// <param name="type">字段类型</param>
public static void AddField(IFeatureLayer featureLayer, string name, string alias, esriFieldType type)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = featureLayer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
/// <summary>
/// 向图层添加字段
/// </summary>
/// <param name="featureLayer">图层对象</param>
/// <param name="name">字段名称</param>
/// <param name="alias">字段别名</param>
/// <param name="type">字段类型</param>
/// <param name="length">字段长度</param>
public static void AddField(IFeatureLayer featureLayer, string name, string alias, esriFieldType type, int length)
{
if (alias == "")
{
alias = name;
}
try
{
IFeatureLayer flayer = featureLayer;
IFeatureClass fclass = flayer.FeatureClass;
IField newField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)newField;
fieldEdit.Name_2 = name;
fieldEdit.Type_2 = type;
fieldEdit.AliasName_2 = alias;
fieldEdit.Length_2 = length;
fclass.AddField(newField);
}
catch (Exception)
{
;
}
}
向图层添加字段
最新推荐文章于 2023-02-15 14:30:18 发布