LocationRectangle.IntersectWithLine does not work as expected

2 posts, 0 answers
  1. dilsah
    dilsah avatar
    8 posts
    Member since:
    Dec 2010

    Posted 17 Oct 2012 Link to this post

    I have a collection of mapshapes which mostly consists of mappolygons. I want to draw lines on the map only if the line does not intersect with another shape. For this purpose i am using the "IntersectWithLine" but when the line comes near the shape, even if they do not intersect the result is always true. Below is the code:

            Location point = somevalue;
            Location point1 = somevalue1;


                foreach (var item in myLayer.Items)
                {
                    LocationRect rect = (item as MapShape).GeographicalBounds;
                    if (rect.IntersectWithLine(point, point1))
                    {
        //change the color of the shape that intersects with the line
                        (item as MapShape).Fill = new SolidColorBrush(Colors.Black);
                    }
                }

    What am i doing wrong?? Can you provide me a sample project? 
    Thanks
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 22 Oct 2012 Link to this post

    Hello Dilsah,

    Unfortunately you can't use this approach to detect intersection of line and arbitrary map shape. The IntersectWithLine is the method of the location rectangle. When you call it you check whether the given line intersects with bounding rectangle (not with the original shape). The original shape can occupy just a small part of the bounding rectangle.

    Calculation of the intersection of the line with arbitrary shape (even with arbitrary polygon) is a quite complex geometrical task for which we have not ready for use solution. However I suggest that you search for this in stackoverflow for example, where I believe you'll find the answer.

    Regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top