[OSM-talk] calculating lon/lat bounds from tilename
Oliver Reimann
waschbaer42 at gmx.de
Fri Jun 22 04:34:09 BST 2007
Hallo,
im using the following perl function for get the coordinates of an tilename
(mostly got from the t at h):
#-----------------------------------------------------------------------------
sub Project{
my ($X,$Y, $Zoom) = @_;
my $Unit = 1 / (2 ** $Zoom);
my $relY1 = $Y * $Unit;
my $relY2 = $relY1 + $Unit;
my $LimitY = ProjectF(85.0511);
my $RangeY = 2 * $LimitY;
$relY1 = $LimitY - $RangeY * $relY1;
$relY2 = $LimitY - $RangeY * $relY2;
my $Lat1 = ProjectMercToLat($relY1);
my $Lat2 = ProjectMercToLat($relY2);
$Unit = 360 / (2 ** $Zoom);
my $Long1 = -180 + $X * $Unit;
return(($Lat2, $Long1, $Lat1, $Long1 + $Unit)); # S,W,N,E
}
#-----------------------------------------------------------------------------
sub ProjectMercToLat($){
my $MercY = shift();
return( 180/pi* atan(sinh($MercY)));
}
#-----------------------------------------------------------------------------
sub ProjectF($){
my $Lat = pi/180 * shift();
my $Y = log(tan($Lat) + sec($Lat));
return($Y);
}
#-----------------------------------------------------------------------------
Am Freitag, 22. Juni 2007 00:19 schrieben Sie:
> Hi, not sure if this is the right place to post this question, so
> forgive me if it's off topic...
> I've been working on a script that takes a lon/lat position, zoom level
> and a size of grid to capture.
> and it retrieves all the tiles in a grid of your size centered around
> the lon/lat provided.
> so I might say zoom=15, gridsize=4 and it will get me a 4x4 grid of
> tiles at that zoom level around my lon/lat.
> Now I'm doing this to use with TrekBuddy which is very cool. And I want
> a script that will build me the Atlas inputs it requires using the
> openstreetmap images.
> Everything works great.. however I need to generate a file that
> specifies the lon/lat of the top left corner and bottom right corner of
> my grid. I have no idea how to do that (I stole the calculation for
> lon/lat -> mercator tile from the osm page that contained a perl
> example.
>
> Any one have any ideas? I'm really keen to make it simple to use open
> streetmap data in trekbuddy so that I can see what currenty exists on
> the map as I walk around new places, to avoid going mapping stuff
> already there.
>
> Thanks for any assistance, even if only to point me at a better place to
> ask the question!
>
> Sincerely
>
> Daniel Would
>
>
> _______________________________________________
> talk mailing list
> talk at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
More information about the talk
mailing list