C#+ArcGIS Engine实现获取图层字段信息

FieldInformation类用于保存字段信息:

public class FieldInformation
{
	public int Index { get; set; }

	public bool Editable { get; set; }

	public string Name { get; set; }

	public esriFieldType FieldType { get; set; }

	public int Precision { get; set; }

	public int Scale { get; set; }

	public int Length { get; set; }

	public string Alias { get; set; }

	public bool IsNullable { get; set; }

	public bool IsRequired { get; set; }
}

获取字段信息的方法:

public static List<FieldInformation> GetFieldInformation(IFields pFields, string sTableName = "")
{
	List<FieldInformation> lstFieldInformation = null;
	try
	{
		var nFieldCount = pFields.FieldCount;
		for (int i = 0; i < nFieldCount; i++)
		{
			var pField = pFields.Field[i];
			if (null == pField) continue;

			var sFieldName = pField.Name;
			if (!string.IsNullOrEmpty(sTableName))
			{
				var nIndexOfDot = sFieldName.LastIndexOf(".");
				if (nIndexOfDot > 0)
				{
					var sFieldTable = sFieldName.Substring(0, nIndexOfDot);
					if (0 != string.Compare(sTableName, sFieldTable, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					sFieldName = sFieldName.Substring(nIndexOfDot + 1);
				}
			}

			if (null == lstFieldInformation) lstFieldInformation = new List<FieldInformation>();
			lstFieldInformation.Add(new FieldInformation()
			{
				Index = i,
				Editable = pField.Editable,
				Name = sFieldName,
				FieldType = pField.Type,
				Precision = pField.Precision,
				Scale = pField.Scale,
				Length = pField.Length,
				Alias = pField.AliasName,
				IsNullable = pField.IsNullable,
				IsRequired = pField.Required
			});
		}
		return lstFieldInformation;
	}
	catch
	{
		return null;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值