...

View Full Version : Resolved Scale long/lat coordinates to image



sonny
01-19-2012, 08:39 PM
Hi All

The Code below works fine, problem I'm having is, I'd like to make the image 360 x 720
when I change the size inside the function the dot is way off the location.




$im = imagecreatefromjpeg("earth_360.jpg");//180-360
//$im = imagecreatefromjpeg("earth_720.jpg"); 360 - 720

$red = imagecolorallocate ($im, 255,0,0);

// Next need to find the base image size.
// We need these variables to be able scale the long/lat coordinates.

$scale_x = imagesx($im);
$scale_y = imagesy($im);
$pt = getlocationcoords($lat, $long, $scale_x, $scale_y);

// Now mark the point on the map using a red 4 pixel rectangle
imagefilledrectangle($im,$pt["x"]-2,$pt["y"]-2,$pt["x"]+2,$pt["y"]+2,$red);

imagestring($im,2,1,$scale_y-20,"Geo Map",$black);

header("Content-Type: image/png");

imagepng($im);
imagedestroy($im);
// this works
function getlocationcoords($lat, $lon, $width, $height)
{
$x = (($lon + 180) * ($width / 360));
$y = ((($lat * -1) + 90) * ($height / 180));
return array("x"=>round($x),"y"=>round($y));
}



This edit below to use a larger image did not work for some reason, can someone please
let me know how to scale the location dot with different image sizes?


function getlocationcoords($lat, $lon, $width, $height)
{
$x = (($lon + 360) * ($width / 720));
$y = ((($lat * -1) + 180) * ($height / 360));
return array("x"=>round($x),"y"=>round($y));
}

mlseim
01-19-2012, 08:47 PM
I would say that you need to know how many pixels there are in 1 degree,
or 1 minute/second of latitude and longitude.

How are you representing your coordinates ?
By decimal or by minutes (WGS-84)?

Example:
Current position (by decimal):
44.955440188735956, -93.10223236419677
WGS-84 GeoTracker (by minutes):
N 44 57.326, W 93 6.134

There must be some known way to determine the zoom level, and how
many pixels there are in a certain distance. Can you describe where your
map is coming from? Or an example we can see?


.

sonny
01-19-2012, 09:18 PM
I would say that you need to know how many pixels there are in 1 degree,
or 1 minute/second of latitude and longitude.

How are you representing your coordinates ?
By decimal or by minutes (WGS-84)?

Example:
Current position (by decimal):
44.955440188735956, -93.10223236419677
WGS-84 GeoTracker (by minutes):
N 44 57.326, W 93 6.134

There must be some known way to determine the zoom level, and how
many pixels there are in a certain distance. Can you describe where your
map is coming from? Or an example we can see?


.

as I mentioned above It works that's 99% of the code I posted above its just a simple
image location map, only thing I left out is the incoming long/Lat code.

The scale works in that first block I posted above, the image that it works with is 180 x
360, I just would like to enlarge that image 360 x 720, that's all?

it's tricky yes, but not as complex as the way you describe, maybe someone experienced
in dealing with image string maps will come along and point out what edit I'm missing.

I thought I would just double the math to get it working with a larger image, I'm most likely
just missing something simple, I'm really interested in the logic behind scaling to size

Thanks
Sonny

mlseim
01-19-2012, 09:49 PM
I guess I'm missing the whole idea of it, sorry.

So the location dot is not part of the smaller image?
When you enlarge, are you actually zooming in, or just making the orginal image bigger?

And can you get the latitude and longitude of that "location dot"?
Can you give me an example of the map with the location dot in it?
And how you get that image?

Post an example of what each of these 4 variables might be .. make up some numbers...
getlocationcoords($lat, $lon, $width, $height)


.

sonny
01-19-2012, 10:10 PM
I guess I'm missing the whole idea of it, sorry.

So the location dot is not part of the smaller image?
When you enlarge, are you actually zooming in, or just making the orginal image bigger?

And can you get the latitude and longitude of that "location dot"?
Can you give me an example of the map with the location dot in it?
And how you get that image?

Post an example of what each of these 4 variables might be .. make up some numbers...
getlocationcoords($lat, $lon, $width, $height)

.
$lat and $long are just variables with the lat and long,
the image size is defined inside function getlocationcoords()
the image size is exactly as I entered it, in that function
what I posted above is everything.

that code above "first post" works perfect with a 180 x 360 earth image

Thanks
Sonny

mlseim
01-19-2012, 10:35 PM
So you have some values for a latitude and longitude, but you won't tell me what
those values might be. I'll just make up some values for those.

$lat = "44.955440188735956";
$lon = "-93.10223236419677";

The location dot is placed on your image exactly in the center of your image.
Let's say your image is this:
Height: 180 pixels
Width: 360 pixels
The dot is placed at: 90,180 (the exact center of your image)

