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.

I'm trying to split a polyline by the boundaries of a polygon using IPolyCurve2.SplitAtPoints using C#. The polyline I'm trying to split is zAware and holds elevation values at a regular interval. After splitting the polyline I would obviously like to get the different parts and save them as new features in my feature class, then deleting the original one. The problem is that when I try to set feature.shape to the geometry in my geometry collection made up of all the polyline parts, I get the error message that the geometry has no Z values.

Does anybody know how to solve this issue? I've looked around in the forum but all I found was code that doesn't deal with polylines that hold Z values.

Thank you very much!

Here is the code I'm using, passing in the original polyline, the point collection that holds all the intersection points with the polygon and the original feature class I create new features in.

public void SplitPolylineFeature(IFeature pPolylineFeature, IPointCollection pSplitPointCollection, IFeatureClass pFeatureClass)
    {
        //split the feature, each split makes a new part
        IEnumVertex pEnumVertex = pSplitPointCollection.EnumVertices;
        IPolycurve2 pPolyCurve = pPolylineFeature.Shape as IPolycurve2;
        IEnumSplitPoint pEnumSplitPoint = pPolyCurve.SplitAtPoints(pEnumVertex, true, true, -1);
        object Missing = Type.Missing;

        if(pEnumSplitPoint.SplitHappened)
        {
            //new geocoll for polycurve
            IGeometryCollection pGeometryCollection = pPolyCurve as IGeometryCollection;

            //loop through the parts of the split polyline
            for(int intPartCount = 0; intPartCount < pGeometryCollection.GeometryCount; intPartCount++)
            {
                IGeometryCollection pLineGeoColl = new PolylineClass();
                IGeometry pGeometry = pGeometryCollection.get_Geometry(intPartCount);
                //IZAware zAware1 = (IZAware)pGeometry;
                //zAware1.ZAware = true;

                pLineGeoColl.AddGeometry(pGeometry, ref Missing, ref Missing);

                IFeature pFeature = pFeatureClass.CreateFeature();

                pFeature.Shape = pLineGeoColl as IGeometry;  //code crashes here: Geometry has no Z values
                pFeature.Store();

            }
        }
        pPolylineFeature.Delete();
    }
share|improve this question
    
At a minimum I think you need to set your pLineGeoColl to be ZAware. Probably give it a spatial reference as well. Not sure what else to try. –  blah238 Mar 12 '13 at 23:13
    
This old ESRI forum post has a slightly different approach but worth a look: forums.esri.com/Thread.asp?c=93&f=993&t=82601 –  blah238 Mar 12 '13 at 23:15
add comment

1 Answer 1

up vote 1 down vote accepted

This code works for me:

public void SplitPolylineFeature(IFeature pPolylineFeature, IPointCollection pSplitPointCollection, IFeatureClass pFeatureClass)
{
    //split the feature, each split makes a new part
    IEnumVertex pEnumVertex = pSplitPointCollection.EnumVertices;
    IPolycurve2 pPolyCurve = pPolylineFeature.Shape as IPolycurve2;
    IEnumSplitPoint pEnumSplitPoint = pPolyCurve.SplitAtPoints(pEnumVertex, true, true, -1);
    object Missing = Type.Missing;

    if(pEnumSplitPoint.SplitHappened)
    {
        //new geocoll for polycurve
        IGeometryCollection pGeometryCollection = pPolyCurve as IGeometryCollection;

        //loop through the parts of the split polyline
        for(int intPartCount = 0; intPartCount < pGeometryCollection.GeometryCount; intPartCount++)
        {
            IGeometryCollection pLineGeoColl = new PolylineClass();
            IZAware zAware1 = (IZAware)pLineGeoColl;
            zAware1.ZAware = true;

            IGeometry pGeometry = pGeometryCollection.get_Geometry(intPartCount);

            pLineGeoColl.AddGeometry(pGeometry, ref Missing, ref Missing);

            IFeature pFeature = pFeatureClass.CreateFeature();

            pFeature.Shape = pLineGeoColl as IGeometry;
            pFeature.Store();
        }
    }
    pPolylineFeature.Delete();
}

All I did was make pLineGeoColl ZAware.

share|improve this answer
    
Thank you very much - all so obvious but I still didn't spot it! –  Hubert Mar 13 '13 at 9:20
add comment

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.