PDA

View Full Version : Extract Data from Pushpin/Shaded Area Map



xonji
11-24-2011, 06:43 AM
Hi there, its me again :)

I searched for that problem here but didn't find anything usefull, I hope you can help me again. Maybe Im not very creative enough to get things work.

Problem:
I fill up my dataset with Data like Country, Zipcode, Salesamount a.so. this data comes from a SQL Select into a DataTable into a .csv .
For some reasons of useability, I call the datamapping wizard to let the User chose how to display the imported Data on the map. This works like a charm! But now when the Data is shown on the map, my Projectleader wants to interact with that Data - that means I want to "Click" or "Doubleclick" on for example a Pushpin or an area of a shaded area map, and receive from that object the information behind it (like Salesamount, Zipcode).

If I can catch the Information onClick, and save that information in, for example a datatable or a List, I'm able to work wih That Data on a Grid or pivot or something.

The Higher idea is to Interact with the single Objects on the map showing Data for "one" specialized object!

I hope someone could help me :) :sorcerer:

best regards
xonji

Eric Frost
11-24-2011, 08:22 AM
So it's not enough to just right-click and select "Show Information" and pop up the balloon? This is the way I would steer the the project manager. You don't have perfect, but you do have enough control over what appears in the balloon I would think. You can enough mock up little text charts in the balloon.

Otherwise, yes you can track the on-click event. When I do this with a COM Add-in for instance, I usually have a toggle so that the OnClick is Active or it can be Deactivated. Thus you don't lose any regular MapPoint functionality.

Eric

xonji
11-24-2011, 09:34 AM
Hey Eric!

Thanks to you reply!

No it's not enough to show the data in that BaloonState. My Task is to integrate Mappoint in a Solution for other Companys.

We need to get that information from the Baloonstate, so that we can use our own pivotgridcontrol to show the data which comes from the Pin.

so far i tryed something like this:


private void bt_suche_Click(object sender, RoutedEventArgs e)
{
Pushpin dummy = myControl.mapControl.ActiveMap.Selection as Pushpin;

string test = dummy.Name;

Location loc = myControl.mapControl.ActiveMap.XYToLocation(xCoord ,yCoord);

Recordset rs = dummy.Parent.QueryAllRecords();

foreach (Field fd in rs.Fields)
{
if (fd.Value == test)
{
Console.WriteLine(fd.Value);
}
i++;
}
}

But it doesnt work, cause the if-clause is never true. If I out-comment the if clause i get for every pushpin on the map the same information.

hope you can understand my problem.

b.r. xonji

xonji
11-25-2011, 03:48 AM
ok got it by myself :) here's the solution:




private void bt_suche_Click(object sender, RoutedEventArgs e)
{
Pushpin dummy = myControl.mapControl.ActiveMap.Selection as Pushpin;

string test = dummy.Name;

Recordset rs = dummy.Parent.QueryAllRecords();


int y = dummy.Parent.RecordCount;
rs.MoveFirst();
for (int x = 0; x < dummy.Parent.RecordCount;x++)
{
foreach (Field fd in rs.Fields)
{
if (fd.Value.ToString() == test)
{
MessageBox.Show(fd.Value.ToString());
Console.WriteLine(fd.Value);
break;
}
i++;
}
rs.MoveNext();
}
}



thx for the support I hope my Threads will help others as well.

Only thing is how to get information from a shaded area - if I found out I will post the solution here!

b.r. xonji

Eric Frost
11-25-2011, 05:02 AM
Good work and thanks for the follow up!

I don't know if this helps, but MapPoint will give a tooltip with the shaded area information if you hover over the shaded area..

Eric

xonji
11-25-2011, 06:04 AM
Yes, i know this was my last intention but i dont know how to get the tooltips information.

I cant select the shape or the part of the shape I want to extract the data from, so there is no pushpin on which I can call the Parent(Pushpinset).

maybe someone have an idea how to get the information from the tooltip hint?

b.r. xonji

Eric Frost
11-25-2011, 06:07 AM
Look into using ObjectFromPoint? You would have to sort through the information to match the geographic level of the shaded area. Then you would probably have to loop through the dataset to match the particular item and retrieve the data.

Eric

xonji
11-28-2011, 05:17 AM
You would have to sort through the information to match the geographic level of the shaded area.
Eric

Hey Eric thx for the reply,

I tried this but i didn't know how to get this work, do you have any examples how I can access the data from a shapearea with the ObjectsFromPoint() Method?

I use C# and the Mappoint 2011 COM Add-in.

b.r. xonji

Eric Frost
11-28-2011, 05:49 AM
It's a shape or one of the built-in geographies?

Eric

xonji
11-28-2011, 06:43 AM
It's a shape or one of the built-in geographies?

Eric

Hey Eric,

Its one of the build in, it appears when I choose the Shaded Area Option to display my Data on the maps surface.

b.r. xonji

Eric Frost
11-28-2011, 08:23 AM
Good. I've been planning to to a feature in an upcoming newsletter about using ObjectsFromPoint, but it will all be Excel VBA, not C#. Nonetheless, it should help. Let me see how this week goes and I'll plan on getting at least the ObjectsFromPoint part published by the end of this week.

Eric

xonji
11-29-2011, 07:43 AM
Ok! it would be nice if you could link this into this Thread :)

b.r. xonji

xonji
12-01-2011, 02:15 AM
Ok, i got it, now I'm able to catch the information from the dataset i want, when i click on the shaded area. Here my Code:




private void bt_suche_Click(object sender, RoutedEventArgs e)
{
int count = 0;
object index = null;
object indexT = 1;
List<MapPoint.Location> LocationList = new List<Location>();
Pushpin dummy = mapControl.ActiveMap.Selection as Pushpin;
dataSet = geoControl.getDataSetInfo();

FindResults results = mapControl.ActiveMap.ObjectsFromPoint(xCoord, yCoord);

for (int i = 0; i < results.Count; i++)
{
object id = i + 1;
Location loc = results.get_Item(ref id) as Location;

if (loc != null)
{
if (loc.Type == GeoShowDataBy.geoShowByRegion1)
continue;

double radius = 1;
bool notA = true;
object fieldindex = 1;
int countData = 1;

while (notA)
{
Recordset rec = dataSet.QueryCircle(loc, radius);

while (!rec.EOF)
{
foreach (var fd in rec.Fields)
{
fieldindex = countData;
MessageBox.Show("Info: " + rec.Fields.get_Item(ref fieldindex).Value.ToString()+"\n");
fieldindex = countData;
countData++;
}

notA = false;
i = results.Count + 1;
break;
}

if (radius > 50)
{
break;
}
else
{
radius += 5;
}
}
}
}


if (dummy != null)
{
int ires = results.Count;

string test = dummy.Name;
Recordset rs = dummy.Parent.QueryAllRecords();

rs.MoveFirst();
for (int x = 0; x < dummy.Parent.RecordCount; x++)
{
foreach (Field fd in rs.Fields)
{
if (fd.Value.ToString() == test)
{
MessageBox.Show(fd.Value.ToString() + "\nI'm from If");
Console.WriteLine(fd.Value);
break;
}
i++;
}
}
}
else
{
}
}



My next question is now:
My Solution only tracks the single data from the dataset, but the Mappoint routine captures that data shows it in a Region e.g. "Elsass" for France, and calculates the sum of all matches for that Region. The point is that I never give mappoint a Region Information only zipcodes, but it tracks those zipcodes and map them into a Region, these Information is shown in the tooltip if I navigate my Mouse over that region. How can I get that information from the tooltip?