Can anyone please help me with some C#-code on how to get a working polygon-search method...?
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...?...
Can anyone please help me with some C#-code on how to get a working polygon-search method...?
Hi,
can you explain what you exacly means by "polygon-search method" ?
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
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.
Hi,
Yu have to make triangles from out of the polygon (not a real problme of course but not coded in 5 minutesthen check them each out invidually.
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
I found this code in VB.NET. It should do the trick.
I, however, can't figure out which dataset I should use when I translate this line into C#: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
Is there a way to find out which datasets I can choose from?Code:objDataSet = Karta.ActiveMap.DataSets("sbg031_2003")
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.
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
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?
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:
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 namingCode: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();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.
And look hereCode: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(); }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.
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
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:
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:MapPoint.DataSets ds = MP.ActiveMap.DataSets; foreach (MapPoint.DataSet d in ds) Console.WriteLine(d.Name);
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:o = "My Pushpins"; rs = MP.ActiveMap.DataSets.get_Item(ref o).QueryShape(s); rs.MoveFirst(); while (!rs.EOF) { rs.MoveNext(); }
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(); }
rgds, Wilfried Mestdagh
www.mestdagh.biz
www.comfortsoftware.be
www.expertsoftware.be
MapPoint coding demo
MapPoint 2011 available, buy now
There are currently 1 users browsing this thread. (0 members and 1 guests)