PHP Classes

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

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 34 All time: 11,027 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: 31944 in Georgia Georgia
Week rank: 216 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 (18)  
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 (18)  /  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 (18)  /  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 (18)  /  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 (18)  /  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 (18)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:34
This week:0
All time:11,027
This week:78Up