1

I am attempting to split the geometry of a line feature for further manipulation, without modifying the feature itself. I am using an IPointCollection, consisting of points that intersect the line, to split the line, where I can find the midpoint of these line segments. My code:

IFeature m_feature = some polyline feature;
IFeatureClass pointFeatureClass = some point feature class;
// storage for point geometry
IGeometry multipoint = new Multipoint() as IGeometry;
multipoint.SpatialReference = m_feature.Shape.SpatialReference;
IPointCollection intersectingPoints = (IPointCollection)multipoint;
// get intersecting points
sFilter.Geometry = (IGeometry)m_feature.Shape;
sFilter.GeometryField = pointFeatureClass.ShapeFieldName;
sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor pCursor = pointFeatureClass.Search(sFilter, false);
IFeature thisFeature;
object Missing = Type.Missing;
while ((thisFeature = pCursor.NextFeature()) != null)
{
 IPoint pnt = thisFeature.Shape as IPoint;
 pnt.SpatialReference = thisFeature.Shape.SpatialReference;
 intersectingPoints.AddPoint(pnt, ref Missing, ref Missing);
}
MessageBox.Show(intersectingPoints.PointCount.ToString()); // returns correct number (i.e. greater than 1)
// split m_feature polyline at intersecting points into individual polyline objects
IPolycurve2 polyCurve = (IPolycurve2)m_feature.Shape;
IEnumVertex splitPoints = intersectingPoints.EnumVertices;
IEnumSplitPoint enumSplitPoint = polyCurve.SplitAtPoints(splitPoints, true, true, -1);
// check if split occurred
if (enumSplitPoint.SplitHappened)
{
 MessageBox.Show("Split Happened") // always shows as split
}
// new geoCol for polycurve
IGeometryCollection geoColl = (IGeometryCollection)polyCurve;
MessageBox.Show(geoColl.GeometryCount.ToString()); // prints 1 as if split didn't occur

Referencing Splitting zAware polyline by points using ArcObjects with C#? and GeoNet.

What am I doing that might be causing the polycurve object to not be split? Or is there a better way to accomplish what I am doing?

asked Mar 8, 2017 at 21:17
2
  • You're adding the points to intersectingVOPs but splitting using points in intersectingPoints. You shouldn't need to set pnt.SpatialReference = thisFeature.Shape.SpatialReference; but that's neither here nor there.. finding points (assuming sFilter is ISpatialFilter) with a line is bound to be hit and miss, try buffering by a little bit. Is this splitting any lines? Is your m_feature returned from a non-recycling cursor? Are the spatial references the same? i.e. you might need to pnt.Project(m_feature.Shape.SpatialReference) to ensure they're compatible. Commented Mar 8, 2017 at 21:51
  • @MichaelMiles-Stimson Thanks for taking the blinders off of me. See my comment in the answer below. Commented Mar 9, 2017 at 4:47

1 Answer 1

2

Just thinking out aloud. So all the action occurs here:

IEnumSplitPoint enumSplitPoint = polyCurve.SplitAtPoints(splitPoints, true, true, -1)
  • Your cut off distance is -1. Not sure that should be negative? The API help for this method on this interface does not say anything about negative numbers, may be try a positive value?
  • You have set the parameter createParts to TRUE. May be your count which is returning 1 is returning a count of 1 polyline but its actually a multi-part shape, each part being the line segment you wanted?
answered Mar 8, 2017 at 21:32
1
  • 1
    In the examples I linked in my question, I had seen the cutoffdistance = -1. I had assumed that this would not grab any points off of the line. I had tried 0.0, which resulted in the enumSplitPoint.SplitHappened = False, so i had wrongly assumed that the -1 was working. Being in a GCS, i was hesitant to use any large positive cutoffdistance, but as MichaelMiles-Stimson pointed out, since i used a spatial query to build my pointcollection, the intersecting points will be hit or miss. However, a cutOffDistance of 0.1 did the trick. Thanks Commented Mar 9, 2017 at 4:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.