Skip to content

Commit 0f94263

Browse files
committed
WKB parser now parses the SRID of the given WKB value.
1 parent eae31fa commit 0f94263

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Types/Geometry.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,23 @@ public static function getWKTClass($value)
7070

7171
public static function fromWKB($wkb)
7272
{
73-
// mysql adds 4 NUL bytes at the start of the binary
73+
$srid = substr($wkb, 0, 4);
74+
$srid = unpack('L', $srid)[1];
75+
7476
$wkb = substr($wkb, 4);
7577
$parser = new Parser(new Factory());
7678

77-
return $parser->parse($wkb);
79+
/** @var Geometry $parsed */
80+
$parsed = $parser->parse($wkb);
81+
82+
if ($srid >= 0 && $srid < 4000) {
83+
$parsed->setSrid($srid);
84+
}
85+
86+
return $parsed;
7887
}
7988

80-
public static function fromWKT($wkt, $srid = 0)
89+
public static function fromWKT($wkt, $srid = null)
8190
{
8291
$wktArgument = static::getWKTArgument($wkt);
8392

0 commit comments

Comments
 (0)