Find points inside polygon

4 posts, 1 answers
  1. Esther
    Esther avatar
    13 posts
    Member since:
    Jun 2010

    Posted 24 Jan 2011 Link to this post

    Hello,
    I´ve a RadMap with several MapPinPoints on it. After drawing an ellipse I want to know how many point are inside this ellipse.
    ¿Which is the easiest way of doing that?
    Thanks in advance,
    Esther
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 26 Jan 2011 Link to this post

    Hi Esther,

    If ellipse is a map shape object (MapEllipse) which is visible over the map, then you can use following method to detect whether specified location is inside the shape:

    private bool IsLocationInShape(MapShape shapeToTest, Location location)
    {
        bool isInShape = false;
      
        IEnumerable<object> list = this.InformationLayer.GetItemsInLocation(location);
        foreach (object item in list)
        {
            MapShape shape = item as MapShape;
            if (shape != null && shape == shapeToTest)
            {
                isInShape = true;
                break;
            }
        }
      
        return isInShape;
    }

    Then you can loop through the list of the objects and use this method to detect whether the object location is inside the specified shape.

    Kind regards,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Esther
    Esther avatar
    13 posts
    Member since:
    Jun 2010

    Posted 26 Jan 2011 Link to this post

    Thanks for the reply.
    The problem that I have now is that when I get the list of elements of the information layer, they are MapPinPoints and it fails when I do the cast to MapShape. TryCast returns Nothing. This is my code:

    Private Function pr__IsLocationInShape(ByVal shapeToTest As MapShape, ByVal location As Location) As Boolean
           Dim isInShape As Boolean = False
           Try
               Dim list As IEnumerable(Of Object) = Me.m_c_marker_layer.GetItemsInLocation(location)
     
          
               For Each item As Object In list
                   Dim shape As MapShape = TryCast(item, MapShape)
                   If shape IsNot Nothing AndAlso shape.Equals(shapeToTest) Then
                       isInShape = True
                       Exit For
                   End If
               Next
     
               Return isInShape
     
           Catch ex As Exception
     
               Return False
           End Try
       End Function
  5. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 31 Jan 2011 Link to this post

    Hello Esther,

    It is the expected behavior. My C# and your VB.NET code looks for the MapShape object in the information layer. The information layer can contain objects of different types. If item from the layer can be casted to the MapShape the result will not be Nothing (null in C#) and we will be able to compare it with given map shape. Otherwise we just check next item.

    As I've mentioned alredy the map shape object (MapEllipse) must be visible over the map. If you use 2 layers (one for pin points and second for ellipse), then you should call GetItemsInLocation method for the layer which contains MapEllipse (or other shape).

    All the best,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top