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 all commits
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
10 changes: 9 additions & 1 deletion src/Geometries/MultiPoint.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace MStaack\LaravelPostgis\Geometries;
use InvalidArgumentException;

class MultiPoint extends PointCollection implements GeometryInterface, \JsonSerializable
{
Expand Down Expand Up @@ -43,8 +44,15 @@ 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);
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
24 changes: 24 additions & 0 deletions tests/Geometries/MultiPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ 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)');
$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 All @@ -24,6 +40,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)];
Expand Down