Google Answers Logo
View Question
 
Q: Latitude/ Longitude on map graphic ( Answered 5 out of 5 stars,   7 Comments )
Question  
Subject: Latitude/ Longitude on map graphic
Category: Computers > Programming
Asked by: j_philipp-ga
List Price: $15.00
Posted: 18 Feb 2004 12:48 PST
Expires: 19 Mar 2004 12:48 PST
Question ID: 308057
I would like to know the latitude/ longitude values for this map,
based on the X/Y parameters: http://www.findforward.com/image/map.gif

Any idea how I can get those?
E.g. a great answer would consist of a grid of say 100*100 sections
(or less -- the more the better( defined as x1,y1,x2,y2 rectangles
with the latidude, longitude values, like so:
10,20,30,10,20.000,30.000 [only sample values]

Request for Question Clarification by webadept-ga on 18 Feb 2004 13:08 PST
Becareful with that "the more the better" stuff Phillipp, it can get
you in trouble. Yes, I think I can do that for you. Do you want these
drawn on there, or an imagemap made? And what real spacing do you want
for these (doesn't matter to me, but if you want them drawn on there,
you could get back a black box if they are too close).

webadept-ga

Clarification of Question by j_philipp-ga on 18 Feb 2004 13:48 PST
The best would be: an image map with rectangles which more or less
cover everything (needs not be pixel perfect). As many as make sense,
it's a little hard for me to say. Just a nice grid, doesn't have to
cover water either.

Philipp (one "l"), hoping to not get into trouble

Request for Question Clarification by mathtalk-ga on 19 Feb 2004 13:58 PST
Hi, j_philipp-ga:

Would it be safe to assume an imagemap in xhtml would be preferred to one in HTML?

regards, mathtalk-ga
(also with one l)

Clarification of Question by j_philipp-ga on 19 Feb 2004 15:05 PST
Mathtalk,

Anything will do... something like this would be great:

x1,y1,x2,y3,lat,long

For example

10,20,30,10,20.000,30.000
40,10,30,10,-3,20.000

(Basically, a CVS file you can import in Excel etc.)
But an image map would do as well, as long as the long/lat parameters
are in the link.

Philipp (three "p")

Request for Question Clarification by mathtalk-ga on 23 Feb 2004 07:52 PST
Again a progress report...

I've now fitted the Y coordinates satisfactorily.  Apparently the map
uses a Mercator projection, which I will explain with my Answer.

In addition to the formulas derived, I will supply a CVS list of
coordinates as you've requested.  For "fine" control I can prepare a
batch of 8x5 rectangles, in keeping with the original request.  But
this would be supplied as a download.  Due to size of such listings
I'll perhaps include a listing of 89x55 rectangles in the text of the
Answer itself, for illustrative purposes (tiling outward from the
intersection of the Equator and the Prime Meridian).

Your sample format for latitude and longitude includes three places to
the right of the decimal point.  This would be something of an
exaggeration of the actual precision available.  In terms of the
degrees most of my data points were fitted to within less than a
degree, but anything more than a single decimal point is overkill. 
After all, we're reporting a single geographic location for an entire
rectangle.

-- mathtalk-ga
Answer  
Subject: Re: Latitude/ Longitude on map graphic
Answered By: mathtalk-ga on 23 Feb 2004 22:20 PST
Rated:5 out of 5 stars
 
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

Clarification of Answer by mathtalk-ga on 24 Feb 2004 12:23 PST
Not a problem, j_philipp.  I'm using Excel to do the calculations, and
I'd planned to use a SQL query to pair up the X and Y intervals to
make the rectangle records for you.

I don't know if you do much with Excel and/or a SQL engine, but the
basic idea is to populate two tables and do a Cartesian join.

I'll put up a link later to download the file that results from using
9x6 rectangles.  You may want to eliminate ones over the oceans to
save on page size & frustration.  I noticed some of the rectangles
return no GeoURL results.

-- mathtalk-ga

Request for Answer Clarification by j_philipp-ga on 24 Feb 2004 12:56 PST
Cool. Thanks!

Clarification of Answer by mathtalk-ga on 24 Feb 2004 21:29 PST
Hi, j_philipp-ga:

Here's a link from which you can download the finer grid, using 9x6
pixel rectangles:

http://68.15.21.151/uploads/researchers/rectangle.csv

It looks to me like the longitude and latitude given by your map +
grid is correct, even though of a coarse granularity.  Note that your
specification was to put the latitude in front of the longitude on
each line, and I've done so in the file above.  This agrees with the
presentation in your sample image map, i.e. putting the latitude
before the longitude in the URLs.

I'd be happy to try to answer any questions you have about the
numerical methods involved.  I know getting something that works can
be a great motivation to learn more.  If some glitches turn up in the
mapping, it will probably be pretty straightforward to tweak the
rectangles as needed.  Let me know how I can be of service.

regards, mathtalk-ga
j_philipp-ga rated this answer:5 out of 5 stars and gave an additional tip of: $25.00
Much of the math talk was lost on me (excuse the pun), but the final
result is great!

Comments  
Subject: Re: Latitude/ Longitude on map graphic
From: mathtalk-ga on 18 Feb 2004 21:20 PST
 
Dear j_philipp-ga,

The map looks like a cylindrical projection, probably with a greater
portion of the southern polar region removed than the northern one. 
If so the X (horizontal) coordinates can be transformed into
longitudes in a simple linear fashion, while the Y (vertical)
coordinates can be made to give the latitudes by an inverse cosine
transformation.

I'm wondering if you are looking for a visual "grid" overlay for your
map, for some mathematical functions that can be programmed, or
perhaps for a Java-like program that would actually convert a mouse
position into latitude/longitude.

Ask and you shall receive!

-- mathtalk
Subject: Re: Latitude/ Longitude on map graphic
From: j_philipp-ga on 19 Feb 2004 03:58 PST
 
Mathtalk,

If it's a mathematical algorithm that helps me to generate the output
that would be fine! And as I said it needs not be pixel perfect.

If you have a Java applet solution of some sort I'd like to know more
about it first because I'm not sure I could make good use of it.

As for the visual grid, no I don't need anything like that if I
understand you right. The grid can be invisible, like an HTML
image-map that I could create from the coordinates.

Thanks!
Subject: Re: Latitude/ Longitude on map graphic
From: pugwashjw-ga on 19 Feb 2004 07:17 PST
 
Mathtalk is complicated but correct. If you take your map as it is and
divide it top to bottom with 361 horizontal lines, giving 360 gaps,
then each gap would be equal to one degree which converts to sixty
nautical miles. Do thje same with vertical lines. Then each square
formed would be 60 X 60 nautical miles. The result, although not
perfectly exact, due to the earth being round, would come out as we
know latitude and longitude co-ordinates on most world maps. Equator:
horizontal line through centre = 0 degrees, then in one degree
increments to 180 degrees North, and 180 degrees South, equates with
Latitude. In the real world, the vertical lines would converge at the
North and South poles, but on your map would be parallel. Hope this
helps. Capn.Pugwash
Subject: Re: Latitude/ Longitude on map graphic
From: mathtalk-ga on 19 Feb 2004 07:58 PST
 
Thanks, Capn. Pugwash. Permission to come aboard!

I've looked at the map, and I see there are some blank areas at left
and right margins.  Hence of the 896 (X/horizontal) by 576
(Y/vertical) pixels in the map.gif image, some parts will need to be
excluded from the "mapping".

To rigorously define the transformations we need to pin down some
coordinates of well-known geographic features in the map.  Easiest to
use will be lines of longitude or latitude (which form country
boundaries and are thus drawn).

These are a bit unusual as country boundaries, even when they don't
follow an ocean coast, tend to be tied to other natural features like
rivers and mountains.

The US/Canadian border following the 49 North "parallel" of latitude
is one such feature, and the Alaska/Canadian border following the 141
West "circle" of longitude is another.

Elsewhere in the world, the western and southern boundaries of Egypt:

Eygpt/Libya :  25 E Longitude

Egypt/Sudan :  22 N Latitude

The boundary between Indonesia and Papua New Guinea is not an exact
north/south feature, but close enough for our purposes at 141 East
Longitude.

Even from this modest sampling of coordinates one can see that the map
does emphasize the northern hemisphere.  Therefore we should perhaps
begin by trying to pin down a vertical pixel location for the equator.

-- mathtalk-ga
Subject: Re: Latitude/ Longitude on map graphic
From: j_philipp-ga on 19 Feb 2004 10:38 PST
 
Hi Mathtalk, if you can wrap it up together and guide me through the
algorithm, please inhibit the answer spot!

In the end I hope you can see the result at http://www.findforward.com
and you'll get a mention in the About page!
Subject: Re: Latitude/ Longitude on map graphic
From: mathtalk-ga on 21 Feb 2004 12:45 PST
 
In the way of a progress report, I've been using the Internet together
with a 1949 edition of the Handy Reference Atlas by Bartholomew & Sons
(London) for the latitude/longitude values, and Microsoft HTML Help
Image Editor for the GIF coordinates.

I have ten longitude values, which are reasonably well fit by a linear
interpolation.

I have a dozen latitude values, four of which are on or near the
equator, with which to do the (nonlinear) inverse sine (or cosine)
fit.  I also have points the tropic parallels and at or near the top
and bottom of the map.

Stay tuned...

-- mathtalk-ga
Subject: Re: Latitude/ Longitude on map graphic
From: j_philipp-ga on 22 Feb 2004 18:57 PST
 
I'm staying tuned...

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy