/** * Download srtm files for a specific latitude and longitude. * @param int $lat * @param int $lng */ function download_srtm_for($lat, $lon) { global $config; $base_url = 'http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/'; $srtm_directory = get_srtm_directory() . "/"; $fname = srtm::get_filename($lat, $lon); $zip_fname = $fname . '.zip'; $regions = array('Africa', 'Australia', 'Eurasia', 'Islands', 'North_America', 'South_America'); /* * Search file in all regions */ foreach ($regions as $region) { if (!($srtm_data = @file_get_contents($base_url . '/' . $region . '/' . $zip_fname))) { continue; } file_put_contents($srtm_directory . $zip_fname, $srtm_data); if (!($zip = zip_open($srtm_directory . $zip_fname))) { die("Cannot unzip file \"" . $srtm_directory . $zip_fname . "\"\n"); } while ($e = zip_read($zip)) { if (zip_entry_name($e) !== $fname) { continue; } zip_entry_open($zip, $e, "r"); $uncompressed = zip_entry_read($e, zip_entry_filesize($e)); file_put_contents($srtm_directory . $fname, $uncompressed); zip_close($zip); unlink($srtm_directory . $zip_fname); return true; } } die("Cannot find tile for {$lat},{$lon}\" in any region.\n"); }
<?php require_once dirname(__FILE__) . '/../../globals/classes/srtm.php'; // Calculate needed files $needed_files = array(); $bounds = $_SESSION['config']['map']['bounds']; for ($lat = floor($bounds['min_latitude']); $lat <= ceil($bounds['max_latitude']); $lat += 1) { // Clamp if ($lat > 90) { $lat = -90; } for ($lng = floor($bounds['min_longitude']); $lng <= ceil($bounds['max_longitude']); $lng += 1) { // clamp if ($lng > 180) { $lng = -180; } $fname = srtm::get_filename($lat, $lng); $needed_files[$fname] = array('exists' => file_exists(dirname(__FILE__) . '/../../files/srtm/' . $fname), 'lat' => $lat, 'lng' => $lng); } } $web_folders = array('Africa', 'Australia', 'Eurasia', 'Islands', 'North_America', 'South_America'); if (!extension_loaded('zip') || !function_exists('zip_open')) { show_error('You need <strong>"zip"</strong> extension to download srtm files.'); return true; } echo '<ul class="srtm">'; foreach ($needed_files as $fname => $data) { echo '<li data-lat="' . $data['lat'] . '" data-lng="' . $data['lng'] . '" class="' . ($data['exists'] ? 'existing' : 'missing') . '">' . '<span>' . $fname . '</span></li>'; } echo '</ul>'; echo '<div style="clear: both;"> </div>'; ?>
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ ini_set('max_execution_time', 300); header('Content-Type: application/json'); require_once dirname(__FILE__) . '/../globals/classes/srtm.php'; if (!isset($_GET['lat']) || !isset($_GET['lng'])) { return; } $base_url = 'http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/'; $srtm_directory = dirname(__FILE__) . '/../files/srtm/'; $fname = srtm::get_filename((int) $_GET['lat'], (int) $_GET['lng']); $zip_fname = $fname . '.zip'; $regions = array('Africa', 'Australia', 'Eurasia', 'Islands', 'North_America', 'South_America'); /* * Search file in all regions */ foreach ($regions as $region) { if (!($srtm_data = @file_get_contents($base_url . '/' . $region . '/' . $zip_fname))) { continue; } file_put_contents($srtm_directory . $zip_fname, $srtm_data); if (!($zip = zip_open($srtm_directory . $zip_fname))) { echo json_encode(array('result' => '500', 'error' => 'cannot unzip')); return; } while ($e = zip_read($zip)) {