C#: MapPoint 2004 - Check Regions

suamikim
12-12-2006, 03:59 AM
Hi,

i've created an C#-App which uses the MapPoint2004 ActiveX-Control to steadily show the GPS-Position of some vehicles connected to the software.

The next step would be the following, but i don't know, if, and especially, how i can achieve this:

The program should be able to check if the specified vehicle is located in a specified area. If the vehicle leaves this area (lets say a country or even a single city), the program should alert the user (respective it would be brilliant if it would be possible, that the program alerts the user, when the vehicle comes near a boundary of the specified area, but thats all still up in the air).

I know that it is possible to specify territories in MapPoint. Is it now possible to read them into my C#-App and check if a concrete GPS-Position is within or outside this territory/ies?

Hope, someone can help me!

thanks & regards

Wilfried
12-12-2006, 04:45 AM
Hi,

I never tried this. I think if you use FindaddressResults or FindPlaceResults for a location in a territory you get a collection of Location objects. Possible 1 of the location objects is having the Type property to 4 (Territory), and I assume the Name property is the name of the Territory.

Please feedback if it works that way. It will benefit others :)

suamikim
12-12-2006, 05:43 AM
Thanks for you answer, but i must concede, that i don't really get what you mean.

To use FindaddressResults or FindPlaceResults i need to know a concrete street, city, region, postal code or country to search for. The problem is, that i only have the GPS-Data of the vehicle and need to get the corresponding address (street, city, country, ... even country would be enough, but the more exact, the better it is).

Hope you know what i mean...

thks

ps.: I'm from austria, so my english isn't the best, therefor it could possible be, that i just didn't get what you meant, because of translation-problems ;)

Wilfried
12-12-2006, 09:44 AM
Hi,

Sorry you right. What if you try GetLocation ? It has a Name, PlaceCategory, Type property. Possible you can see which is the territory ?

suamikim
12-14-2006, 02:37 AM
Ok, this could work. I haven't tried it by now cause of little time.

If this works there would be another requirement:

The program should be able to read regions/territories which have been created in MapPoint (so the user can decide on his own, how many countries, states or even just cities he wants to allow).

Is it possible to read this so created files and check the positions of the vehicles?

I hope, i explained it in a understandable way!

Wilfried
12-14-2006, 01:27 PM
Hi,

I dont think you can create territories in mappoint. I think you only can import them. Please dont slap me if I'm wrong, I never tryed mutch in the standalone executable :)

Anyway if it is imported data then there is no problem because you can import it into your program as well.

suamikim
12-15-2006, 01:41 AM
I'm not gonna slap you, but i gotta tell you, that you're wrong ;)

You can do this the following way:

Data -> Territories/Regions (in German it's "Gebiete" and i don't exactly know, how it is called in the English version but i think it's territories cause the shortcut is Strg+T).
Next you have to choose "create manually" and the type of geographical unit (postal code, township, canton, state or country/region).

This way you can select some regions on the basis of the selected geographical unit.

E.g. i have created a region with 3 countries (Germany, Austria, France), which i can save either as a "MapPoint-Map (*.ptm)" or a Maptemplate (*.ptt)"):
http://www.ras-kas.net/Pics/mappoint_regions.jpg

Now i want to be able to read this so created region in my c#-App and check if a specific location (vehicle) is in it's boundaries.

thanks & regards

Wilfried
12-15-2006, 03:35 AM
Hi,

Thank you for pointing it out to me. I tryed it now :) I think it is time to try what has previously discussed to see if it works. I try it out as soon as I have a moment of time and give feedback. Please do the same.

suamikim
12-15-2006, 03:52 AM
Ok, i'm gonna give you a feedback, but i'm afraid that it won't be in the next days, cause theres a lot to do these days...

I just started the thread to get some information BEFORE i start implementing it ;)

Wilfried
12-15-2006, 07:57 AM
Hi,

