Passed
Push — master ( 41a4af...bb1b1f )
by Swen
03:21
created

TWKB::getLineString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 3
nop 1
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