Gmail Calendar Documents Web Reader more »
Help | Sign in
Google Groups Home
How can I calculate tile coordinates (bbox) in php?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
nelsong  
View profile  
 More options Jan 18 2008, 8:58 am
From: nelsong <nelson.g...@gmail.com>
Date: Thu, 17 Jan 2008 12:58:34 -0800 (PST)
Local: Fri, Jan 18 2008 8:58 am
Subject: How can I calculate tile coordinates (bbox) in php?
Hi everyone,

I have a problem that I can't solve and I was wondering if anyone
might be able to help.  I am trying to write a php script that will
take a lat/lng point and calculate the bbox for the enclosing tile and
the pixel coordinates to that lat/lng from the upper left corner of
the tile.  I already know how to do this in javascript using the
google map api (i'll paste the javascript below, but I can't figure
out how to do it in php without the api.  I want to do this because I
am using a WMS getFeatureInfo query to query my map, but I would like
to be able to run those queries outside of the map api on the server
side.

I've searched all over the web, and I just can't find something that
helps me figure this problem out. Is there any way you might be able
to lead me in the right direction?  This for a non-profit site that
maps roadless areas in US forest service land.  You can see it here:
http://roadlessland.org (some of you have already seen this)

thanks so much,
nelson

Here is the javascript that I am currently using:

        var z;  // zoom level at which to calculate the tile

        var proj = map.getCurrentMapType().getProjection();
        var pt = proj.fromLatLngToPixel(latlng,z);

        var tile_coord_x = Math.floor(pt.x/256);
        var tile_coord_y = Math.floor(pt.y/256);
        var a = new GPoint(tile_coord_x,tile_coord_y);
        var lULP = new GPoint(a.x*256,(a.y+1)*256);
        var lLRP = new GPoint((a.x+1)*256,a.y*256);

        var lUL =
G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP,z,false);
        var lLR =
G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,z,false);

        var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;

//      The bbox coordinates:
        var bbox = lBbox;

//      Get the pixel coordinates of the lat/lng point

        var local_x = pt.x % 256;
        var local_y = pt.y % 256;

        var coords = 'x='+local_x+'&y='+local_y;


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vasile cotovanu  
View profile  
 More options Jan 18 2008, 8:51 pm
From: vasile cotovanu <vasile.cotov...@gmail.com>
Date: Fri, 18 Jan 2008 00:51:19 -0800 (PST)
Local: Fri, Jan 18 2008 8:51 pm
Subject: Re: How can I calculate tile coordinates (bbox) in php?
Read also here : http://cfis.savagexi.com/articles/2006/05/03/google-maps-deconstructed
The big magic it is in the projection formulas, Google uses a
different Mercator projection for each zoom level, after you will
define projection formulas you will can easily convert long/lat to
pixels(measure unit in projection used) for a given zoom level and
then to calculate the enclosing tile and of course top and left pixel
from 0,0 of tile.

On Jan 17, 9:58 pm, nelsong <nelson.g...@gmail.com> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bratliff  
View profile  
 More options Jan 19 2008, 2:40 am
From: bratliff <bratl...@umich.edu>
Date: Fri, 18 Jan 2008 06:40:20 -0800 (PST)
Local: Sat, Jan 19 2008 2:40 am
Subject: Re: How can I calculate tile coordinates (bbox) in php?

On Jan 18, 8:51 am, vasile cotovanu <vasile.cotov...@gmail.com> wrote:

> Read also here :http://cfis.savagexi.com/articles/2006/05/03/google-maps-deconstructed
> The big magic it is in the projection formulas, Google uses a
> different Mercator projection for each zoom level,

huh ????

The only difference is the shift amount (zoom parameter).

    http://www.polyarc.us/buildurl.js

Look at the LToX & LToY functions. Ignore the "w" parameter which is
the UTM zone.  I stripped out the UTM projection stuff used by
TerraServer.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
nelsong  
View profile  
(1 user)  More options Jan 19 2008, 6:56 am
From: nelsong <nelson.g...@gmail.com>
Date: Fri, 18 Jan 2008 10:56:58 -0800 (PST)
Local: Sat, Jan 19 2008 6:56 am
Subject: Re: How can I calculate tile coordinates (bbox) in php?
Thanks all,

The article on deconstructing google maps was interesting, but still a
bit far from what I needed to accomplish.  I found the coordtotile.php
function separately, and I realized that it had what I needed (
http://mapki.com/coordtotile.2.phps - also found here:
http://mapki.com/wiki/Lat/Lon_To_Tile )

After some work I figured out how to get the info I needed out of it
by adding a short function.  For anyone interested, I will paste it
below.  This is a function that will spit out a wms query string (bbox
and xy coordinates) given a lat/lng pair and a google zoom.  Just add
this to the end of coordtotile.2.php - then use the function
get_query_string($lat,$lng,$z).  The only caveat is that coordtotile.
2.php does not seem to work well with zooms less than 8 (I imagine it
has something to do with crossing the zero longintude line, but I
didn't investigate further.)

Also, for anyone interested, coordtotile.2.php must have been
developed before google map switched their zoom around, because I had
to add -25 to the zoom so that the results match with current google
map zooms.

best,
nelson

<?
function get_query_string($lat,$lng,$z) {
$z = 25 - $z;
$tile = new Tile($lat,$lng,$z);

$tilelng = $tile->getTileLatLong();
$tilelng = $tilelng->x;
$tilelat = $tile->getTileLatLong();
$tilelat = $tilelat->y;

$tilelat2 = $tilelat;
$tilelng2 = $tilelng;
$lat2 = $lat;
$lng2 = $lng;

while($tilelat2 == $tilelat) {
$lat2 = $lat2 - .001;
$tile = new Tile($lat2,$lng2,$z);
$tilelat2 = $tile->getTileLatLong();
$tilelat2 = $tilelat2->y;

}

while($tilelng2 == $tilelng) {
$lng2 = $lng2 + .001;
$tile = new Tile($lat2,$lng2,$z);
$tilelng2 = $tile->getTileLatLong();
$tilelng2 = $tilelng2->x;

}

$thgt = $tilelat - $tilelat2;
$twdt = $tilelng2 - $tilelng;
$xpt = round(($lng-$tilelng)*256/$twdt);
$ypt = round(($tilelat-$lat)*256/$thgt);

$bbox =  $tilelng.','.$tilelat2.','.$tilelng2.','.$tilelat;
$pt_coords =  '&x='.$xpt.'&y='.$ypt;
$query = 'bbox='.$bbox.$pt_coords;
return $query;

}

?>

On Jan 18, 8:40 am, bratliff <bratl...@umich.edu> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google