Page 1 of 1
mapping with php, converting lon/lat
Posted: Mon Jul 12, 2004 10:46 pm
by nigma
Hey, i'm hoping that someone reading this can help me better understand how to plot longitude and latitude points on a map.
Alright, say I have a map that is 602pixels wide and 324pixels high.
And say I want to map the longitude/latitude cordinate +39,-75
How would I do this?
I'm thinking I would basically just need to find the number of pixels per degree of longitude and pixels per degree of latitude and then multiply the number of degrees of either longitude or latitude by the number of corresponding pixels? But my attempt at doing this did not produce the desired output.
Thanks a bunch for any input provided.
Posted: Mon Jul 12, 2004 10:54 pm
by PrObLeM
http://www.phpbuilder.com/columns/moss2 ... hp3?page=3
remember kids point 0,0 is at the top left and point 602,324 is on the bottom right!
Posted: Tue Jul 13, 2004 1:22 pm
by nigma
That doesn't work accurately when used on an image of an individual continent in which the border of the continent don't touch the border of the image.
Check out the article Trip Mapping on ONLamp
http://www.oreillynet.com/pub/a/php/200 ... p_map.html
Now, the function in that article didn't work for me either, but the logic makes more sense than that of the phpbuilder article.
Posted: Tue Jul 13, 2004 3:11 pm
by PrObLeM
YOu need to find the log and lat for the border of the image...
Re: mapping with php, converting lon/lat
Posted: Tue Jul 13, 2004 3:12 pm
by Kydosan
nigma wrote:Hey, i'm hoping that someone reading this can help me better understand how to plot longitude and latitude points on a map.
Alright, say I have a map that is 602pixels wide and 324pixels high.
And say I want to map the longitude/latitude cordinate +39,-75
How would I do this?
I'm thinking I would basically just need to find the number of pixels per degree of longitude and pixels per degree of latitude and then multiply the number of degrees of either longitude or latitude by the number of corresponding pixels? But my attempt at doing this did not produce the desired output.
Is this map just part of the world, or is it all 360/180 degrees?
If it's the whole world you're laughing, just divide 602 by 360 and 324by 180 to get the amount of pixels per degree, then plot your points accordingly, probably something along the lines of
Code: Select all
$x=(602/360)*$lon //(65.22 in your example above, more or less :))
$y=(324/180)*$lat //(-135)
Then you just need to map them onto your picture, add half the y res to y, and you may need to monkey around with the longitude to get that right - I've written a Mars images search engine, and found that in some data west is positive, and in others, East is, if West is positive and the center of your image is 0,0 in lat/lon 180 should be the far left and 181 should be the far right, so uhh... you'd probably do something like this:
Code: Select all
$longitude_res=602/360
$longitude_origin=$longitude_res*180
$x=(-1*($lon*$longitude_res))+$longitude_origin
if($x<0)$x+=602;
Something like that anyway, of course that all goes out the window if your pic doesn't cover the entire world, and everything'll come out all screwy if the data is using a different coord system.
That the kind of thing you're looking for? If you can provide more details I'll try to help out all I can

Posted: Tue Jul 13, 2004 5:27 pm
by nigma
It's just going to be part of the world. The map i'm using is a 2-d picture of the united states. A friend of mine actually wrote me two functions to do it for me but I'm not quite sure I completely understand what is going on.
So any explanations of why you would do what to get the lon/lat cords onto the image accurately would be greatly apreciated.
Posted: Wed Jul 14, 2004 5:43 pm
by Kydosan
nigma wrote:It's just going to be part of the world. The map i'm using is a 2-d picture of the united states. A friend of mine actually wrote me two functions to do it for me but I'm not quite sure I completely understand what is going on.
So any explanations of why you would do what to get the lon/lat cords onto the image accurately would be greatly apreciated.
As PrObLeM said, you'll need to know the lat/long of the image edges, I've no idea how to accurately do that, at a guess I'd start off on the likes of terraserver.com and manually try to find them, you may be out of luck though.
If you can post a link to the picture I'll try to help you figure it out, but I don't know how helpful I'll be.

Posted: Thu Jul 15, 2004 3:04 am
by JayBird
Can you show us the picture you are using and the code that your friend wrote for you.
Mark