I just tryed it myself. Could not get indication if location was in or out a territory :(

kaborka
12-20-2006, 06:12 PM
I too have the same problem. I need to have a C# program determine in which US State contains a specific location specified in latitude,longitude. Can this be determined from the results supplied by GetLocation?

This is my very first attempt to use MapPoint from a program, so I'm a total newbie. I have MP2006 however, not MP2004.

Wilfried
12-21-2006, 05:55 AM
Hi,

This can easy be done, this is example:

Location loc = MP.ActiveMap.GetLocation(lat, lon, alt);
FindResults StreetResults = MP.ActiveMap.ObjectsFromPoint(MP.ActiveMap.Locatio nToX(loc), MP.ActiveMap.LocationToY(loc));
foreach (object o in StreetResults) {
loc = o as Location;
if (loc != null && loc.StreetAddress != null)
Console.WriteLine("country: " + loc.StreetAddress.Country);
}

kaborka
12-21-2006, 12:34 PM
Thank you, Wilfried. I will try this ASAP. Actually it is the region name (State, for US) I am seeking, not the country name, but I will pursue this approach. Ideally, it would be great to be able to request a specific Location Type, eg. geoShowByRegion1 to get the US State name.

Would this work if the lat,long. is not near any street? I will be performing these calls using computed lat,long coordinates as part of a search to find the nearest region (State) boundary along a given path, by stepping along the path until the State name changes. (Unless there is an easier way to locate the distance to the border in a given direction.)

Wilfried
12-21-2006, 01:23 PM
Hi,

There is a Region property too. So if a US State is the same as a Region (in my language a State is not a region but more like a Country) then you probably can yous that property. Please feedback about this :)

As for you other question you go high altitude. 10 Miles or so even a little higher then you will have always StreetAddresses (with a larger delusion of precision) (you should always check for null value, if it is null ho higher).

kaborka
12-21-2006, 08:59 PM
Alas, I could not get this solution to work. I set MP.Units = 0 (miles) and called GetLocation(33, -118, 10) to obtain a point over Los Angeles, CA. None of the objects returned by FindResults had a nonempty Region value. It found a couple of highways (I-5 and US-395) and an object with Name = North America. It also returned an object with Name "San Diego", but its StreetAdress was null. I tried a lower altitude (1 mi), but that did not help.

Any suggestions?

Wilfried
12-22-2006, 06:33 AM
Hi,

and when StreetAddress is not null, then still both Region and Country are null ?

kaborka
12-22-2006, 11:30 AM
When StreeetAddress was not null, the Region property contained an empty string. I did not check the Country property. I'll do so when I get to work.

kaborka
12-22-2006, 01:18 PM
I found the problem. The approach does work. It turns out that my choice of coordinates was wrong. I rounded the coordinates of Los Angeles incorrectly. 33N,118W is in fact over the ocean! MP was unable to find any useful objects. When I used 34N,118W and confirmed by loc.Goto() this was in fact over the city, the algorithm worked perfectly.

I also checked to see what it returned when the loc was not in a city. I tried 34N,110W and saw this was over the desert in Arizona. Although MP found no location object with a nonnull StreetAddress, it did return a Location of Type geoShowByRegion1, whose Name property was "Arizona". It would seem I can alternatively determine the State by looking for a geoShowByRegion1 Location with a valid US State name.

I will now investigate the possibility of finding a more efficient means of locating the State boundary crossings along a great circle route, which is the actual problem at hand. At least it seems this iterative solution will work if I choose test locations along the route.

Thank you very much for your help with this!

Wilfried
12-23-2006, 06:34 AM
Hi,

Thank you for feedback. To check out I did some experiments, and it seems that the Location objects in the collection are included geoShowByRegion1, geoShowByRegion2, geoShowByCountry, geoShowByDefault ever, if I'm on a street, city, or not.

So I think in your case it is enough to check the type on geoShowByRegion1 and check the Name property.

Wilfried
12-23-2006, 06:43 AM
Hi,

Maybe this thread is also interesting for you:
http://www.mapforums.com/mappoint-functionality-5519.html#post15060

kaborka
12-24-2006, 12:06 PM
Thanks again, Wilfried. As it happened, I had found the State shape data on the Census site, but I did not know MP could import it. QueryShape sounds useful. If the iterative method is too slow I might try it.

PS: I sent you a PM, so check your inbox on this forum.

 
Web mp2kmag.com
mapforums.com