Skip to content

Instantly share code, notes, and snippets.

@BrunoCaimar
Created August 16, 2019 20:18
Show Gist options
  • Save BrunoCaimar/bd9414f21920084c6ca344714ff11601 to your computer and use it in GitHub Desktop.
Save BrunoCaimar/bd9414f21920084c6ca344714ff11601 to your computer and use it in GitHub Desktop.
Flip line - AO
///<summary>The edit sketch direction of all of the selected polyline features is changed or flipped.</summary>
///
///<param name="application">An IApplication interface.</param>
///<param name="editor">An IEditor interface.</param>
///
///<remarks>Already must have a reference to IApplication and get the editor and start an edit session in the edit session you must have an edit selection, the code checks to make sure it is a line feature class and makes sure that there is an edit selection.</remarks>
public void FlipLineDirection(ESRI.ArcGIS.Framework.IApplication application, ESRI.ArcGIS.Editor.IEditor editor)
{
if(application == null || editor == null)
{
System.Windows.Forms.MessageBox.Show("Flip operation aborted");
return;
}
ESRI.ArcGIS.Editor.IEditLayers editLayers = editor as ESRI.ArcGIS.Editor.IEditLayers;
// set up the progress bar and convert the number of selected features into an integer value.
System.Int32 step = System.Convert.ToInt32(editor.SelectionCount / 100);
ESRI.ArcGIS.esriSystem.IStatusBar statusBar = application.StatusBar;
ESRI.ArcGIS.esriSystem.IStepProgressor stepProrogressor = statusBar.ProgressBar;
stepProrogressor.MinRange = 1;
stepProrogressor.MaxRange = 100;
stepProrogressor.Message = "Flipping features...";
stepProrogressor.Position = 0;
stepProrogressor.StepValue = 1;
stepProrogressor.Show();
try
{
// flip all the selected features in an edit operation
editor.StartOperation();
ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature = editor.EditSelection;
enumFeature.Reset();
for (System.Int32 featCount = 0; featCount <= editor.SelectionCount - 1; featCount++)
{
ESRI.ArcGIS.Geodatabase.IFeature feature = enumFeature.Next();
if(!(feature is ESRI.ArcGIS.Geometry.ICurve))
{
continue;
}
ESRI.ArcGIS.Geometry.ICurve curve = feature.Shape as ESRI.ArcGIS.Geometry.ICurve;
curve.ReverseOrientation();
feature.Shape = curve;
feature.Store();
if (featCount == step)
{
stepProrogressor.Step();
step = step + System.Convert.ToInt32(editor.SelectionCount / 100);
}
}
editor.StopOperation("Flip");
stepProrogressor.Hide();
return;
}
catch(System.Exception e)
{
editor.AbortOperation();
System.Windows.Forms.MessageBox.Show("Flip operation aborted");
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment