PHP Classes

WMTS PHP Map Tile Downloader: Download tiles of maps of a world region from WMTS

Recommend this page to a friend!
  Info   View files Example   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-06-13 (11 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 34 All time: 10,977 This week: 78Up
Version License PHP version Categories
wmtstiledownloader 1.0MIT/X Consortium ...5PHP 5, Web services, Geography
Description 

Author

This package can download tiles of maps of a world region from WMTS.

It can take as parameters the coordinates of the corners of a region of the world and a given zoom level.

The package can call a downloader class that this package calls to process the download of the map tile images and save the image files into a given directory.

Picture of Niko Peikrishvili
  Performance   Level  
Name: Niko Peikrishvili <contact>
Classes: 7 packages by
Country: Georgia Georgia
Age: ???
All time rank: 32004 in Georgia Georgia
Week rank: 298 Up1 in Georgia Georgia Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php

use WMTSTileDownloader\Downloader\BasicDownloader;
use
WMTSTileDownloader\Helpers\Mercator;
use
WMTSTileDownloader\Types\LatLng;
use
WMTSTileDownloader\Types\ZoomLevel;
use
WMTSTileDownloader\WMTSTileDownloader;

require
'vendor/autoload.php';

$downloader = new WMTSTileDownloader(mercator: new Mercator(), downloader: new BasicDownloader(saveTo: '/path/to/directory/for/storing/files'));
$nw = new LatLng(59.977005492196, -12.2607421875);
$se = new LatLng(49.610709938074, 1.93359375);
$downloader->generateFromLatLongs(northWest: $nw, southEast: $se, zoomLevel: new ZoomLevel(9));


Details

Description

This library provides very basic functionality for downloading Tile layers from a WMTS server. Your goal is to implement the DownloaderInterface with you logic with your logic and pass it to the WMTSTileDownloader class constructor when creating an object from it.

Data about the tile will be passed to the download method, and then you decide what to do.

int $x, int $y, int $z, int $counter

Example

use WMTSTileDownloader\Downloader\BasicDownloader;
use WMTSTileDownloader\Helpers\Mercator;
use WMTSTileDownloader\Types\LatLng;
use WMTSTileDownloader\Types\ZoomLevel;
use WMTSTileDownloader\WMTSTileDownloader;

require 'vendor/autoload.php';

$downloader = new WMTSTileDownloader(mercator: new Mercator(), downloader: new BasicDownloader(saveTo: '/path/to/directory/for/storing/files'));
$nw = new LatLng(59.977005492196, -12.2607421875);
$se = new LatLng(49.610709938074, 1.93359375);
$downloader->generateFromLatLongs(northWest: $nw, southEast: $se, zoomLevel: new ZoomLevel(9));

The library comes with an example BasicDownloader

<?php

declare(strict_types=1);

namespace WMTSTileDownloader\Downloader;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

final readonly class BasicDownloader implements DownloaderInterface
{

    public function __construct(private string $saveTo)
    {
    }

    /
     * @throws GuzzleException
     */
    public function download(int $x, int $y, int $z, int $counter): bool
    {
        $url = 'https://tile.openstreetmap.org/'.$z.'/'.$x.'/'.$y.'.png';
        $this->downloadFile($url,$z.'_'.$x.'_'.$y,'.png');
        return true;
    }

    /
     * @throws GuzzleException
     */
    public function downloadFile(string $url, string $name, string $extensions): void
    {
        $path = rtrim($this->saveTo,'/').'/' . $name . $extensions;
        $client = new Client();
        $client->get($url, ['sink' => $path]);
    }
}

class that implements the DownloaderInterface It is just for example purposes, but in many cases, it may be the only thing that you need: just download tiles in a folder.


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 4 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Read me
Accessible without login Plain text file usage.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageDownloader (2 files)
Files folder imageExceptions (4 files)
Files folder imageHelpers (2 files)
Files folder imageTypes (4 files)
  Plain text file WMTSTileDownloader.php Class Class source

  Files folder image Files  /  src  /  Downloader  
File Role Description
  Plain text file BasicDownloader.php Class Class source
  Plain text file DownloaderInterface.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file InvalidLatitudeException.php Class Class source
  Plain text file InvalidLongitudeException.php Class Class source
  Plain text file InvalidTileXException.php Class Class source
  Plain text file InvalidZoomLevelException.php Class Class source

  Files folder image Files  /  src  /  Helpers  
File Role Description
  Plain text file Mercator.php Class Class source
  Plain text file MercatorInterface.php Class Class source

  Files folder image Files  /  src  /  Types  
File Role Description
  Plain text file LatLng.php Class Class source
  Plain text file Point.php Class Class source
  Plain text file Tile.php Class Class source
  Plain text file ZoomLevel.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:34
This week:0
All time:10,977
This week:78Up