public static void CalculateFlowAccum(List<FlowLayerDetails> sumFlowAcc, IApplication app)
{
IMap pMap = null;
IFeatureLayer pFLayer = null;
IFeatureSelection pFSel = null;
IFeatureCursor pFCursor = null;
ICursor pCursor = null;
IFeature pFeature = null;
IEditor pEditor = null;
string retAcc = "";
int lSumFieldLoc;
IProgressDialogFactory pProDFact;
IStepProgressor pStepPro;
IProgressDialog2 pProDlg = null;
ITrackCancel pTrkCan;
try
{
if (app == null)
return;
pMap = ((app.Document as IMxDocument).FocusMap);
if (pMap == null)
return;
pEditor = Globals.getEditor(app);
if (pEditor.EditState != esriEditState.esriStateEditing)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"));
return;
}
bool boolCont = true;
// Create a CancelTracker
pTrkCan = new CancelTrackerClass();
// Create the ProgressDialog. This automatically displays the dialog
pProDFact = new ProgressDialogFactoryClass();
pProDlg = (IProgressDialog2)pProDFact.Create(pTrkCan, 0);
pProDlg.CancelEnabled = true;
pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe;
// Set the properties of the Step Progressor
pStepPro = (IStepProgressor)pProDlg;
foreach (FlowLayerDetails sumAcc in sumFlowAcc)
{
bool boolFoundAsLayer = true;
pFLayer = Globals.FindLayer(app, sumAcc.LayerName, ref boolFoundAsLayer) as IFeatureLayer;
if (pFLayer == null)
{
//MessageBox.Show(sumAcc.LayerName + " feature layer not found.\nAny selected features in this layer will be analyzed for acculmuation.");
continue;
}
if (pFLayer.FeatureClass == null)
{
MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20a"));
continue;
}
if (Globals.IsEditable(ref pFLayer, ref pEditor) == false)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20b") + sumAcc.LayerName + ".");
}
pFSel = pFLayer as IFeatureSelection;
// Verify that the layer has some features selected
if (pFSel.SelectionSet.Count < 1)
{
//MessageBox.Show(sumAcc.LayerName + " layer must have some features selected.");
continue;
}
lSumFieldLoc = pFLayer.FeatureClass.Fields.FindField(sumAcc.SumFlowField);
if (lSumFieldLoc == -1)
{
MessageBox.Show(sumAcc.LayerName + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20d") + sumAcc.SumFlowField + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_20e"));
return;
}
// Step through each selected feature in the selection set
pFSel.SelectionSet.Search(null, false, out pCursor);
pFCursor = pCursor as IFeatureCursor;
// Set the properties of the ProgressDialog
pProDlg.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20a") + sumAcc.LayerName;
pProDlg.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20a") + sumAcc.LayerName;
pStepPro.MinRange = 0;
pStepPro.MaxRange = pFSel.SelectionSet.Count;
pStepPro.StepValue = 1;
pStepPro.Position = 0;
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20a") + sumAcc.LayerName + " 0" + A4LGSharedFunctions.Localizer.GetString("OutOf") + pFSel.SelectionSet.Count;
try
{
pEditor.StartOperation();
}
catch
{
pEditor.AbortOperation();
pEditor.StartOperation();
}
int cnt = 1;
while ((pFeature = pFCursor.NextFeature()) != null)
{
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_20a") + sumAcc.LayerName + cnt + A4LGSharedFunctions.Localizer.GetString("OutOf") + pFSel.SelectionSet.Count;
pStepPro.Step();
boolCont = pTrkCan.Continue();
if (!boolCont)
{
pStepPro.Hide();
pProDlg.HideDialog();
pStepPro = null;
pProDlg = null;
pProDFact = null;
return;
}
retAcc = Globals.ReturnAccumulation(ref app, ref pFeature, sumAcc.WeightName, sumAcc.FlowDirection);
if (Globals.IsNumeric(retAcc))
{
pFeature.set_Value(lSumFieldLoc, retAcc);
pFeature.Store();
}
else
{
}
cnt++;
}
pEditor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_20a") + sumAcc.LayerName);
}
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_20b"));
}
catch (Exception ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_20a") + "\n" + ex.Message);
}
finally
{
//pStepPro.Hide();
if (pProDlg != null)
pProDlg.HideDialog();
pProDFact = null;
pStepPro = null;
pProDlg = null;
pTrkCan = null;
pMap = null;
pFLayer = null;
pFSel = null;
if (pFCursor != null)
Marshal.ReleaseComObject(pFCursor);
pFCursor = null;
if (pCursor != null)
Marshal.ReleaseComObject(pCursor);
pCursor = null;
pFeature = null;
pEditor = null;
}
}