Skip to content

Commit

Permalink
Fix empty point behaviour in wkb, ewkb, and hexewkb formats
Browse files Browse the repository at this point in the history
(merges PR phayes#187)
  • Loading branch information
itamair committed Feb 4, 2023
1 parent 12cd124 commit 7de893d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/adapters/WKB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,11 @@ public function write(Geometry $geometry, $write_as_hex = FALSE) {

function writePoint($point) {
// Set the coords
if (!$point->isEmpty()) {
$wkb = pack('dd',$point->x(), $point->y());
return $wkb;
} else {
return '';
if ($point->isEmpty()) {
return pack('dd', NAN, NAN);
}

return pack('dd', $point->x(), $point->y());
}

function writeLineString($line) {
Expand Down
2 changes: 1 addition & 1 deletion lib/geometry/Point.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Point extends Geometry
public function __construct($x = NULL, $y = NULL, $z = NULL) {

// Check if it's an empty point
if ($x === NULL && $y === NULL) {
if (($x === NULL || is_nan($x)) && ($y === NULL || is_nan($y))) {
$this->coords = array(NULL, NULL);
$this->dimension = 0;
return;
Expand Down
Binary file added tests/input/empty_point.ewkb
Binary file not shown.

0 comments on commit 7de893d

Please sign in to comment.