Created
January 2, 2014 18:32
-
-
Save yarl/8224075 to your computer and use it in GitHub Desktop.
Geoportal WMS to TMS conversion.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$zoom = htmlspecialchars($_GET["zoom"]); | |
$x = htmlspecialchars($_GET["x"]); | |
$y = htmlspecialchars($_GET["y"]); | |
//explanation: https://gist.github.com/tmcw/4954720 | |
$y = pow(2, $zoom)-$y-1; | |
//source: https://github.com/timwaters/whoots/blob/master/whoots.rb | |
function get_tile_bbox($x,$y,$z) { | |
$merc1 = get_merc_coords($x * 256, $y * 256, $z); | |
$merc2 = get_merc_coords(($x + 1) * 256, ($y + 1) * 256, $z); | |
$min_x = $merc1['merc_x']; $min_y = $merc1['merc_y']; | |
$max_x = $merc2['merc_x']; $max_y = $merc2['merc_y']; | |
return $min_x.",".$min_y.",".$max_x.",".$max_y; | |
} | |
function get_merc_coords($x,$y,$z) { | |
$resolution = (2 * pi() * 6378137 / 256) / (pow(2,$z)); | |
$merc_x = ($x * $resolution - 2 * pi() * 6378137 / 2.0); | |
$merc_y = ($y * $resolution - 2 * pi() * 6378137 / 2.0); | |
return compact('merc_x', 'merc_y'); | |
} | |
$bbox = get_tile_bbox($x,$y,$zoom); | |
header('Location: http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=Raster&STYLES=&SRS=EPSG:3857&WIDTH=265&HEIGHT=256&BBOX='.$bbox); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment