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

brick / geo / 13969988840

20 Mar 2025 01:03PM UTC coverage: 50.432% (-0.7%) from 51.179%
13969988840

push

github

BenMorel
Prepare for release

1867 of 3702 relevant lines covered (50.43%)

1140.21 hits per line

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

0.0
/src/Proxy/GeometryProxy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Proxy;
6

7
use Brick\Geo\Exception\GeometryIoException;
8
use Brick\Geo\Exception\CoordinateSystemException;
9
use Brick\Geo\Exception\InvalidGeometryException;
10
use Brick\Geo\Exception\UnexpectedGeometryException;
11
use Brick\Geo\Geometry;
12

13
/**
14
 * Proxy class for Geometry.
15
 *
16
 * @internal This class is not part of the public API and can change at any time.
17
 *           Please type-hint against Brick\Geo\Geometry in your projects.
18
 */
19
class GeometryProxy extends Geometry implements ProxyInterface
20
{
21
    /**
22
     * The WKT or WKB data.
23
     */
24
    private readonly string $proxyData;
25

26
    /**
27
     * `true` if WKB, `false` if WKT.
28
     */
29
    private readonly bool $isProxyBinary;
30

31
    /**
32
     * The SRID of the underlying geometry.
33
     */
34
    private readonly int $proxySrid;
35

36
    /**
37
     * The underlying geometry, or NULL if not yet loaded.
38
     */
39
    private ?Geometry $proxyGeometry = null;
40

41
    /**
42
     * @param string $data     The WKT or WKB data.
43
     * @param bool   $isBinary Whether the data is binary (true) or text (false).
44
     * @param int    $srid     The SRID of the geometry.
45
     */
46
    public function __construct(string $data, bool $isBinary, int $srid = 0)
47
    {
48
        $this->proxyData     = $data;
×
49
        $this->isProxyBinary = $isBinary;
×
50
        $this->proxySrid     = $srid;
×
51
    }
52

53
    /**
54
     * Loads the underlying geometry.
55
     *
56
     * @throws GeometryIoException         If the proxy data is not valid.
57
     * @throws CoordinateSystemException   If the resulting geometry contains mixed coordinate systems.
58
     * @throws InvalidGeometryException    If the resulting geometry is not valid.
59
     * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class.
60
     */
61
    private function load() : void
62
    {
63
        $this->proxyGeometry = $this->isProxyBinary
×
64
            ? Geometry::fromBinary($this->proxyData, $this->proxySrid)
×
65
            : Geometry::fromText($this->proxyData, $this->proxySrid);
×
66
    }
67

68
    public function isLoaded() : bool
69
    {
70
        return $this->proxyGeometry !== null;
×
71
    }
72

73
    public function getGeometry() : Geometry
74
    {
75
        if ($this->proxyGeometry === null) {
×
76
            $this->load();
×
77
        }
78

79
        return $this->proxyGeometry;
×
80
    }
81

82
    public function isProxyBinary() : bool
83
    {
84
        return $this->isProxyBinary;
×
85
    }
86

87
    public static function fromText(string $wkt, int $srid = 0) : Geometry
88
    {
89
        return new self($wkt, false, $srid);
×
90
    }
91

92
    public static function fromBinary(string $wkb, int $srid = 0) : Geometry
93
    {
94
        return new self($wkb, true, $srid);
×
95
    }
96

97
    public function srid() : int
98
    {
99
        return $this->proxySrid;
×
100
    }
101

102
    public function asText() : string
103
    {
104
        if (! $this->isProxyBinary) {
×
105
            return $this->proxyData;
×
106
        }
107

108
        if ($this->proxyGeometry === null) {
×
109
            $this->load();
×
110
        }
111

112
        return $this->proxyGeometry->asText();
×
113
    }
114

115
    public function asBinary() : string
116
    {
117
        if ($this->isProxyBinary) {
×
118
            return $this->proxyData;
×
119
        }
120

121
        if ($this->proxyGeometry === null) {
×
122
            $this->load();
×
123
        }
124

125
        return $this->proxyGeometry->asBinary();
×
126
    }
127

128

129
    public function dimension(): int
130
    {
131
        if ($this->proxyGeometry === null) {
×
132
            $this->load();
×
133
        }
134

135
        return $this->proxyGeometry->dimension();
×
136
    }
137

138
    public function coordinateDimension(): int
139
    {
140
        if ($this->proxyGeometry === null) {
×
141
            $this->load();
×
142
        }
143

144
        return $this->proxyGeometry->coordinateDimension();
×
145
    }
146

147
    public function spatialDimension(): int
148
    {
149
        if ($this->proxyGeometry === null) {
×
150
            $this->load();
×
151
        }
152

153
        return $this->proxyGeometry->spatialDimension();
×
154
    }
155

156
    public function geometryType(): string
157
    {
158
        if ($this->proxyGeometry === null) {
×
159
            $this->load();
×
160
        }
161

162
        return $this->proxyGeometry->geometryType();
×
163
    }
164

165
    public function geometryTypeBinary(): int
166
    {
167
        if ($this->proxyGeometry === null) {
×
168
            $this->load();
×
169
        }
170

171
        return $this->proxyGeometry->geometryTypeBinary();
×
172
    }
173

174
    public function isEmpty(): bool
175
    {
176
        if ($this->proxyGeometry === null) {
×
177
            $this->load();
×
178
        }
179

180
        return $this->proxyGeometry->isEmpty();
×
181
    }
182

183
    public function is3D(): bool
184
    {
185
        if ($this->proxyGeometry === null) {
×
186
            $this->load();
×
187
        }
188

189
        return $this->proxyGeometry->is3D();
×
190
    }
191

192
    public function isMeasured(): bool
193
    {
194
        if ($this->proxyGeometry === null) {
×
195
            $this->load();
×
196
        }
197

198
        return $this->proxyGeometry->isMeasured();
×
199
    }
200

201
    public function coordinateSystem(): \Brick\Geo\CoordinateSystem
202
    {
203
        if ($this->proxyGeometry === null) {
×
204
            $this->load();
×
205
        }
206

207
        return $this->proxyGeometry->coordinateSystem();
×
208
    }
209

210
    public function withSrid(int $srid): \Brick\Geo\Geometry
211
    {
212
        if ($this->proxyGeometry === null) {
×
213
            $this->load();
×
214
        }
215

216
        return $this->proxyGeometry->withSrid($srid);
×
217
    }
218

219
    public function toXy(): \Brick\Geo\Geometry
220
    {
221
        if ($this->proxyGeometry === null) {
×
222
            $this->load();
×
223
        }
224

225
        return $this->proxyGeometry->toXy();
×
226
    }
227

228
    public function withoutZ(): \Brick\Geo\Geometry
229
    {
230
        if ($this->proxyGeometry === null) {
×
231
            $this->load();
×
232
        }
233

234
        return $this->proxyGeometry->withoutZ();
×
235
    }
236

237
    public function withoutM(): \Brick\Geo\Geometry
238
    {
239
        if ($this->proxyGeometry === null) {
×
240
            $this->load();
×
241
        }
242

243
        return $this->proxyGeometry->withoutM();
×
244
    }
245

246
    public function withRoundedCoordinates(int $precision): \Brick\Geo\Geometry
247
    {
248
        if ($this->proxyGeometry === null) {
×
249
            $this->load();
×
250
        }
251

252
        return $this->proxyGeometry->withRoundedCoordinates($precision);
×
253
    }
254

255
    public function getBoundingBox(): \Brick\Geo\BoundingBox
256
    {
257
        if ($this->proxyGeometry === null) {
×
258
            $this->load();
×
259
        }
260

261
        return $this->proxyGeometry->getBoundingBox();
×
262
    }
263

264
    public function toArray(): array
265
    {
266
        if ($this->proxyGeometry === null) {
×
267
            $this->load();
×
268
        }
269

270
        return $this->proxyGeometry->toArray();
×
271
    }
272

273
    public function swapXy(): \Brick\Geo\Geometry
274
    {
275
        if ($this->proxyGeometry === null) {
×
276
            $this->load();
×
277
        }
278

279
        return $this->proxyGeometry->swapXy();
×
280
    }
281

282
    public function project(\Brick\Geo\Projector\Projector $projector): \Brick\Geo\Geometry
283
    {
284
        if ($this->proxyGeometry === null) {
×
285
            $this->load();
×
286
        }
287

288
        return $this->proxyGeometry->project($projector);
×
289
    }
290

291
    public function isIdenticalTo(\Brick\Geo\Geometry $that): bool
292
    {
293
        if ($this->proxyGeometry === null) {
×
294
            $this->load();
×
295
        }
296

297
        return $this->proxyGeometry->isIdenticalTo($that);
×
298
    }
299

300
}
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