Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replaces \d in with [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+) to support fl…
…oating point values
  • Loading branch information
opengisdev committed Feb 16, 2021
commit e51ca77ca02871d06477ef60a6fb12c0ff55a15d
4 changes: 2 additions & 2 deletions src/Geometries/MultiPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down
8 changes: 8 additions & 0 deletions tests/Geometries/MultiPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand Down