Now, you want to expand the image.
The dot is not part of the image, so after you enlarge it, you need to relocate that dot.

Your image is now:
Height: 360 pixels
Width : 720 pixels

You now have to place the location dot in the same spot on the enlarged image.

Here's my question once again ...
How was the location dot originally placed on the small image?
Who put the location dot on the original image ... did you do it?

Somebody put that location dot on the original image. who did that?
If you put the dot there, how did you know where to put it on the image?

There has to be some relationship between lat, lon and the pixel coordinates of the dot.


.

sonny
01-19-2012, 11:25 PM
So you have some values for a latitude and longitude, but you won't tell me what
those values might be. I'll just make up some values for those.

$lat = "44.955440188735956";
$lon = "-93.10223236419677";

The location dot is placed on your image exactly in the center of your image.
Let's say your image is this:
Height: 180 pixels
Width: 360 pixels
The dot is placed at: 90,180 (the exact center of your image)

Now, you want to expand the image.
The dot is not part of the image, so after you enlarge it, you need to relocate that dot.

Your image is now:
Height: 360 pixels
Width : 720 pixels

You now have to place the location dot in the same spot on the enlarged image.

Here's my question once again ...
How was the location dot originally placed on the small image?
Who put the location dot on the original image ... did you do it?

Somebody put that location dot on the original image. who did that?
If you put the dot there, how did you know where to put it on the image?

There has to be some relationship between lat, lon and the pixel coordinates of the dot.


.

the image dot is created by the code above its not a gif or anything like that, the dot is placed on the earth png image based on lat and long supplied by the $lat and $long variables. example



if(empty($long))$long = -63.10774861954596;
if(empty($lat)) $lat = 46.2899306519141;


that's all there is to it. everything is in the first post above

Sonny

mlseim
01-19-2012, 11:47 PM
hmmmmph....

That means those variables $lat and $long must be pixel coordinates of the PNG.

So it's not like this:

$lat = "44.955440188735956"
$lon = "-93.10223236419677"

It's more like this:

$lat = "135"
$lon = "78"

And then it places the dot at those pixel locations.

Am I correct on that now?

sonny
01-20-2012, 12:02 AM
hmmmmph....

That means those variables $lat and $long must be pixel coordinates of the PNG.

So it's not like this:

$lat = "44.955440188735956"
$lon = "-93.10223236419677"

It's more like this:

$lat = "135"
$lon = "78"

And then it places the dot at those pixel locations.

Am I correct on that now?

I have been looking for this article again, and finally found it
http://www.web-max.ca/PHP/article_1.php
this should explain things much better then I did

from what I read, they say its easy to enlarge the image
I must be tired or something, but whatever I try does not work?

Sonny

mlseim
01-20-2012, 01:21 AM
Thank you for that link ... that answered my question.

Here's what they are doing ...

1) They have a JPG image of the whole Earth - layed out flat (Cylindrical projection).

2) All images reference the upper left corner as 0,0 pixels.

THIS IS THE WHOLE KEY TO WHAT IS HAPPENING ...

3) See the attached image. They know what latitude and longitude match
the upper-left corner and the lower-right corner. Two known points ... that's the key.

4) Then they talk about enlarging the image. They mean the very same image
... the whole Earth (Cylindrical projection) with the 0,0 upper-left pixel location
matching the same latitude and longitude. The lower-right lat/lon is still
the same, but the max width and max height of image changes ... easy.

5) The image must be the same image ... no matter how big you make it, it's
the same whole Earth with the upper left being in the same exact spot.

6) I'm guessing you want to do the same thing with an image that IS NOT
of the whole Earth? Am I correct? You won't know what latitude and
logitude is in the upper left corner, or the lower right corner. Unless you
have two known points to match the lat/lon with x,y pixels, you're screwed.

Does that make sense now?


TRY THIS:
Take the attached image and make it 1656 X 906 ...
Now, look at the lat and long ... they didn't change did they?
The upper-left and lower-right lat/lon are in the same spot no matter how big you make it.



.
.

sonny
01-20-2012, 03:48 AM
I am trying to just enlarge that earth image the way it is.
when you say make larger, I'm guessing just the earth image
itself.

Thanks I will try this tomorrow.
Sonny

mlseim
01-20-2012, 12:31 PM
Yes, if you make that full Earth image any size, it will work.
It should work ... let me say that.

What they're doing is "line equations".
There must be at least two known points on the line.
Enlarging the image changes the slope of the line.

sonny
01-20-2012, 05:36 PM
Yes, if you make that full Earth image any size, it will work.
It should work ... let me say that.

What they're doing is "line equations".
There must be at least two known points on the line.
Enlarging the image changes the slope of the line.

Yes works fine now, thanks for explaining things and that scale image graph, I was able to
fine tune by playing with the scale H/W as well. I also found out how to work with the
imagestring like font size, color,and string positioning x/y etc.

Thanks again, this place is the best
Sonny



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum