MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Polygonsearch with C#

This is a discussion on Polygonsearch with C# within the MapPoint 2006/2009 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...?...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
Polygonsearch with C#

Can anyone please help me with some C#-code on how to get a working polygon-search method...?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-14-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,105
Hi,

can you explain what you exacly means by "polygon-search method" ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 01-14-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-14-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,105
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 01-15-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 01-15-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,105
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 01-15-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 01-16-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,105
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,105
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();
            }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
polygonsearch


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 05:50 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Flight to Tenerife
Don't check in before you check out Holiday Hypermarket. Book a low cost flight to Tenerife and soak up some Canary Island sun.

Independent Travel Agent
Travel Counsellors is a completely Independent Travel Agent. Our travel agents are free to help with your travel plans.

Cuba Holiday
A Cuba Holiday has so much to offer with numerous different cultures affecting the sights, sounds and tastes. Visit this fascinating country with dealchecker.co.uk.

Holidays to Mauritius
Visit the paradise island in your holidays to Mauritius. Enjoy the friendliness of the locals, the warm of the sun and the beauty of the views!

Cyprus
Before visiting Cyprus, make sure you are well informed to make the most of your holiday. Online at ulookubook.com you check out our useful travel guides. Find out all about the Cyprus nightlife, shopping, eating and customs.

Travel Deals
Find the very best travel deals on your prime comparison site, Travel.co.uk

Holidays to Florida
Sun and sea! Get info on holidays to Florida, only at On The Beach.


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