1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains the BinaryReader class. |
4
|
|
|
* For more information see the class description below. |
5
|
|
|
* |
6
|
|
|
* @author Peter Bathory <[email protected]> |
7
|
|
|
* @since 2016-02-18 |
8
|
|
|
* |
9
|
|
|
* This code is open-source and licenced under the Modified BSD License. |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
namespace geoPHP\Adapter; |
14
|
|
|
|
15
|
|
|
use geoPHP\Geometry\Geometry; |
16
|
|
|
use geoPHP\Geometry\Point; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* PHP Geometry <-> TWKB encoder/decoder |
20
|
|
|
* |
21
|
|
|
* "Tiny Well-known Binary is is a multi-purpose format for serializing vector geometry data into a byte buffer, |
22
|
|
|
* with an emphasis on minimizing size of the buffer." |
23
|
|
|
* @see https://github.com/TWKB/Specification/blob/master/twkb.md |
24
|
|
|
* |
25
|
|
|
* This implementation supports: |
26
|
|
|
* - reading and writing all geometry types (1-7) |
27
|
|
|
* - empty geometries |
28
|
|
|
* - extended precision (Z, M coordinates; custom precision) |
29
|
|
|
* Partially supports: |
30
|
|
|
* - bounding box: can read and write, but don't store readed boxes (API missing) |
31
|
|
|
* - size attribute: can read and write size attribute, but seeking is not supported |
32
|
|
|
* - ID list: can read and write, but API is completely missing |
33
|
|
|
*/ |
34
|
|
|
class TWKB implements GeoAdapter |
35
|
|
|
{ |
36
|
|
|
use TWKBReader, TWKBWriter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Point |
40
|
|
|
*/ |
41
|
|
|
protected $lastPoint; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array<string, int> mapping of geometry types to TWKB type codes |
45
|
|
|
*/ |
46
|
|
|
protected static $typeMap = [ |
47
|
|
|
Geometry::POINT => 1, |
48
|
|
|
Geometry::LINESTRING => 2, |
49
|
|
|
Geometry::POLYGON => 3, |
50
|
|
|
Geometry::MULTI_POINT => 4, |
51
|
|
|
Geometry::MULTI_LINESTRING => 5, |
52
|
|
|
Geometry::MULTI_POLYGON => 6, |
53
|
|
|
Geometry::GEOMETRY_COLLECTION => 7 |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|