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
Next Next commit
fixes multipoint fromwkt without nested parenthesis (default with geo…
…server 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
  • Loading branch information
opengisdev committed Feb 16, 2021
commit 3f8ecd7f169bbc954742a8fe0f9f53d4a5be9988
7 changes: 7 additions & 0 deletions src/Geometries/MultiPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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 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))');
Expand Down