Select to view content in your preferred language

Portion of the polyline geometry

725
3
09-09-2011 07:16 AM
Sravan_KumarUddarraju
Emerging Contributor
Hi,

I am looking for work around to get the sub-curve from the polyline using Silverlight API. I have polyline feature and I need to get the portion of the polyline from start point (from-point of the line) to the user click point on the feature.

Thanks in advance.
Srav
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
Looks related to the search of the point of a polyline which is the closest of the clicked point : http://forums.arcgis.com/threads/33168-Polyline-Nearest-point?p=132773#post132773.

Once you get this point, it's easy to build a polyline having this point as end point.
0 Kudos
Sravan_KumarUddarraju
Emerging Contributor
Thanks for the help on this.
I created two functions to solve my problem.  There might be an easy way, but these functions solved my purpose.

FindNearestPointOntheSegment: To find the nearest point on the segment.


private Point FindNearestPointOntheSegment(Point pt1, Point pt2, Point pt)
        {

            double m = (double)(pt2.Y - pt1.Y) / (pt2.X - pt1.X); //slope
            double c = (double)pt1.Y - (m * pt1.X); //intercept

            //Get nearest point on the line
            //ttp://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html"

            double x = (m * pt.Y + pt.X - m * c) / (m * m + 1);
            double y = (m * m * pt.Y + m * pt.X + c) / (m * m + 1);

            return new Point(x, y);
        }

//IsPointOnSegment: To find, is the projected point on the segment or not.


        private bool IsPointOnSegment(Point pt1, Point pt2, Point pt)
        {
            //y= mx+c
            //ttp://www.softwareandfinance.com/Turbo_C/Check_Point_Lies_line_Segment.html
            double m = (pt2.Y-pt1.Y) / (pt2.X-pt1.X); //Slope

            double c = pt1.Y - (m * pt1.X); //intercept

            //Create bounding box
            double left;
            double right;
            double top;
            double bottom;
            if (pt1.X < pt2.X) { left = pt1.X; right = pt2.X;}
            else{left = pt2.X;right = pt1.X;}
           
            if (pt1.Y < pt2.Y){top = pt1.Y;bottom = pt2.Y;}
            else{top = pt2.Y;bottom = pt1.Y;}

            // Checking if pt is on the line passing through the end points.

            if (((m * pt.X + c) > (pt.Y - 0.001)) && ((m * pt.X + c) < (pt.Y + 0.001)))
            {
                if ((pt.X >= left && pt.X <= right) && pt.Y >= top && pt.Y < bottom)
                    return true;
                else
                    return false;
            }
            else
            {
                return false;  
            }

        }
0 Kudos
GaryBushek
Deactivated User
This sounds similar to what I need to do.  I have 2 points that were obtained from intersecting street 2 with street 1 and then street 3 with street 1.  Now I want to get the segment of street 1 that falls between those 2 points.  Is there an easy way to do this in the silverlight API?  I don't think I need a bunch of coding help but just some good ideas on which direction to go; whether there are geometry service utilities in the API to handle this or if there are toolbox tools I should be utilizing within a custom geoprocessing service. Any guidance is greatly appreciated.  The old code for this process was written in 9.1 ADF/ArcObjects using IPath.QueryPointAndDistance() and IPath.GetSubCurve() and somehow I need to accomplish the same thing in the Silverlight API.

Thanks, Gary
0 Kudos