AE開發中,要素類新增欄位
/// <summary>
/// 新增欄位,以及計算幾何面積
/// </summary>
/// <param name="pFeatureLayer">向量圖層</param>
/// <param name="fieldName">新增的欄位名稱,如:相交面積</param>
private void AddCalculateField(IFeatureLayer pFeatureLayer, string fieldName)
{
//獲取預審生成圖層
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IField pField = null;
IFieldEdit pFieldEdit = null;
if (pFeatureClass.Fields.FindField(fieldName) < 0)
{
pField = new FieldClass();
pFieldEdit = pField as IFieldEdit;
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
pFieldEdit.Name_2 = fieldName;
pFieldEdit.IsNullable_2 = true;
pFeatureClass.AddField(pField);
}
IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
//設定座標系統,計算幾何需要座標系統
pFeature.Shape.Project(m_spatialReference);
double area = pArea.Area;
int index = pFeature.Fields.FindField(fieldName);
pFeature.set_Value(index, area);
pFeature.Store();
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = pFeatureCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
}
IFeatureClass pFeatureClass = m_FeatureLayer.FeatureClass;
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
ISpatialReference m_spatialReference = pGeoDataset.SpatialReference;