Select to view content in your preferred language

Get the point along a curve

858
3
Jump to solution
09-27-2013 09:24 AM
ShaningYu
Honored Contributor
For a curve, I want to get the point at a distance from the curve's start point.  A piece of code is below:
            ICurve pCurve = (ICurve)feature.ShapeCopy;   // feature is a IFeature
            IPoint startPoint = pCurve.FromPoint;
            IPoint toPoint = pCurve.ToPoint;
            double distanceOnCurve = 0.4 * pCurve.Length;
            double offset = double.NaN;
            bool isRightSide = false;
            bool asRatio = false;
            pCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, startPoint, asRatio, toPoint,
                ref distanceOnCurve, ref offset, ref isRightSide);
But I don't know how the result be returned as a Point.  Appreciate in advance if you can provide a hint.
0 Kudos
1 Solution

Accepted Solutions
ShaningYu
Honored Contributor
The problem has been solved by the procedure below:
1)  Define a curve (or a line) and get its FromPoint (and ToPoint).
2)  Break the curve (or line) to multiple points, as returned as <List>IPoint.
3)  Loop the List, and calculate the distance between FromPoint to the point in the List.
4)  If the distance calculated is below the allowed value (e.g. 0.1 or 0.2, or even smaller), return the result as this point.
Thanks for your review my thread.

View solution in original post

0 Kudos
3 Replies
ShaningYu
Honored Contributor
The problem has been solved by the procedure below:
1)  Define a curve (or a line) and get its FromPoint (and ToPoint).
2)  Break the curve (or line) to multiple points, as returned as <List>IPoint.
3)  Loop the List, and calculate the distance between FromPoint to the point in the List.
4)  If the distance calculated is below the allowed value (e.g. 0.1 or 0.2, or even smaller), return the result as this point.
Thanks for your review my thread.
0 Kudos
HailiangShen
Deactivated User
Did you try the method QueryPoint in ICurve? That may also work
0 Kudos
RichardFairhurst
MVP Alum
For a curve, I want to get the point at a distance from the curve's start point.  A piece of code is below:
            ICurve pCurve = (ICurve)feature.ShapeCopy;   // feature is a IFeature
            IPoint startPoint = pCurve.FromPoint;
            IPoint toPoint = pCurve.ToPoint;
            double distanceOnCurve = 0.4 * pCurve.Length;
            double offset = double.NaN;
            bool isRightSide = false;
            bool asRatio = false;
            pCurve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, startPoint, asRatio, toPoint,
                ref distanceOnCurve, ref offset, ref isRightSide);
But I don't know how the result be returned as a Point.  Appreciate in advance if you can provide a hint.


I don't think this is the method you want to use.  ToPoint is the output point that is positioned along the line at the closest location to the input point (startPoint).  Since the input point is your from point of the line, that is where the output point will be.  The distanceOnCurve value you are specifying is ignored, since that is an output parameter and will return position 0 for the first point in the line every time.  This method is used to find the distance along the line of the input point, so if you had a point that was at 40% down the line, you could use this method to determine that is in fact where the point was located.

If what you really want is to create a point that is at a position 40% down the curve's length from the line's beginning then you need to use the GetPoint method.  This will create a point anywhere along the line or on the projection of the line's end points.  So you can actually ask for positions extending beyond the end points of the line in addition to points that actually fall on the line.  This method will create an output point at the 40% position along your line, based on a ratio of the line length or an actual distance measured along the line.  So a distance along of 0.4 with the ratio flag set to true is the same as a distance along of 0.4 * pCurve.Length when the ratio flag is set to false.
0 Kudos