PHP code example of mbolli / php-geobuf
1. Go to this page and download the library: Download mbolli/php-geobuf library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mbolli / php-geobuf example snippets
File = './my.geojson';
$geobufFile = basename($jsonFile) . '.geobuf';
try {
// encodes a json string to geobuf
$geobufString = \MBolli\PhpGeobuf\Encoder::encode(
file_get_contents($jsonFile), // (string) a json string
6, // (int) precision: max number of digits after the decimal point in coordinates, 6 by default
2 // (int) dimensions: number of dimensions in coordinates, 2 by default.
);
// decodes a geobuf file to json
$jsonString = \MBolli\PhpGeobuf\Decoder::decodeToJson(
file_get_contents($geobufFile) // (string) expects a geobuf string
)
} catch (\MBolli\PhpGeobuf\GeobufException $e) {
var_dump($e);
} catch (\Throwable $e) {
var_dump($e);
}
bash
composer
bash
bin/protoc --proto_path=src --php_out=build src/geobuf.proto