Skip to content

Commit 61c908e

Browse files
committed
WIP: empty point NaN
1 parent 7110c26 commit 61c908e

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

src/Io/EwkbReader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
*/
1818
final readonly class EwkbReader extends AbstractWkbReader
1919
{
20+
public function __construct(
21+
bool $supportEmptyPointWithNan = true,
22+
) {
23+
parent::__construct($supportEmptyPointWithNan);
24+
}
25+
2026
/**
2127
* @throws GeometryIoException
2228
*/

src/Io/EwkbWriter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace Brick\Geo\Io;
66

7+
use Brick\Geo\Exception\GeometryIoException;
78
use Brick\Geo\Geometry;
89
use Brick\Geo\Io\Internal\AbstractWkbWriter;
10+
use Brick\Geo\Io\Internal\WkbByteOrder;
911
use Brick\Geo\Io\Internal\WkbTools;
1012
use Override;
1113

@@ -14,6 +16,18 @@
1416
*/
1517
final readonly class EwkbWriter extends AbstractWkbWriter
1618
{
19+
/**
20+
* @param bool $supportEmptyPointWithNan Whether to support PostGIS-style empty points with NaN coordinates.
21+
*
22+
* @throws GeometryIoException
23+
*/
24+
public function __construct(
25+
?WkbByteOrder $byteOrder = null,
26+
bool $supportEmptyPointWithNan = true,
27+
) {
28+
parent::__construct($byteOrder, $supportEmptyPointWithNan);
29+
}
30+
1731
#[Override]
1832
protected function packHeader(Geometry $geometry, bool $outer) : string
1933
{

src/Io/Internal/AbstractWkbReader.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929
*/
3030
abstract readonly class AbstractWkbReader
3131
{
32+
/**
33+
* Whether to support PostGIS-style empty points with NaN coordinates.
34+
* This is not part of the WKB standard.
35+
* This will be disabled by default in WKB, but enabled by default in EWKB.
36+
*/
37+
private bool $supportEmptyPointWithNan;
38+
39+
public function __construct(
40+
bool $supportEmptyPointWithNan,
41+
) {
42+
$this->supportEmptyPointWithNan = $supportEmptyPointWithNan;
43+
}
44+
3245
/**
3346
* @throws GeometryIoException
3447
*/

src/Io/Internal/AbstractWkbWriter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@
2626
private WkbByteOrder $byteOrder;
2727
private WkbByteOrder $machineByteOrder;
2828

29+
/**
30+
* Whether to support PostGIS-style empty points with NaN coordinates.
31+
* This is not part of the WKB standard.
32+
* This will be disabled by default in WKB, but enabled by default in EWKB.
33+
*/
34+
private bool $supportEmptyPointWithNan;
35+
2936
/**
3037
* @throws GeometryIoException
3138
*/
32-
public function __construct(?WkbByteOrder $byteOrder = null)
33-
{
39+
public function __construct(
40+
?WkbByteOrder $byteOrder = null,
41+
bool $supportEmptyPointWithNan,
42+
) {
3443
$this->machineByteOrder = WkbTools::getMachineByteOrder();
3544
$this->byteOrder = $byteOrder ?? $this->machineByteOrder;
45+
$this->supportEmptyPointWithNan = $supportEmptyPointWithNan;
3646
}
3747

3848
/**

src/Io/WkbReader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
*/
1818
final readonly class WkbReader extends AbstractWkbReader
1919
{
20+
public function __construct(
21+
bool $supportEmptyPointWithNan = false,
22+
) {
23+
parent::__construct($supportEmptyPointWithNan);
24+
}
25+
2026
/**
2127
* @param string $wkb The WKB to read.
2228
* @param int $srid The optional SRID of the geometry.

src/Io/WkbWriter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@
44

55
namespace Brick\Geo\Io;
66

7+
use Brick\Geo\Exception\GeometryIoException;
78
use Brick\Geo\Geometry;
89
use Brick\Geo\Io\Internal\AbstractWkbWriter;
10+
use Brick\Geo\Io\Internal\WkbByteOrder;
911
use Override;
1012

1113
/**
1214
* Writes geometries in the WKB format.
1315
*/
1416
final readonly class WkbWriter extends AbstractWkbWriter
1517
{
18+
/**
19+
* @param bool $supportEmptyPointWithNan Whether to support PostGIS-style empty points with NaN coordinates.
20+
*
21+
* @throws GeometryIoException
22+
*/
23+
public function __construct(
24+
?WkbByteOrder $byteOrder = null,
25+
bool $supportEmptyPointWithNan = false,
26+
) {
27+
parent::__construct($byteOrder, $supportEmptyPointWithNan);
28+
}
29+
1630
#[Override]
1731
protected function packHeader(Geometry $geometry, bool $outer) : string
1832
{

0 commit comments

Comments
 (0)