Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Two polylines intersecting

I am stuck at a problem for weeks, Please Help!!!

I am making program in C# Here is what I need to do --- I have two polylines that are intersecting with each other at some points. I want to delete those portion of one polyline which are going above the other polyline. I am attaching an image explaining the problem I am going through. In this image, I have two Polylines Line1 and Line2. So according to that image, I want to remove the dashed portions of Line2.

Please Help!!! Thanks a ton in advance

Here is what I have done till now.... First I am finding out all the points of intersection of the two lines and saving them in a layer.... Then I am Splitting these lines at these points using this code...

while (pPointF != null)
{
    IPoint pPoint = (IPoint)pPointF.Shape;
    ISpatialFilter pSF = new SpatialFilterClass();

    pSF.Geometry = pPoint;
    pSF.GeometryField = "Shape";
    pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

    IFeatureCursor pLineCursor = pFeatureclass1.Search(pSF, true);
    IFeature pLineF = pLineCursor.NextFeature();

    while (pLineF != null)
    {
        IPolycurve pPolycurve = (IPolycurve)pLineF.Shape;
        IPoint pToPoint = pPolycurve.ToPoint;
        IPoint pFromPoint = pPolycurve.FromPoint;

        if (pFromPoint.X != pPoint.X && pFromPoint.Y != pPoint.Y && pToPoint.X != pPoint.X && pToPoint.Y != pPoint.Y)
        {
            IFeatureEdit pFeatureEdit = (IFeatureEdit)pLineF;
            pFeatureEdit.Split(pPoint);
        }
        pLineF = pLineCursor.NextFeature();
    }
}

The problem with this code that it is giving different results than expected. As I can see from attribute table, it is generating more than expected parts of line i.e. if there are 5 intersection points then there should be 6 parts of a line, nut it is creating 10-12 parts. Also the number of parts created for both lines are different, which logically should be same. Due to these problems, when I am trying to delete unwanted parts of line, the arcGis crashes..... Please help with this problem. . . . Now I am using a Geoprocessor to do splitting, following is the code:

        SplitLineAtPoint pSplitter = new SplitLineAtPoint();
        pSplitter.in_features = pPolylayer1;
        pSplitter.point_features = pPointsFeatureLayer;
        string outfile = txtDirName.Text + "\\" + "splitted";
        pSplitter.out_feature_class = @outfile;

        Geoprocessor GeoPro = new Geoprocessor();
        GeoPro.Execute(pSplitter, null);

But on the last line, where Geoprocessor is being executed, the ArcGIS crashes... Please tell me where is the problem...

share|improve this question
2  
This question makes almost no sense at all to me. Can you edit it to explain (all of) what the real data represents, what you mean by polyline (e.g. linestring or multilinestring), what you mean by polylines that "intersect at some points", what you mean by deleting a portion of a polyline, and what you mean by "going above". Also show what you've already done (paste the code), explain what happens now, and what you expect to happen instead. –  BradHards Apr 17 '13 at 5:43
1  
Sometimes a picture is worth a 1000 words, so if you can give an image of what you are trying to do, it will help. Further more, define "going above the other polyline" Do you mean towards the North? North of what? The intersection point, or the entire line? –  Devdatta Tengshe Apr 17 '13 at 5:46
    
This won't work because you are effectively deleting 1 feature and creating two new features each time you call Split(). I think this method is meant more for interactive splitting of one feature with one point at a time, not for multiple splitting of many features with many points. For that try IPolycurve2.SplitAtPoints –  blah238 Apr 22 '13 at 9:06
    
Also have you tried my answer yet? –  blah238 Apr 22 '13 at 9:08

1 Answer 1

It may make more sense to think of each segment of the second line as being on either the left or right hand side of the first line (based on its direction of digitization), rather than "above" or "below" which is ambiguous.

You could use ITopologicalOperator.Cut to divide the second line into left and right hand parts and discard only the left (or right) parts.

share|improve this answer
    
:: It may be correct for the given diagram which is an ideal case but sometimes I have curves also in polyline layers. There this methodology might mot be helpful... –  Avinash Nirankari Apr 17 '13 at 12:04
    
I think it would work with curves as well but I am not sure. You didn't mention curves in your question. –  blah238 Apr 17 '13 at 17:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.