Hi, j_philipp-ga:
I analyzed the map.gif image which you posted by combining the few
"country borders" that happen to coincide with lines of longitude or
parallels of latitude with some other reasonably easily identifiable
features, like the mouth of the Amazon or Cape Horn. In addition to
searching out Web pages that give geograhic coordinates for such
things, I had the use of a compact world atlas published in 1949 in
Great Britain:
The Handy Reference Atlas, edited by John Bartholomew (15th ed., Edinburgh)
Before delving into the arcana of geographic coordinates, however,
it's probably a good idea to begin with a refresher on the pixel
coordinates of a GIF image. After saving the cited map.gif to my
local hard disk, I used Microsoft's HTML Help Image Editor (v. 4.73)
to examine its details. Of course many other programs would serve
this purpose equally well.
The image is 896 by 576 (width times height), and as explained in this tutorial:
[Manual Clickable Image Maps]
http://staff.washington.edu/larryg/Classes/R561/zz-click-man.html
"Note that pixel values always start at 0,0 in the upper left corner
and get larger as you move down and to the right."
Thus our pixel coordinates will range from 0 to 895 in the horizontal
"X" direction (left to right) and from 0 to 575 in the vertical "Y"
direction (top to bottom).
I'll assume a basic familiarity with the conventions of longitude and
latitude; at bottom are a couple of links to earlier Google Answers
threads where I've dealt with these to some extent.
Per our earlier exchanges of Comments and Clarifications, the
longitude and latitude angles are going to be provided in degrees.
This would pass without mention except that mathematicians and
numerical programmers prefer to work with angles measure in radians,
for more or less the same reason that we'd pick "natural" logarithms
over the common ones. However in using a pidgeon-Excel formulation of
the algorithms, I think the context of degrees versus radians will be
clear.
After the horizontal (longitude) coordinates were modelled rather
easily (linearly in pixel's X, as expected), the vertical (latitude)
coordinates proved somewhat challenging. Fortunately the Google
Search Engine is our friend, and the following page tells us pretty
much everything we need to know:
[Mercator Conformal Projection]
http://www.ualberta.ca/~norris/navigation/Mercator.html
"The Mercator Projection is named after its inventor: Gerhard Kremer,
a Flemish cartographer who lived from 1512 to 1594. (Gerhardus
Mercator was the latinized form of his name)."
"He published the first map using this projection in 1569, but the
projection did not become popular until 30 years later (1599), when
Edward Wright published an explanation of it."
Here are the formulas given there for a perfect sphere, in a slightly
modified form convenient to our needs. For points in the northern
hemisphere:
L = angle of longitude in radians (east = positive)
A = angle of latitude in radians (north = positive)
E = distance east
N = distance north
we have:
E = r L
N = r ln( tan( (A + pi/2)/2 )
where r represents a distance (namely the radius of the sphere "to
scale"). Note that angles here are measured by radians, which are
"pure" numbers, lacking any identifying units of measurement. The
angle pi/2 in radians is equal to 90 degrees.
In the southern hemisphere we use essentially the same formulas, but A
is replaced by |A| and the sign of N (distance north) switches to
negative:
N = -r ln( tan( (|A| + pi/2)/2 )
Finally the distance coordinates E and N are "affinely" related to
pixel coordinates:
X = horizontal gif coordinate in pixels (right = positive)
Y = vertical gif coordinate in pixels (down = positive)
This is a fancy way of saying that X,Y are first degree polynomials in
E,N. In fact for some constant coefficients a,b,c,d:
X = a E + b
Y = c N + d
where c < 0 in order to obtain the reversed direction of the vertical
coordinate (latitude increases from bottom to top, but the Y
coordinate decreases in that direction).
By a least squares fitting of one dozen "measured" points of latitude
and ten points of longitude, I arrived at these rounded
approximations:
DEGREES( L ) = (X - 430.25)/2.4
A = SIGN(395.5 - Y)*[2*ATAN(EXP(ABS(395.5 - Y)/137)) - PI/2]
Here L and A are in radians, but Excel provides a function DEGREES( )
that converts to the familiar units (as well as a function RADIANS( )
to go the other way).
In fact the formulas above are pretty much the ones I worked with in
Excel, except for the necessity of cell references and the fact that
PI must become the constant (nullary) function PI().
* * * * * * * * * * * * * * * * * * * * * * * * * *
A Sample Grid
=============
The mapping above puts:
the Prime Meridian along X = 430.25, and
the Equator at Y = 395.5.
For the sake of illustration, let's begin with a single rectangle of
size 89 x 55 that is roughly centered on that point.
Bearing in mind that pixels are "fence posts", if we have N pixels in
a line (horizontal or vertical), then the difference in the
coordinates of the endpoints is N-1. Two adjacent pixels would have a
difference of 1, for example.
So if we took the left and right extremes of this first rectangle to be:
X0 = 430 - 44 = 386
X1 = 430 + 44 = 474
and if we took the top and bottom extremes to be:
Y0 = 396 - 27 = 369
Y1 = 396 + 27 = 423
then the "center" of the rectangle would be X=430,Y=396. [If one
prefers to hit Y = 395.5, then a rectangle of even height would be
required.]
It is a nice feature that longitude L depends only on X, and latitude
A only on Y. In the present circumstance:
DEGREES( L ) = (430 - 430.25)/2.4 = -0.25/2.4 ~ -0.1
A = SIGN(395.5 - 396)*[2*ATAN(EXP(ABS(395.5 - 396)/137)) - PI/2]
= - [ 2*ATAN( EXP( 0.5/137 ) ) - PI/2 ] ~ -0.00365 in radians
DEGREES( A ) ~ -0.2
Here the negativeness of L means we're slightly West of the Prime
Meridian, and the negativeness of A that we are slightly South of the
Equator.
The corresponding tabulation you requested would be:
X0, Y0, X1, Y1, A , L
-------------------------
386,369,474,423,-0.2,-0.1
where I've rounded the angles to the nearest tenth of a degree.
In fact we can readily work out the horizontal and vertical intervals
of our grid separately, adding or subtracting 89 to the pairs of X
coordinates until we reach the map's edges, and likewise adding or
subtracting 55 to the pairs of Y coordinates:
X0, X1,DEG(L) Y0, Y1,DEG(A)
-------------- --------------
0, 29,-173.2 0, 38, 82.7
30,118,-148.4 39, 93, 79.7
119,207,-111.4 94,148, 74.6
208,296, -74.3 149,203, 67.2
297,385, -37.2 204,258, 56.5
386,474, -0.1 259,313, 41.6
475,563, 37.0 314,368, 22.2
564,652, 74.1 369,423, -0.2
653,741, 111.1 424,478, -22.6
742,830, 148.2 479,533, -41.9
831,895, 180.3 534,575, -55.2
Note that the final longitudinal interval manages to squeak its center
just beyond the International Dateline (or more precisely the meridian
antipodal to the Prime Meridian, since the International Dateline is
allowed to bend around somewhat).
A coarse rectangular grid would be obtained by pairing any X interval
with any Y interval, thus covering your map.gif. Our first rectangle,
for example, is the combination of the sixth interval from the X
column and the eight interval from the Y column.
* * * * * * * * * * * * * * * * * * * * * * * * * *
Additional Links
================
[Q: Identifying zip codes between two points]
http://answers.google.com/answers/threadview?id=247783
[Q: Distance and angles "through" the globe.]
http://answers.google.com/answers/threadview?id=233527
regards, mathtalk-ga |
Request for Answer Clarification by
j_philipp-ga
on
24 Feb 2004 08:41 PST
Hi Mathtalk,
Thanks a lot. I couldn't follow all your explanations but this table worked for me:
X0, X1,DEG(L) Y0, Y1,DEG(A)
-------------- --------------
0, 29,-173.2 0, 38, 82.7
30,118,-148.4 39, 93, 79.7
119,207,-111.4 94,148, 74.6
208,296, -74.3 149,203, 67.2
297,385, -37.2 204,258, 56.5
386,474, -0.1 259,313, 41.6
475,563, 37.0 314,368, 22.2
564,652, 74.1 369,423, -0.2
653,741, 111.1 424,478, -22.6
742,830, 148.2 479,533, -41.9
831,895, 180.3 534,575, -55.2
Since I don't know how exactly you calculated these values
(automatically, manually, ...), I would like to ask you: would it be
much work to provide two times as many as those, or three times as
many? Especially in Europe the grid is too big to allow users to pick
their country. I plan to tip you :)
Please check out the image map I created based on your values:
http://www.findforward.com/?q=test&t=world
When you load the page in IExplorer and press tab many times, you can
see the different grids. Now when you move your mouse over a specific
grid, you can see the alt-text pop up showing latitude/ longitude (it
seems to be right). When you click on it sites using GeoURL within a
radius of 50 miles are being shown. Do you think the lat/long values
used are correct? E.g. when you click near New York, you will be taken
to sites reading: "near Paterson, USA".
Philipp
|