Code with C# to Split line in ARCGIS 10

3804
1
Jump to solution
09-15-2015 04:15 PM
MohammedAlsadaany
New Contributor II

Dear

i'm new with Arcmap

i have task i need a help in it

i need to make a button to split a selected line into two lines using C#

please i need a help

Best regards

0 Kudos
1 Solution

Accepted Solutions
OlaRennemo
New Contributor III

Hi, just a few hints, if you indend to use ArcObjects and C#, and have not found out already:

There are many detalis to consider, and a lot of documentation to read. Online help is useful.

This is approximately how I do it:

    

"Acivate split processing mode in your code via custom tool event"

"Click on map"

...

IPoint p = mxDoc.CurrentLocation;

IEnvelope e = p.Envelope;

e.Expand( searchRadius);

map.SelectByShape(e,env,justOne);              

IFeatureSelection fs = (IFeatureSelection)lineFeaturelayer;

IEnumIDs en = fs.SelectionSet.IDs;    
en.Reset();
for(int i=0; i<fs.SelectionSet.Count; i++)
{
Int32 fid = en.Next();
}...

IFeature f = lineFeaturelayer.FeatureClass.GetFeature(fid);

IPolyline plin = (IPolyline)f.Shape

    

plin.SplitAtPoint(p, projecPointOnLine, createPart, out splitDone, out newPartIndex, out newSegmentIndex);

feature1.shape = ..

feature1.Store();

feature2.shape = ..

feature2.Store();

...

View solution in original post

1 Reply
OlaRennemo
New Contributor III

Hi, just a few hints, if you indend to use ArcObjects and C#, and have not found out already:

There are many detalis to consider, and a lot of documentation to read. Online help is useful.

This is approximately how I do it:

    

"Acivate split processing mode in your code via custom tool event"

"Click on map"

...

IPoint p = mxDoc.CurrentLocation;

IEnvelope e = p.Envelope;

e.Expand( searchRadius);

map.SelectByShape(e,env,justOne);              

IFeatureSelection fs = (IFeatureSelection)lineFeaturelayer;

IEnumIDs en = fs.SelectionSet.IDs;    
en.Reset();
for(int i=0; i<fs.SelectionSet.Count; i++)
{
Int32 fid = en.Next();
}...

IFeature f = lineFeaturelayer.FeatureClass.GetFeature(fid);

IPolyline plin = (IPolyline)f.Shape

    

plin.SplitAtPoint(p, projecPointOnLine, createPart, out splitDone, out newPartIndex, out newSegmentIndex);

feature1.shape = ..

feature1.Store();

feature2.shape = ..

feature2.Store();

...