• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / geo / 13872073621

15 Mar 2025 10:37AM UTC coverage: 51.165% (-36.2%) from 87.322%
13872073621

push

github

BenMorel
Add support for GeosOp in requireEngine()

1866 of 3647 relevant lines covered (51.17%)

1154.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.38
/src/IO/WKBReader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\IO;
6

7
use Brick\Geo\Exception\GeometryIOException;
8
use Brick\Geo\Geometry;
9
use Brick\Geo\IO\Internal\AbstractWKBReader;
10
use Brick\Geo\IO\Internal\WKBBuffer;
11
use Brick\Geo\IO\Internal\WKBGeometryHeader;
12
use Brick\Geo\Proxy;
13
use Override;
14

15
/**
16
 * Builds geometries out of Well-Known Binary strings.
17
 */
18
final class WKBReader extends AbstractWKBReader
19
{
20
    /**
21
     * @param string $wkb  The WKB to read.
22
     * @param int    $srid The optional SRID of the geometry.
23
     *
24
     * @throws GeometryIOException
25
     */
26
    public function read(string $wkb, int $srid = 0) : Geometry
27
    {
28
        $buffer = new WKBBuffer($wkb);
2,320✔
29
        $geometry = $this->readGeometry($buffer, $srid);
2,320✔
30

31
        if (! $buffer->isEndOfStream()) {
2,320✔
32
            throw GeometryIOException::invalidWKB('unexpected data at end of stream');
×
33
        }
34

35
        return $geometry;
2,320✔
36
    }
37

38
    /**
39
     * Introspects the given WKB and returns a proxy of the corresponding class.
40
     *
41
     * This prevents having to fully hydrate the underlying geometry object graph, while still returning an instance
42
     * of the correct geometry class.
43
     *
44
     * @return Geometry&Proxy\ProxyInterface
45
     *
46
     * @throws GeometryIOException
47
     */
48
    public function readAsProxy(string $wkb, int $srid = 0) : Geometry
49
    {
50
        $buffer = new WKBBuffer($wkb);
×
51
        $buffer->readByteOrder();
×
52
        $geometryHeader = $this->readGeometryHeader($buffer);
×
53

54
        return match ($geometryHeader->geometryType) {
×
55
            Geometry::POINT => new Proxy\PointProxy($wkb, true, $srid),
×
56
            Geometry::LINESTRING => new Proxy\LineStringProxy($wkb, true, $srid),
×
57
            Geometry::CIRCULARSTRING => new Proxy\CircularStringProxy($wkb, true, $srid),
×
58
            Geometry::COMPOUNDCURVE => new Proxy\CompoundCurveProxy($wkb, true, $srid),
×
59
            Geometry::POLYGON => new Proxy\PolygonProxy($wkb, true, $srid),
×
60
            Geometry::CURVEPOLYGON => new Proxy\CurvePolygonProxy($wkb, true, $srid),
×
61
            Geometry::MULTIPOINT => new Proxy\MultiPointProxy($wkb, true, $srid),
×
62
            Geometry::MULTILINESTRING => new Proxy\MultiLineStringProxy($wkb, true, $srid),
×
63
            Geometry::MULTIPOLYGON => new Proxy\MultiPolygonProxy($wkb, true, $srid),
×
64
            Geometry::GEOMETRYCOLLECTION => new Proxy\GeometryCollectionProxy($wkb, true, $srid),
×
65
            Geometry::POLYHEDRALSURFACE => new Proxy\PolyhedralSurfaceProxy($wkb, true, $srid),
×
66
            Geometry::TIN => new Proxy\TINProxy($wkb, true, $srid),
×
67
            Geometry::TRIANGLE => new Proxy\TriangleProxy($wkb, true, $srid),
×
68
            default => throw GeometryIOException::unsupportedWKBType($geometryHeader->geometryType),
×
69
        };
×
70
    }
71

72
    #[Override]
73
    protected function readGeometryHeader(WKBBuffer $buffer) : WKBGeometryHeader
74
    {
75
        $wkbType = $buffer->readUnsignedLong();
2,320✔
76

77
        if ($wkbType < 0 || $wkbType >= 4000) {
2,320✔
78
            throw GeometryIOException::unsupportedWKBType($wkbType);
×
79
        }
80

81
        $geometryType = $wkbType % 1000;
2,320✔
82
        $dimension = ($wkbType - $geometryType) / 1000;
2,320✔
83

84
        $hasZ = ($dimension === 1 || $dimension === 3);
2,320✔
85
        $hasM = ($dimension === 2 || $dimension === 3);
2,320✔
86

87
        return new WKBGeometryHeader($geometryType, $hasZ, $hasM);
2,320✔
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc