PHPackages                             heymoon/vector-tile-data-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. heymoon/vector-tile-data-provider

ActiveLibrary[API Development](/categories/api)

heymoon/vector-tile-data-provider
=================================

Serve, write and read Mapbox Vector Tile 2.1

1.1.6(11mo ago)51.6k↓50%[1 issues](https://github.com/heymoon-cc/php-vector-tile-data-provider/issues)MITPHPPHP &gt;=8.1CI passing

Since Oct 31Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/heymoon-cc/php-vector-tile-data-provider)[ Packagist](https://packagist.org/packages/heymoon/vector-tile-data-provider)[ RSS](/packages/heymoon-vector-tile-data-provider/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (17)Used By (0)

Mapbox vector tiles library for PHP
===================================

[](#mapbox-vector-tiles-library-for-php)

[![Version](https://camo.githubusercontent.com/af56d5abcb8365ec7ea13f488a80ee5be0c2edb39f85f188d6644eff60e6eb64/68747470733a2f2f706f7365722e707567782e6f72672f6865796d6f6f6e2f766563746f722d74696c652d646174612d70726f76696465722f76)](https://packagist.org/packages/heymoon/vector-tile-data-provider)[![PHP Version Require](https://camo.githubusercontent.com/54162fb83450020bb9f8b02ba20c72b3ae5105071ca80cb30b8181375fab1399/68747470733a2f2f706f7365722e707567782e6f72672f6865796d6f6f6e2f766563746f722d74696c652d646174612d70726f76696465722f726571756972652f706870)](https://packagist.org/packages/heymoon/vector-tile-data-provider)[![Test](https://github.com/heymoon-cc/php-vector-tile-data-provider/actions/workflows/test.yaml/badge.svg)](https://github.com/heymoon-cc/php-vector-tile-data-provider/actions/workflows/test.yaml)[![Maintainability](https://camo.githubusercontent.com/7b71c78ddb2bbb8206e31f4018a60f76b2f8f16e61ba28b8ea0ad23f4775e640/68747470733a2f2f716c74792e73682f6261646765732f38313064666530322d366265332d343337352d386434612d6462313964616134336662372f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/heymoon-cc/projects/php-vector-tile-data-provider)[![Code Coverage](https://camo.githubusercontent.com/c8f508b65a170813b7b98d6318fa1ba977a3537c2973466e16b8f39c83045f86/68747470733a2f2f716c74792e73682f6261646765732f38313064666530322d366265332d343337352d386434612d6462313964616134336662372f746573745f636f7665726167652e737667)](https://qlty.sh/gh/heymoon-cc/projects/php-vector-tile-data-provider)[![Matrix](https://camo.githubusercontent.com/ba4f5185d05e0c579d98c22173f397e90b8bdd45d498c034f3c13e60391c1a33/68747470733a2f2f696d672e736869656c64732e696f2f6d61747269782f7068702d766563746f722d74696c652d646174612d70726f76696465722533416865796d6f6f6e2e63633f66657463684d6f64653d6775657374)](https://matrix.to/#/#php-vector-tile-data-provider:heymoon.cc)

Symfony + Redis demo: ****
--------------------------------------------------

[](#symfony--redis-demo-httpsmapheymooncc)

[![Screenshot](https://repository-images.githubusercontent.com/556105367/1ae4eed2-6718-45ea-909e-16aad3ef7dc9)](https://repository-images.githubusercontent.com/556105367/1ae4eed2-6718-45ea-909e-16aad3ef7dc9)

Basic [Leaflet](https://leafletjs.com/)-based map example with realtime Symfony backend performance preview. When "Use cache" checkbox is not active, `getTileMVT` function is called on each request without any additional static caching strategy. With "Use cache" option, backend renders each tile only once and stores results in Redis. Two layers are requested separately for benchmarking:

- Polygons based off 976K GeoJSON with 7 string properties.
- Lines based off 2.8M GeoJSON with 139 optional properties.

It only has 1 CPU and low RAM at its disposal so please be gentle.

Summary
-------

[](#summary)

Convert [OpenGIS](https://www.ogc.org/standards/sfa) data loaded by [brick/geo](https://github.com/brick/geo) directly to [Mapbox Vector Tile 2.1](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) format. Focused on frequent source data changes delivery with the lowest latency possible. Process data fast with [GEOS](https://libgeos.org) C/C++ library via [PHP integration](https://git.osgeo.org/gitea/geos/php-geos.git) with custom update trigger to fit your needs. Perform SRID transformation and Douglas-Peucker simplification faster than ever.

---

Additional: convert MVT tiles to SVG (debug purposes only, not designed for production). Install [meyfa/php-svg](https://github.com/meyfa/php-svg) to use this feature.

Motivation
----------

[](#motivation)

If you want to display current weather conditions or some moving objects on your map, it's good to be able to generate your tileset directly on receiving updates from data provider, for example when reading GeoJSON from HTTP API response. The bottleneck is usually encountered with the following:

- Necessity to use intermediate storage compatible with some 3rd-party utility for preparing MVT
- Generating tiles for large zoom levels
- Sharing update between server nodes, especially if it's stored in single [MBTiles](https://github.com/mapbox/mbtiles-spec) file. Of course, you can [generate tiles from your PostGIS database](https://github.com/mapbox/postgis-vt-util) which will allow for frequent source data update, but you'll probably have a hard time battling performance drops after each index update. So, with standard toolset you'll be forced to choose between low update latency and low response time. But it shouldn't be that way. This is where this library could help.

How is it faster
----------------

[](#how-is-it-faster)

Most likely your data doesn't always change in every tile. And even if it does, if you'll look into request distribution by zoom, you'll probably notice that most of generated tiles smaller than, for example, zoom 18, are rarely requested between data changes but take the most of update's time, so you may want to prioritize some tiles more than others. With enough flexibility it is possible to invalidate parts of previous result and process in advance only frequently requested scales, leaving the rest to on-demand processing and updating MVT cache only on HTTP-request. With this library you'll be able to implement tight integration with the specific update scenario and minimize redundant calculations with custom update pipeline. Also, since [GEOS](https://libgeos.org)functions can be called directly, it's much easier to scale.

Installation
------------

[](#installation)

`composer require heymoon/vector-tile-data-provider`

You must explicitly generate protobuf classes from your project root:

`protoc --proto_path=./vendor/heymoon/vector-tile-data-provider/proto --php_out=./vendor/heymoon/vector-tile-data-provider/proto/gen ./vendor/heymoon/vector-tile-data-provider/proto/vector_tile.proto`

Install `php-geos` and `php-protobuf` extensions for best performance. Example Dockerfile for [Alpine 3.16 with PHP 8.1](https://hub.docker.com/layers/library/php/8.1-alpine3.16/images/sha256-298daac152760e2510ff283b0785c8feef72a2b134b27af918a80e40f26c1bb8):

```
FROM php:8.1-alpine3.16
RUN apk add --no-cache --virtual .build-deps \
    $PHPIZE_DEPS \
    geos-dev \
    git
RUN apk add --no-cache protoc geos
RUN pecl install protobuf \
    && docker-php-ext-enable protobuf \
	&& git clone https://git.osgeo.org/gitea/geos/php-geos.git /usr/src/php/ext/geos && cd /usr/src/php/ext/geos && \
	./autogen.sh && ./configure && make && \
	echo "extension=/usr/src/php/ext/geos/modules/geos.so" > /usr/local/etc/php/conf.d/docker-php-ext-geos.ini
RUN apk del -f .build-deps && rm -rf /tmp/* /var/cache/apk/*
# run "composer install" and then...
RUN protoc --proto_path=./vendor/heymoon/vector-tile-data-provider/proto --php_out=./vendor/heymoon/vector-tile-data-provider/proto/gen ./vendor/heymoon/vector-tile-data-provider/proto/vector_tile.proto
```

Provides
--------

[](#provides)

- `HeyMoon\VectorTileDataProvider\Entity\Source` and `Entity\SourceProxy` (storing geometries as WKB until evaluated) instances initialized by `HeyMoon\VectorTileDataProvider\Factory\SourceFactory` for easy data load from `Brick\Geo\IO\GeoJSON\FeatureCollection` or manually populated `Brick\Geo\Geometry` objects.
- `HeyMoon\VectorTileDataProvider\Service\SpatialService` for cheap spatial system transformation.
- `HeyMoon\VectorTileDataProvider\Service\GridService` and resulting `HeyMoon\VectorTileDataProvider\Entity\Grid` instance for filtering geometries visible only in particular tile and assigned to particular thread (threading can be achieved through providing filter callback function in `GridService::getGrid` to skip tiles based on position). This operation is the most demanding of RAM, but could be completed much faster than full result generation.
- `HeyMoon\VectorTileDataProvider\Service\TileService` for [Mapbox Vector Tile 2.1](https://github.com/mapbox/vector-tile-spec/tree/master/2.1) generation, presumably in `Grid::iterate` callback or HTTP request, reading required geometries from pre-saved `GridService` groups. Geometry simplification is performed only on `TileService::getTileMVT`.
- `HeyMoon\VectorTileDataProvider\Service\ExportService` for basic export to `.mvt`, to serve tileset as static files via NGINX, or `.svg` for result preview.
- `HeyMoon\VectorTileDataProvider\Factory\TileFactory` for parsing and merging ready vector tiles.

Spatial systems
---------------

[](#spatial-systems)

By default, grid is expected to be aligned with the [Web Mercator projection](https://en.wikipedia.org/wiki/Web_Mercator_projection), which is most likely different from your original data source spatial reference system. In order to process inputs with arbitrary SRID, library includes custom implementation of spatial transformation engine in `HeyMoon\VectorTileDataProvider\Service\SpatialService` (since SRID transformation is unsupported by php-geos and has performance issues in PostGIS). Following geometries are currently supported out-of-the-box:

- SRID 3857 (aka [Web Mercator](https://en.wikipedia.org/wiki/Web_Mercator_projection)mentioned earlier).
- SRID 4326 (aka [WGS 84](https://en.wikipedia.org/wiki/World_Geodetic_System#1984_version), most commonly used, default for GeoJSON [according to RFC 7946](https://www.rfc-editor.org/rfc/rfc7946.html)).

Additional projections can be described as subclass of `SpatialProjectionInterface` and passed in `supports` function of a new class extended from `AbstractProjectionRegistry`. Projection class should implement conversion of point coordinates on 2D surface from WGS 84 to the required spatial system and the reverse transformation function.

Example usage in Symfony:
-------------------------

[](#example-usage-in-symfony)

### DI configuration:

[](#di-configuration)

```
services:
  Brick\Geo\IO\GeoJSONReader: ~
  Brick\Geo\Engine\GeometryEngine:
    class: 'Brick\Geo\Engine\GEOSEngine'
  HeyMoon\VectorTileDataProvider\Contract\GeometryCollectionFactoryInterface:
    class: 'HeyMoon\VectorTileDataProvider\Factory\GeometryCollectionFactory'
  HeyMoon\VectorTileDataProvider\Contract\SourceFactoryInterface:
    class: 'HeyMoon\VectorTileDataProvider\Factory\SourceFactory'
  HeyMoon\VectorTileDataProvider\Contract\ProjectionRegistryInterface:
    class: 'HeyMoon\VectorTileDataProvider\Registry\BasicProjectionRegistry'
  HeyMoon\VectorTileDataProvider\Contract\ExportFormatInterface:
    class: 'HeyMoon\VectorTileDataProvider\Registry\ExportFormatRegistry'
  HeyMoon\VectorTileDataProvider\Contract\SpatialServiceInterface:
    class: 'HeyMoon\VectorTileDataProvider\Service\SpatialService'
  HeyMoon\VectorTileDataProvider\Contract\GridServiceInterface:
    class: 'HeyMoon\VectorTileDataProvider\Service\GridService'
  HeyMoon\VectorTileDataProvider\Contract\TileServiceInterface:
    class: 'HeyMoon\VectorTileDataProvider\Service\TileService'
  HeyMoon\VectorTileDataProvider\Contract\ExportServiceInterface:
    class: 'HeyMoon\VectorTileDataProvider\Service\ExportService'
```

### Action:

[](#action)

```
use Brick\Geo\IO\GeoJSONReader;
use Brick\Geo\Exception\GeometryException;
use HeyMoon\VectorTileDataProvider\Entity\TilePosition;
use HeyMoon\VectorTileDataProvider\Contract\SourceFactoryInterface;
use HeyMoon\VectorTileDataProvider\Contract\GridServiceInterface;
use HeyMoon\VectorTileDataProvider\Contract\TileServiceInterface;
use HeyMoon\VectorTileDataProvider\Contract\ExportServiceInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'app:export')]
class ExportCommand extends Command
{
    public function __construct(
        private readonly GeoJSONReader $geoJSONReader,
        private readonly SourceFactoryInterface $sourceFactory,
        private readonly GridServiceInterface $gridService,
        private readonly TileServiceInterface $tileService,
        private readonly ExportServiceInterface $exportService
    )
    {
        parent::__construct();
    }

    public function configure()
    {
        $this->addArgument('in', InputArgument::REQUIRED);
        $this->addArgument('out', InputArgument::REQUIRED);
        $this->addOption('zoom', 'z', InputOption::VALUE_OPTIONAL);
        $this->addOption('type', 't', InputOption::VALUE_OPTIONAL,
            'mvt for .mvt or svg for .svg');
    }

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $source = $this->sourceFactory->create();
        try {
            $source->addCollection('export', $this->geoJSONReader->read(file_get_contents($input->getArgument('in'))));
            $grid = $this->gridService->getGrid($source, $input->getOption('zoom') ?? 0);
            $path = $input->getArgument('out');
            $type = $input->getOption('type') ?? 'mvt';
            $grid->iterate(fn (TilePosition $position, array $data) =>
                $this->exportService->dump(
                    $this->tileService->getTileMVT($data, $position), "$path/$position.$type")
            );
        } catch (GeometryException $e) {
            $output->writeln("Data error: {$e->getMessage()}");
            return 1;
        }
        return 0;
    }
}
```

Tested with [Symfony 6.1](https://symfony.com/releases/6.1).

Export result
-------------

[](#export-result)

In real life scenario instead of dumping SVG files you would write data in your database of choice. For example, you could create [MBTiles](https://github.com/mapbox/mbtiles-spec) file readable by [tileserver-gl](https://github.com/maptiler/tileserver-gl). This is achievable with the SQLite database containing schema from [the latest specification description](https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md). Alternatively you could store only the grid partitioning result for on-demand generation in your own vector data source controller on PHP later (useful if faster data update is needed).

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance58

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~4 days

Total

16

Last Release

332d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b87e85a4fa81b0cf22cff5ede2eb41460a4bff02b8cd99d301fd8b7d23a8494?d=identicon)[heymoon](/maintainers/heymoon)

---

Top Contributors

[![egbuk](https://avatars.githubusercontent.com/u/1367406?v=4)](https://github.com/egbuk "egbuk (53 commits)")

---

Tags

mapbox-vector-tiletileserver-glvt-pbfmvtvt-pbf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/heymoon-vector-tile-data-provider/health.svg)

```
[![Health](https://phpackages.com/badges/heymoon-vector-tile-data-provider/health.svg)](https://phpackages.com/packages/heymoon-vector-tile-data-provider)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
