Determining the projection in a given map
I realise this is potentially not a programming question, however its a problem I keep bumping into as a programmer, so I figure others here might have useful knowledge to share.
I have a map of a region of th开发者_如何学运维e earth (it could be any, but here's an example) how should I determine the projection used in the map and then how should I programatically transform latitude and longitude coordinates into pixel positions on the image.
At the moment I have matlab code to open the image and plot the resulting (x,y) coord, but I can't figure out how to convert lat/longs to x,y!
Any help at all would be greatly appreciated.
Geographic coordinates are a variation of spherical coordinates. You can transform them to normal coordinates:
x = r * sin(90 - lat) * cos(lon)
y = r * sin(90 - lat) * sin(lon)
z = r * cos(90 - lat)
This is not really accurate because Earth is not exactly a sphere. Depending on the type of the map there are several ways to obtain 2D coordinates from these. The image may be projected from the sphere to a cylinder or two planes.
These links might help:
- http://en.wikipedia.org/wiki/Geographic_coordinate_system
- http://en.wikipedia.org/wiki/Map_projection
- http://en.wikipedia.org/wiki/Spherical_coordinates
It turns out that programatically calculating the projection of a map is a complex task of image processing. The way I managed to get around this problem is simply using maps that have well defined projections - for example Google maps use the Mercator projection, as do most maps of the UK (as our British Reference Grid is based on the Universal Transverse Mercator).
I hope this helps someone else out!
精彩评论