splitting zAware polylines

545
1
Jump to solution
03-12-2013 02:18 AM
HubertBast
New Contributor II
Hi All,

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();                     try                     {                         pFeature.Shape = pLineGeoColl as IGeometry;  //code crashes here: Geometry has no Z values                         pFeature.Store();                     }                     catch (Exception ex)                     {                         MessageBox.Show("Error in WillisPolylines.SplitPolylineFeature: " + ex.Message);                     }                                     }             }             pPolylineFeature.Delete();         }
0 Kudos
1 Solution

Accepted Solutions
HubertBast
New Contributor II
Solution:
Simply set the pLineGeoColl as zAware - that's the whole trick!
IGeometryCollection pLineGeoColl = new PolylineClass(); IZAware zAware1 = (IZAware)pLineGeoColl; zAware1.ZAware = true;  IGeometry pGeometry = pGeometryCollection.get_Geometry(intPartCount);  pLineGeoColl.AddGeometry(pGeometry, ref Missing, ref Missing);


Many Thanks to those looking at it!

View solution in original post

0 Kudos
1 Reply
HubertBast
New Contributor II
Solution:
Simply set the pLineGeoColl as zAware - that's the whole trick!
IGeometryCollection pLineGeoColl = new PolylineClass(); IZAware zAware1 = (IZAware)pLineGeoColl; zAware1.ZAware = true;  IGeometry pGeometry = pGeometryCollection.get_Geometry(intPartCount);  pLineGeoColl.AddGeometry(pGeometry, ref Missing, ref Missing);


Many Thanks to those looking at it!
0 Kudos