Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 9 of 9

Polygonsearch with C#

This is a discussion on Polygonsearch with C# within the MapPoint Desktop Discussion forums, part of the Map Forums category; Can anyone please help me with some C#-code on how to get a working polygon-search method...?...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Polygonsearch with C#

    Can anyone please help me with some C#-code on how to get a working polygon-search method...?

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    can you explain what you exacly means by "polygon-search method" ?

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    I want to draw a polygon on the map with the freeform tool. The metod should for instance return all the pushpins in the area that the polygon encloses.

    I want to be able to do a search within the polygon only, not the whole map.

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    Yu have to make triangles from out of the polygon (not a real problme of course but not coded in 5 minutes then check them each out invidually.

  5. #5
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    I found this code in VB.NET. It should do the trick.

    Code:
    Dim a As MapPoint.Shape
    Dim objDataSet As MapPoint.DataSet
    Dim objRecordset As MapPoint.Recordset
    ListBoxValdaKunder.Items.Clear()
    If Karta.ActiveMap.Shapes.Count > 0 Then
      objDataSet = Karta.ActiveMap.DataSets("sbg031_2003")
      Cursor.Current = Cursors.WaitCursor
      a = Karta.ActiveMap.Shapes(Karta.ActiveMap.Shapes.Count)
      objRecordset = objDataSet.QueryShape(a)
      If objRecordset.EOF = False Then
        Do Until objRecordset.EOF
          ListBoxValdaKunder.Items.Add(objRecordset.Pushpin.Name)
          objRecordset.MoveNext()
        Loop
      End If
    End If
    I, however, can't figure out which dataset I should use when I translate this line into C#:
    Code:
    objDataSet = Karta.ActiveMap.DataSets("sbg031_2003")
    Is there a way to find out which datasets I can choose from?

  6. #6
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    QueryShape returns all records within a shape (learned again something new). So when you add the pushpins to the map you add them as whell into a dataset. And itis _that_ dataset you have to use.

  7. #7
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    So what is the default dataset? I haven't declared nor named any dataset in my application, and I'm still able to add pushpins to the map... so there must be som kind of default dataset?

  8. #8
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    I had a moment of free time so I did a little experiment, as I did not knew the answer for your problem eather. It seems that pushpins are always added to a "default" dataset. I assume it is always the first one in the collection. This is what I tryed:

    Code:
                uint Count = 10;
                Location Loc;
                Pushpin PP;
                Double Lat = 50;
                Double Lon = -3;
                Double Alt = 1000;
    
                while (Count-- > 0) {
                    Lon += 0.5;
                    Loc  = MP.ActiveMap.GetLocation(Lat, Lon, Alt);
                    PP   = MP.ActiveMap.AddPushpin(Loc, "Kieken");
                    PP.Symbol = 1;
                }
                MP.ActiveMap.DataSets.ZoomTo();
    The ZoomTo works here ! This proves there is a dataset of the Pushpins. If there is one then we can access it. ps: dont mind the puspin's name, I always do silly things naming Lest just try something stupid and see where we coming. We draw a circle, select it ans see if we can get a recordset out of a dataset.

    Code:
                Loc = MP.ActiveMap.GetLocation(Lat, Lon, Alt);
                Shape s = MP.ActiveMap.Shapes.AddShape(GeoAutoShapeType.geoShapeRadius, Loc, 100, 100);
                s.Line.Weight = 0;
                s.Select();
                object o = 1;
                Recordset rs = MP.ActiveMap.DataSets.get_Item(ref o).QueryShape(s);
                rs.MoveFirst();
                while (!rs.EOF) {
                    Console.WriteLine(rs.Pushpin.Name.ToString());
                    rs.MoveNext();
                }
    And look here only the records in the shape are returned. I think this is what you need Note that the first dataset is 1 and not 0 in the index. This is with Mappoint whole time, it start indexing at 1.

  9. #9
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    I did a litte additional research and tought to put it here as it can benefit you and others.

    First of all this dataset where pushpins are added has the name 'My Pushpins". I found this like this:

    Code:
                MapPoint.DataSets ds = MP.ActiveMap.DataSets;
                foreach (MapPoint.DataSet d in ds)
                    Console.WriteLine(d.Name);
    This means that you can access the selected pushpins by dataset name. Maybee it is also safer ? Or is index 1 always the 'My Pushpins" dataset ? Should be nice if someone canclarify this. Anyway as this you access it by name:

    Code:
                o = "My Pushpins";
                rs = MP.ActiveMap.DataSets.get_Item(ref o).QueryShape(s);
                rs.MoveFirst();
                while (!rs.EOF) {
                    rs.MoveNext();
                }
    You can also create a new dataset and move the selected pushpins in it, like this. Note that they are deleted form the old dataset.

    Code:
                MapPoint.DataSet InCircle = MP.ActiveMap.DataSets.AddPushpinSet("In circle");
                rs.MoveFirst();
                while (!rs.EOF) {
                    rs.Pushpin.MoveTo(InCircle);
                    rs.MoveNext();
                }
                o = "In circle";
                rs = MP.ActiveMap.DataSets.get_Item(ref o).QueryShape(s);
                rs.MoveFirst();
                while (!rs.EOF) {
                    rs.MoveNext();
                }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96