Dazzer
04-25-2006, 06:22 AM
I'm drawing shapes in mappoint and the saving the coordinates (lat\lon) to a file.
I then have another program that needs to be able to read these files in and plot the shape on a VB .net form using GDI+ (Not mappoint)
The problem i'm having is converting these lat lon coordinates into x y pixel coordinates.
Does anyone have any ideas? The shape needs to re-size with the form.
manav
04-25-2006, 06:42 AM
Hi
There is a way to convert the lat long to the xy coordinates.
Once you converted your lat longs to xy then you can easily redraw then again
The method for converting the is present in render services of mappoint
RenderService.ConvertToPoint()
This method takes few arguments as below :
1. waypoint of the map generated
2. view array of the map
3. your picture box's width
4. your picture box's height
now with there values you can get the x y coordinates. this is help ful as when the picture box size is changes then it takes the fresh height and width
Regards
Manav
Winwaed
04-25-2006, 07:09 AM
It sounds like Manav's answer is for the MapPoint Web Service, but this is forum is mainly for Desktop MapPoint.
You need to create a Location object from the longitude,latitude coords and then use the LocationToX() and LocationToY() methods. See the MapPoint documentation for full details, but here's the example from the help file:
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objLocNY As MapPoint.Location
Dim objLocLA As MapPoint.Location
Dim objCenter As MapPoint.Location
Dim objTextbox As MapPoint.Shape
'Set up application and create Location objects
Let objApp.Visible = True
Let objApp.UserControl = True
Set objMap = objApp.ActiveMap
Set objLocNY = objMap.FindResults("New York, NY").Item(1)
Set objLocLA = objMap.FindResults("Los Angeles, CA").Item(1)
'Find the point on the screen midway between the two
X1% = objMap.LocationToX(objLocNY)
Y1% = objMap.LocationToY(objLocNY)
X2% = objMap.LocationToX(objLocLA)
Y2% = objMap.LocationToY(objLocLA)
Richard
Dazzer
04-25-2006, 09:18 AM
Yeah thats not really what I'm trying to.
I have an app that uses mappoint, the user draws a shape and submits that shape to a database, the shape is stored as a set of lat lon coordinates.
I have a second app that doesn't use mappoint (and cant) on which I need to plot the shape on a windows form using GDI. The difficulty I'm having is plotting the lat lon coordinates using GDI points.
The question I was asking was how do I convert these Lat lon coordinates into Pixel X Y coordinates without using mappoint.
In summary I need to convert a set of lat lon coordinates into Pixel X Y coordinates to plot a shape on a windows form (or possibly change the scale on the form using GDI however being a GDI novice i;m unsure of how to do this either)
Thanks for your help
Winwaed
04-25-2006, 10:04 AM
You need to read about map projections. This is a huge subject unto itself, and there are books dedicated to the subject.
The good news is that you can do it with "a bit of maths".
A simplistic projection would be to simply use a linear mapping from longitude,latitude to x,y (eg. x=Longitude+180); y=90-Latitude). This will seriously distort the poles, but gives you an idea of a simple approach. There are literally hundreds of different map projections according to your specific needs.
Richard
Dazzer
04-25-2006, 10:07 AM
Thanks for your help, I can see i'm going to have to look into this a bit deeper!
Winwaed
04-25-2006, 03:22 PM
"Transverse Mercator" is probably a good start.
I'm sorry I can't be of much help beyond this, but it should help in your web and book searches. Many years ago, I did work with esoteric map projections but these were intended for specialist projections of angular data (equal-angle projections for crystallography, and equal-area projections for structural geology).
I remember at high school we'd often use an equal area map because relative land areas remained the same. Despite this the map looked distorted - eg. Africa was large, and Northern Europe (and Canada) were squashed.
Richard
Dazzer
04-26-2006, 05:49 AM
Thanks for all your help,
I've got a good grounding now for my research, I didn't think there would be a simple answer (although I hoped there would!), thanks for pointing me in the right direction.
Fabio
04-26-2006, 10:07 AM
Maybe another simple solution is to hold on the database not only lat & long but also corresponding X & Y on the map.
Is it right?
Dazzer
04-27-2006, 10:09 AM
Fabio,
I agree some sort of variation on your suggestion would have been the best way (Convert Lat Lon to xy when drawing the shape and store that, then use that to scale the shape to the size of the form)
However the data already exists, there are hundreds of thousands of these shapes so to try to re-plot and resubmit would probably more work than attempted a programatic conversion.
Incidently after some of the suggestions found here I'm actually quite close to a solution, thanks again for your help.