Insert new Point to PointCollection

1986
5
Jump to solution
07-11-2013 01:42 AM
CarstenSchumann
Occasional Contributor

Hey folks around,

when trying to update a features geometry by inserting a new point (using the IPointCollection-Interface) I run through an System.Runtime.InteropServices.SEHException which I can´t interpret in any way. But all posts concerning this topic simply add a new Point at the end of the geometry, but never in the middle or at the beginning.

My current code is the following:

// the candidate to add to the result-list ICurve candidate = new PathClass();   
IPointCollection curvePoints = (IPointCollection) candidate; 
// add the new point at the beginning of the geometry 
object before = curvePoints.get_Point(0); 
object after = Type.Missing; 
curvePoints.AddPoint(fromPoint, ref before, ref after);

Does anyone around know where the error is?

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
I found this bit of C code on the ESRI website, midPoints is a IPointCollection pointer

object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing);

View solution in original post

0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor
Carsten,

I'm guessing the error is occurring because your candidate is pointing to a path class which is a sequence of connected segments, try a polyline class?

Duncan
0 Kudos
CarstenSchumann
Occasional Contributor
Makes no difference, the same error occures.

What I don´t understand is that adding the point without any information on the position (just use PointCollection.Addpoint(IPoint)) works as it should, but with arguments I get the mentioned error...
0 Kudos
DuncanHornby
MVP Notable Contributor
I found this bit of C code on the ESRI website, midPoints is a IPointCollection pointer

object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing);
0 Kudos
CarstenSchumann
Occasional Contributor
Ok, I tried it out and the error disappeared. Does this mean the object you´re using is rather the actual point but the index of this point casted as an object? Then the method is quite confusing as simply using integers for the indexes would simplify it...

However, it works.
Thanks for the help

The following finally works:
ICurve candidate = new PathClass();      // the candidate to add to the result-list
IPointCollection curvePoints = (IPointCollection) candidate;
// ...
// add some points to the collection
// ...
// add the point at the beginning of the geometry
object before = (object) 0; // rather then curvePoints.get_Point(0); we could also use (object) 3 or whatever index we need
object after = Type.Missing;
curvePoints.AddPoint(fromPoint, ref before, ref after);
0 Kudos
DuncanHornby
MVP Notable Contributor
Accessing the point collection using an index makes a lot of sense to me but I totally agree the Help for this method is about as clear as mud. ESRI need to improve this with proper examples.
0 Kudos