From 3f8ecd7f169bbc954742a8fe0f9f53d4a5be9988 Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 21:13:52 +0000 Subject: [PATCH 1/5] fixes multipoint fromwkt without nested parenthesis (default with geoserver st_astext), the testFromWKTWithoutInnerParentesis in tests/Geometries/MultiPointTest shows the error, this could probably be done with the preg_match_all but I'm not that good at regex --- src/Geometries/MultiPoint.php | 7 +++++++ tests/Geometries/MultiPointTest.php | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index c7e6805..85e548d 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -43,6 +43,13 @@ public static function fromWKT($wkt) public static function fromString($wktArgument) { + if (!strpos(trim($wktArgument), '(')) { + $points = explode(',', $wktArgument); + $wktArgument = implode(", ", array_map(function ($pair) { + return '(' . trim($pair) . ')'; + }, $points)); + }; + $matches = []; preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches); diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index bbecb02..0e5b16f 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,6 +16,14 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKTWithoutInnerParentesis() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testFromWKT3d() { $multipoint = MultiPoint::fromWKT('MULTIPOINT Z((1 1 1),(2 1 3),(2 2 2))'); From ab24f9fbcb9063c4f04baf7415fa72ea745410a7 Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 21:30:15 +0000 Subject: [PATCH 2/5] rename testFromWKTWithoutNestedParentesis --- tests/Geometries/MultiPointTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index 0e5b16f..88587e1 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,7 +16,7 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } - public function testFromWKTWithoutInnerParentesis() + public function testFromWKTWithoutNestedParentesis() { $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); $this->assertInstanceOf(MultiPoint::class, $multipoint); From 7cf7e58e37739259b76cac604158ab13d29c3adc Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 21:37:11 +0000 Subject: [PATCH 3/5] creates the test for 3D points without nested parentesis --- tests/Geometries/MultiPointTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index 88587e1..a8bd363 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -32,6 +32,14 @@ public function testFromWKT3d() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKT3dWithoutNestedParentesis() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT Z(1 1 1, 2 1 3, 2 2 2)'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testToWKT() { $collection = [new Point(1, 1), new Point(1, 2), new Point(2, 2)]; From e51ca77ca02871d06477ef60a6fb12c0ff55a15d Mon Sep 17 00:00:00 2001 From: Etienne Date: Tue, 16 Feb 2021 22:56:11 +0000 Subject: [PATCH 4/5] replaces \d in with [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+) to support floating point values --- src/Geometries/MultiPoint.php | 4 ++-- tests/Geometries/MultiPointTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php index 85e548d..d7a7421 100644 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -45,13 +45,13 @@ public static function fromString($wktArgument) { if (!strpos(trim($wktArgument), '(')) { $points = explode(',', $wktArgument); - $wktArgument = implode(", ", array_map(function ($pair) { + $wktArgument = implode(',', array_map(function ($pair) { return '(' . trim($pair) . ')'; }, $points)); }; $matches = []; - preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches); + preg_match_all('/\(\s*([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+(\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+)?)\s*\)/', trim($wktArgument), $matches); if (count($matches) < 2) { return new static([]); diff --git a/tests/Geometries/MultiPointTest.php b/tests/Geometries/MultiPointTest.php index a8bd363..6f24f85 100644 --- a/tests/Geometries/MultiPointTest.php +++ b/tests/Geometries/MultiPointTest.php @@ -16,6 +16,14 @@ public function testFromWKT() $this->assertEquals(3, $multipoint->count()); } + public function testFromWKTWithFloatingPoint() + { + $multipoint = MultiPoint::fromWKT('MULTIPOINT((1.0 1.0),(2.0 1.0),(2.0 2.0))'); + $this->assertInstanceOf(MultiPoint::class, $multipoint); + + $this->assertEquals(3, $multipoint->count()); + } + public function testFromWKTWithoutNestedParentesis() { $multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)'); From 413f155d1d2d8cad198e8ba9f6852d43ef269bd0 Mon Sep 17 00:00:00 2001 From: Etienne Date: Wed, 12 Jan 2022 13:50:52 +0000 Subject: [PATCH 5/5] Adds use InvalidArgumentException to Geometries/MutltiPoint --- src/Geometries/MultiPoint.php | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 src/Geometries/MultiPoint.php diff --git a/src/Geometries/MultiPoint.php b/src/Geometries/MultiPoint.php old mode 100644 new mode 100755 index d7a7421..c94fbc1 --- a/src/Geometries/MultiPoint.php +++ b/src/Geometries/MultiPoint.php @@ -1,6 +1,7 @@