Download the PHP package mbolli/php-geobuf without Composer
On this page you can find all versions of the php package mbolli/php-geobuf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mbolli/php-geobuf
More information about mbolli/php-geobuf
Files in mbolli/php-geobuf
Package php-geobuf
Short Description PHP library for the geobuf compact geospatial format
License ISC
Informations about the package php-geobuf
php-geobuf
PHP library for the geobuf compact geospatial format.
This is essentially a PHP port of the great pygeobuf.
Geobuf stores GeoJSON 6-8 times smaller and TopoJSON 2-3 times smaller. Depending on the $precision
attribute, lossless compression is possible. More information about Geobuf is available in the JS implementation or the Python implementation.
Quick size comparison: An example 745 kB GeoJSON was converted to a 90 kB Geobuf file – more than 8 times less.
Beware: Experimental state – it works for my purposes but there probably are some bugs.
Installation
Usage
The following methods are exposed:
Encoder
encode()
reads a JSON string. Returns a geobuf-encoded string- string
$dataJson
a JSON string
- string
encodeToFile()
reads a JSON string and writes to a file. Returns the filesize of the resulting file or false- string
$filePath
where to store the resulting geobuf file - string
$dataJson
a JSON string
- string
encodeFileToBufFile()
reads from a JSON file and writes to a file. Returns the filesize of the resulting file or false- string
$jsonFile
path to the JSON file - string
$geobufFile
where to store the resulting geobuf file
- string
encodeFileToBuf()
reads from a JSON file. Returns a geobuf-encoded string- string
$fileName
path to the JSON file
- string
All encoding methods support the following two non-mandatory arguments:
- int
$precision
max number of digits after the decimal point in coordinates, 6 by default (10 cm). - int
$dim
number of dimensions in coordinates, 2 by default.
Decoder
decodeToArray()
returns a PHP array- string
$encodedInput
geobuf input
- string
decodeFileToArray()
returns a PHP array- string
$fileName
path to the geobuf file
- string
decodeToJson()
returns a JSON string- string
$encodedInput
geobuf input
- string
decodeFileToJson()
returns a JSON string- string
$fileName
path to the geobuf file
- string
decodeFileToJsonFile()
writes to a file and returns the filesize of the resulting JSON file or false- string
$geobufFile
path to the geobuf file - string
$jsonFile
where to store the resulting JSON file
- string
Example
Contribute
Pull requests are encouraged. Code style is enforced by PHP-CS-Fixer:
If the PR is about the Encoder or Decoder, please add a test JSON to the tests/geojson
folder. The test suite will automatically pick it up and test it when executed.
Background: Proto compilation
Classes were generated by the proto compiler using this command:
Used was mapbox/geobuf proto file for proto3 compatibility and automated namespace generation.