1. 程式人生 > >[C#] [ArcGIS] [Engine] 對選擇的要素進行資料更新操作

[C#] [ArcGIS] [Engine] 對選擇的要素進行資料更新操作

/// <summary>
/// 獲取選擇要素並進行更新操作
/// </summary>
/// <param name="featureLayer">圖層要素物件</param>
/// <returns>返回遊標物件</returns>
public static IFeatureCursor get_SelectedFeatures_Update(IFeatureLayer featureLayer)
{
    ICursor cursor = null;
    IFeatureCursor featureCursor = null;
    if (featureLayer== null) 
    {
        return null;
    }
    // 選定的特徵集
    IFeatureSelection featureSelection = featureLayer as IFeatureSelection;

    // 由於 ISelectionSet2 繼承自 ISelectionSet 介面並且可以通過 SelectionSet 類物件進行實現
    // 所以這裡將 ISelectionSet 型別的 SelectionSet 轉換為 ISelectionSet2
    ISelectionSet2 selectionSet2= featureSelection.SelectionSet as ISelectionSet2;       

    // 在 ISelectionSet 中只有 Search 方法,可以進行搜尋
    // 在 ISelectionSet2 中添加了 Update 方法,可以進行更新、搜尋
    selectionSet2.Update(null, false, out cursor);
    featureCursor = cursor as IFeatureCursor;
    return featureCursor;         
}