Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Scale long/lat coordinates to image

    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.

    PHP Code:

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

    $red imagecolorallocate ($im255,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?
    PHP Code:
    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));

    Last edited by sonny; 01-20-2012 at 05:39 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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?


    .

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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
    Last edited by sonny; 01-19-2012 at 09:26 PM.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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)


    .

  • #5
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.


    .
    Last edited by mlseim; 01-19-2012 at 11:01 PM.

  • #7
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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

    PHP Code:
     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

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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?

  • #9
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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
    Last edited by sonny; 01-20-2012 at 03:45 AM.

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.



    .
    .
    Attached Thumbnails Attached Thumbnails Scale long/lat coordinates to image-longlat.gif  
    Last edited by mlseim; 01-20-2012 at 01:24 AM.

  • Users who have thanked mlseim for this post:

    sonny (01-20-2012)

  • #11
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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
    Last edited by sonny; 01-20-2012 at 03:50 AM.

  • #12
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.

  • #13
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •