Addin source code for setup flow direction
1.Create an c# object with establish flow as a function
2.Call this function from the addin on click method by passing the application reference and the type of flow direction you wish to set to your network
To know more about geometric network setting flow direction setting flow direction
Setting Flow Direction through ArcObjects Code |
public static void EstablishFlow(Globals.GNFlowDirection flowDirection, IApplication app)
{
IProgressDialog2 progressDialogs= default(IProgressDialog2);
IProgressDialogFactory progressDialogFactorys = null;
IEditor editing = null;
IMouseCursor appCursor = null;
INetworkAnalysisExt netExt = null;
UID pUID = null;
List<IGeometricNetwork> geonetworklist= null;
ITrackCancel trackCancel = null;
Int32 int32_hWnd;
IStepProgressor stepProgressorobj= null;
IMxDocument mxdoc = null;
IEditLayers eLayers = null;
IMap pMap = null;
try
{
int calcCount = 0;
//Get editing
editing = Globals.geteditor(ref app);
if (editing.EditState != esriEditState.esriStateEditing)
{
MessageBox.Show(Teamgeofunctions.Localizer.GetString("MustBEditg"), Teamgeofunctions.Localizer.GetString("GeoNetToolsLbl_2"));
return;
}
eLayers = editing as IEditLayers;
//Change mouse cursor to wait - automatically changes back (ArcGIS Desktop only)
appCursor = new MouseCursorClass();
appCursor.SetCursor(2);
ESRI.ArcGIS.esriSystem.IStatusBar statusBar = app.StatusBar;
statusBar.set_Message(0, Teamgeofunctions.Localizer.GetString("GeoNetToolsWait_1"));
//Get NA Extension in order to update the current network with the first visible network
pUID = new UIDClass();
pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
netExt = app.FindExtensionByCLSID(pUID) as INetworkAnalysisExt;
//Get Visible geometric networks
pMap = editing.Map;
geonetworklist= Globals.GetGeometricNetworksCurrentlyVisible(ref pMap);
if (gnList.Count > 0)
{
//ProgressBar
progressDialogFactorys= new ProgressDialogFactoryClass();
// Create a CancelTracker
trackCancel = new CancelTrackerClass();
// Set the properties of the Step Progressor
int32_hWnd = app.hWnd;
stepProgressorobj= progressDialogFactory.Create(trackCancel, int32_hWnd);
stepProgressor.MinRange = 0;
stepProgressor.MaxRange = gnList.Count;
stepProgressor.StepValue = 1;
stepProgressor.Message = "";
stepProgressor.Hide();
// Create the ProgressDialog. This automatically displays the dialog
progressDialogs= (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast
// Set the properties of the ProgressDialog
progressDialog.CancelEnabled = false;
progressDialog.Description = Teamgeofunctions.Localizer.GetString("GeoNetToolsDesc_1");
progressDialog.Title = Teamgeofunctions.Localizer.GetString("GeoNetToolsTitle_1");
progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
bool editStarted = false;
try
{// Create an edit operation enabling undo/redo
editing.StartOperation();
editStarted = true;
}
catch
{
editStarted = false;
}
IGeometricNetwork gn = null;
IEnumFeatureClass enumFC = null;
INetwork net = null;
IUtilityNetworkGEN unet = null;
IEnumNetEID edgeEIDs = null;
//IFeatureLayer fLayer = null;
try
{
for (int i = 0; i < gnList.Count; i++)
{
gn = gnList[i] as IGeometricNetwork;
stepProgressor.Message = Teamgeofunctions.Localizer.GetString("GeoNetToolsProc_1");// +fLayer.Name;
//Establish flow using AncillaryRole values
if (flowDirection == Globals.GNFlowDirection.AncillaryRole)
{
enumFC = gn.get_ClassesByNetworkAncillaryRole(esriNetworkClassAncillaryRole.esriNCARSourceSink);
if (enumFC.Next() == null)
MessageBox.Show(Teamgeofunctions.Localizer.GetString("GeoNetToolsError_1a") + gn.FeatureDataset.Name + Teamgeofunctions.Localizer.GetString("GeoNetToolsError_1b") + Environment.NewLine +
Teamgeofunctions.Localizer.GetString("GeoNetToolsError_1c"), Teamgeofunctions.Localizer.GetString("GeoNetToolsProc_2"));
else
{
gn.EstablishFlowDirection();
calcCount += 1;
}
}
//Establish flow direction based on digitized direction.
else
{
net = gn.Network;
unet = net as IUtilityNetworkGEN;
edgeEIDs = net.CreateNetBrowser(esriElementType.esriETEdge);
edgeEIDs.Reset(); int edgeEID;
for (long j = 0; j < edgeEIDs.Count; j++)
{
edgeEID = edgeEIDs.Next();
unet.SetFlowDirection(edgeEID, esriFlowDirection.esriFDWithFlow);
}
calcCount += 1;
}
stepProgressor.Step();
}
}
catch (Exception ex)
{
editing.AbortOperation();
MessageBox.Show(Teamgeofunctions.Localizer.GetString("GeoNetToolsProc_2") + "\n" + ex.Message, ex.Source);
}
finally
{
if (enumFC != null)
Marshal.ReleaseComObject(enumFC);
gn = null;
enumFC = null;
net = null;
unet = null;
edgeEIDs = null;
//fLayer = null;
}
if (editStarted)
{ // Stop the edit operation
if (flowDirection == Globals.GNFlowDirection.AncillaryRole)
editing.StopOperation(Teamgeofunctions.Localizer.GetString("GeoNetToolsProc_2"));
else
editing.StopOperation(Teamgeofunctions.Localizer.GetString("GeoNetToolsProc_3"));
}
object Missing = Type.Missing;
mxdoc = app.Document as IMxDocument;
mxdoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Missing, mxdoc.ActiveView.Extent);
}
catch (Exception ex)
{
return;
}
finally
{
// delete the references to cleanup the memory
if (progressDialogs!= null)
progressDialog.HideDialog();
progressDialogs= null;
progressDialogFactorys= null;
editing = null;
eLayers = null;
appCursor = null;
netExt = null;
pUID = null;
pMap = null;
geonetworklist= null;
trackCancel = null;
stepProgressorobj= null;
mxdoc = null;
}
No comments:
Post a Comment