From 3b20986313b1c53f3f0aa40be34a1aa1284d1723 Mon Sep 17 00:00:00 2001 From: DaanDeSmedt Date: Fri, 19 Jul 2019 10:12:50 +0200 Subject: [PATCH 1/2] Initial commit Initial commit --- composer.json | 31 ++ src/PHPWKTAdapter/Lexer/WKTLexer.php | 129 +++++++ src/PHPWKTAdapter/WKTAdapter.php | 357 +++++++++++++++++++ tests/PHPWKTAdapter/WKTAdapterTest.php | 473 +++++++++++++++++++++++++ 4 files changed, 990 insertions(+) create mode 100644 composer.json create mode 100644 src/PHPWKTAdapter/Lexer/WKTLexer.php create mode 100644 src/PHPWKTAdapter/WKTAdapter.php create mode 100644 tests/PHPWKTAdapter/WKTAdapterTest.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..44c5fe9 --- /dev/null +++ b/composer.json @@ -0,0 +1,31 @@ +{ + "name": "daandesmedt/phpwktadapter", + "description": "Read and parse 2D, 3D and 4D WKT (Well Known Text) / EWKT (Extended Well-Known Text) object strings into geometry objects with this simple WKT PHP adapter library.", + "keywords": ["php", "string", "text", "geometry", "geography", "spatial", "wkt", "ewkt"], + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Daan De Smedt", + "email": "daan.de.smedt@hotmail.com" + } + ], + "autoload": { + "psr-4": { + "daandesmedt\\PHPWKTAdapter\\": "src/PHPWKTAdapter" + } + }, + "autoload-dev": { + "psr-4": { + "daandesmedt\\Tests\\PHPWKTAdapter\\": "tests/PHPWKTAdapter" + } + }, + "minimum-stability": "stable", + "require": { + "php": ">=7.0", + "doctrine/lexer": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + } +} diff --git a/src/PHPWKTAdapter/Lexer/WKTLexer.php b/src/PHPWKTAdapter/Lexer/WKTLexer.php new file mode 100644 index 0000000..9b12561 --- /dev/null +++ b/src/PHPWKTAdapter/Lexer/WKTLexer.php @@ -0,0 +1,129 @@ +token['value']; + } + + /** + * getLookaheadType + * + * @return int + */ + public function getLookaheadType() : int + { + return (int)$this->lookahead['type']; + } + +} \ No newline at end of file diff --git a/src/PHPWKTAdapter/WKTAdapter.php b/src/PHPWKTAdapter/WKTAdapter.php new file mode 100644 index 0000000..4ea62af --- /dev/null +++ b/src/PHPWKTAdapter/WKTAdapter.php @@ -0,0 +1,357 @@ +lexer = $this->lexer ?? new WKTLexer(); + return $this->lexer; + } + + + /** + * Set lexer + * + * @param WKTLexer $lexer + */ + public function setLexer(WKTLexer $lexer) : self + { + $this->lexer = $lexer; + return $this; + } + + + /** + * Read WKT + * + * @param string|null $wkt + * @return array + */ + public function read($wkt) + { + $this->reset(); + $this->wkt = $wkt; + + $this->getLexer()->setInput($this->wkt); + $this->getLexer()->moveNext(); + + if ($this->getLexer()->isNextToken(WKTLexer::T_SRID)) { + $this->srid = $this->getSRID(); + } + + $geometry = $this->getGeometry(); + $geometry['srid'] = $this->srid; + $geometry['dimension'] = $this->dimension; + + return $geometry; + } + + + /** + * Reset + */ + private function reset() + { + $this->srid = null; + $this->type = null; + $this->dimension = null; + $this->wkt = null; + } + + + /** + * Parse spatial geometry object + * + * @return array + */ + protected function getGeometry() + { + $type = $this->getType(); + $this->type = $type; + + if ($this->getLexer()->isNextTokenAny(array(WKTLexer::T_Z, WKTLexer::T_M, WKTLexer::T_ZM))) { + $this->match($this->getLexer()->getLookaheadType()); + $this->dimension = $this->getLexer()->getValue(); + } + + $this->match(WKTLexer::T_OPEN_PARENTHESIS); + $values = $this->$type(); + $this->match(WKTLexer::T_CLOSE_PARENTHESIS); + + return array( + 'type' => $type, + 'value' => $values + ); + } + + + /** + * Match lexer geo T_TYPE + * + * @return string + */ + private function getType() + { + $this->match(WKTLexer::T_TYPE); + return $this->getLexer()->getValue(); + } + + + /** + * Point parser + * + * @return array + */ + private function point() + { + if (null !== $this->dimension) { + return $this->getCoordinates(2 + strlen($this->dimension)); + } + + $values = $this->getCoordinates(2); + + for ($i = 3; $i <= 4 && $this->lexer->isNextTokenAny(array(WKTLexer::T_FLOAT, WKTLexer::T_INTEGER)); $i++) { + $values[] = $this->getCoordinate(); + } + + switch (count($values)) { + case 2: + $this->dimension = null; + break; + case 3: + $this->dimension = 'Z'; + break; + case 4: + $this->dimension = 'ZM'; + break; + } + + return $values; + } + + + /** + * Polygon spatial data type parser + * + * @return array + */ + private function polygon() + { + return $this->parsePointsCollection(); + } + + + /** + * Linestring spatial data type parser + * + * @return array + */ + private function linestring() + { + return $this->parsePoints(); + } + + + /** + * Multilinestring spatial data type parser + * + * @return array + */ + private function multilinestring() + { + return $this->parsePointsCollection(); + } + + + /** + * Multipoint spatial data type parser + * + * @return array + */ + private function multipoint() + { + return $this->parsePoints(); + } + + + /** + * Multipolygon spatial data type parser + * + * @return array + */ + private function multipolygon() + { + $this->match(WKTLexer::T_OPEN_PARENTHESIS); + $polygons = array($this->polygon()); + $this->match(WKTLexer::T_CLOSE_PARENTHESIS); + while ($this->getLexer()->isNextToken(WKTLexer::T_COMMA)) { + $this->match(WKTLexer::T_COMMA); + $this->match(WKTLexer::T_OPEN_PARENTHESIS); + $polygons[] = $this->polygon(); + $this->match(WKTLexer::T_CLOSE_PARENTHESIS); + } + return $polygons; + } + + + /** + * GeometryCollection spatial data type parser + * + * @return array + */ + private function geometrycollection() + { + $collection = array($this->getGeometry()); + while ($this->lexer->isNextToken(WKTLexer::T_COMMA)) { + $this->match(WKTLexer::T_COMMA); + $collection[] = $this->getGeometry(); + } + return $collection; + } + + + /** + * CircularString spatial data type parser + * + * @return array + */ + private function circularstring() + { + return $this->parsePoints(); + } + + + /** + * Parse point collection + * + * @return array + */ + private function parsePointsCollection() + { + $this->match(WKTLexer::T_OPEN_PARENTHESIS); + $points = $this->parsePoints(); + $this->match(WKTLexer::T_CLOSE_PARENTHESIS); + while ($this->getLexer()->isNextToken(WKTLexer::T_COMMA)) { + $this->match(WKTLexer::T_COMMA); + $this->match(WKTLexer::T_OPEN_PARENTHESIS); + $points[] = $this->parsePoints(); + $this->match(WKTLexer::T_CLOSE_PARENTHESIS); + } + return $points; + } + + + /** + * Parse points + * + * @return array + */ + private function parsePoints() + { + $points = array($this->point()); + while ($this->getLexer()->isNextToken(WKTLexer::T_COMMA)) { + $this->match(WKTLexer::T_COMMA); + $points[] = $this->point(); + } + return $points; + } + + + /** + * Get coordinates + * + * @return array + */ + private function getCoordinates($count) + { + $values = array(); + for ($i = 1; $i <= $count; $i++) { + $values[] = $this->getCoordinate(); + } + return $values; + } + + + /** + * Get coordinate + * + * @return int|float + */ + private function getCoordinate() + { + $this->match(($this->getLexer()->isNextToken(WKTLexer::T_FLOAT)) ? WKTLexer::T_FLOAT : WKTLexer::T_INTEGER); + return $this->getLexer()->getValue(); + } + + + /** + * Get SRID + * + * @return string + */ + private function getSRID() : string + { + $this->match(WKTLexer::T_SRID); + $this->match(WKTLexer::T_EQUALS); + $this->match(WKTLexer::T_INTEGER); + $srid = $this->getLexer()->getValue(); + $this->match(WKTLexer::T_SEMICOLON); + return $srid; + } + + + /** + * Match WKT token + * + * @throws + */ + private function match($token) + { + $lookaheadType = $this->getLexer()->getLookaheadType(); + if ($lookaheadType !== $token && ($token !== WKTLexer::T_TYPE || $lookaheadType <= WKTLexer::T_TYPE)) { + throw $this->doUnexpectedValue($this->getLexer()->getLiteral($token)); + } + $this->getLexer()->moveNext(); + } + + + /** + * Unexpected value exception + * + * @throws UnexpectedValueException + */ + private function doUnexpectedValue($expected) + { + $expected = sprintf('Expected %s, got', $expected); + $token = $this->getLexer()->lookahead; + $found = null === $this->getLexer()->lookahead ? 'end of string.' : sprintf('"%s"', $token['value']); + $message = sprintf( + 'Unexpected value exception at line 0, col %d: Error: %s %s in value "%s"', + isset($token['position']) ? $token['position'] : '-1', + $expected, + $found, + $this->wkt + ); + return new UnexpectedValueException($message); + } + +} \ No newline at end of file diff --git a/tests/PHPWKTAdapter/WKTAdapterTest.php b/tests/PHPWKTAdapter/WKTAdapterTest.php new file mode 100644 index 0000000..8f1cb7c --- /dev/null +++ b/tests/PHPWKTAdapter/WKTAdapterTest.php @@ -0,0 +1,473 @@ +assertInstanceOf(WKTLexer::class, $adapter->getLexer()); + $lexer = new WKTLexer(); + $this->assertEquals($lexer, $adapter->setLexer($lexer)->getLexer()); + } + + // FORMAT TESTS + public function testParsingIncorrectValue() + { + $this->doTest( + array( + 'read' => 'blablabla', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + public function testParsingIncorrect() + { + $this->doTest( + array( + 'read' => 'POINTT(30 10)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + + // DIMENSION + public function testDimensionDeclaredZM() + { + $this->doTest( + array( + 'read' => 'POINTZM(30 10 5 60)', + 'expected' => array( + 'srid' => null, + 'type' => 'POINT', + 'value' => array(30, 10, 5, 60), + 'dimension' => 'ZM' + ) + ) + ); + } + + public function testDimensionDeclaredM() + { + $this->doTest( + array( + 'read' => 'POINTM(30 10 5)', + 'expected' => array( + 'srid' => null, + 'type' => 'POINT', + 'value' => array(30, 10, 5), + 'dimension' => 'M' + ) + ) + ); + } + + + public function testDimensionDeclaredZ() + { + $this->doTest( + array( + 'read' => 'POINTZ(30 10 5)', + 'expected' => array( + 'srid' => null, + 'type' => 'POINT', + 'value' => array(30, 10, 5), + 'dimension' => 'Z' + ) + ) + ); + } + + public function testUnknownDimensionDeclared() + { + $this->doTest( + array( + 'read' => 'POINTP(30 10 5)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + + + // SRID + public function testWithSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;POINT(30 10)', + 'expected' => array( + 'srid' => 31370, + 'type' => 'POINT', + 'value' => array(30, 10), + 'dimension' => null + ) + ) + ); + } + + public function testWithFaultySRID() + { + $this->doTest( + array( + 'read' => 'SRID=3137A0;POINT(30 10)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + $this->doTest( + array( + 'read' => 'SRIDa=31370;POINT(30 10)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + + // POINT + public function testPoint() + { + $this->doTest( + array( + 'read' => 'POINT(30 10)', + 'expected' => array( + 'srid' => null, + 'type' => 'POINT', + 'value' => array(30, 10), + 'dimension' => null + ) + ) + ); + } + + public function testPointWithIncorrectCoordinatesFormat() + { + $this->doTest( + array( + 'read' => 'POINT(30, 10 10)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + $this->doTest( + array( + 'read' => 'POINT(30,)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + $this->doTest( + array( + 'read' => 'POINT(,)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + public function testPointWithIncorrectCoordinates() + { + $this->doTest( + array( + 'read' => 'POINT(30 10 10)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + $this->doTest( + array( + 'read' => 'POINT(30)', + 'expectedException' => 'UnexpectedValueException' + ) + ); + $this->doTest( + array( + 'read' => 'POINT()', + 'expectedException' => 'UnexpectedValueException' + ) + ); + } + + // POLYGON + public function testPolygon() + { + $this->doTest( + array( + 'read' => 'POLYGON((0 0,30 40,10 20,0 10,0 0))', + 'expected' => array( + 'srid' => null, + 'type' => 'POLYGON', + 'value' => array( + array(0, 0), + array(30, 40), + array(10, 20), + array(0, 10), + array(0, 0) + ), + 'dimension' => null + ) + ) + ); + } + + + public function testPolygonWithSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;POLYGON((0 0,30 40,10 20,0 10,0 0))', + 'expected' => array( + 'srid' => 31370, + 'type' => 'POLYGON', + 'value' => array( + array(0, 0), + array(30, 40), + array(10, 20), + array(0, 10), + array(0, 0) + ), + 'dimension' => null + ) + ) + ); + } + + + // LINESTRING + public function testLineString() + { + $this->doTest( + array( + 'read' => 'LINESTRING(30 10, 10 30, 40 40)', + 'expected' => array( + 'srid' => null, + 'type' => 'LINESTRING', + 'value' => array( + array(30, 10), + array(10, 30), + array(40, 40) + ), + 'dimension' => null + ) + ) + ); + } + + + public function testLineStringWithSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;LINESTRING(30 10, 10 30, 40 40)', + 'expected' => array( + 'srid' => 31370, + 'type' => 'LINESTRING', + 'value' => array( + array(30, 10), + array(10, 30), + array(40, 40) + ), + 'dimension' => null + ) + ) + ); + } + + + // MULTIPOINT + public function testMultiPoint() + { + $this->doTest( + array( + 'read' => 'MULTIPOINT(0 10,10 10,10 20,10 30)', + 'expected' => array( + 'srid' => null, + 'type' => 'MULTIPOINT', + 'value' => array( + array(0, 10), + array(10, 10), + array(10, 20), + array(10, 30) + ), + 'dimension' => null + ) + ) + ); + } + + + public function testMultiPointWithSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;MULTIPOINT(0 10,10 10,10 20,10 30)', + 'expected' => array( + 'srid' => 31370, + 'type' => 'MULTIPOINT', + 'value' => array( + array(0, 10), + array(10, 10), + array(10, 20), + array(10, 30) + ), + 'dimension' => null + ) + ) + ); + } + + + // MULTILINESTRING + public function testMultiLinestring() + { + $this->doTest( + array( + 'read' => 'MULTILINESTRING((0 0,10 0,10 10,0 10))', + 'expected' => array( + 'srid' => null, + 'type' => 'MULTILINESTRING', + 'value' => array( + array(0, 0), + array(10, 0), + array(10, 10), + array(0, 10) + ), + 'dimension' => null + ) + ) + ); + } + + + public function testMultiLinestringWithSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;MULTILINESTRING((0 0,10 0,10 10,0 10))', + 'expected' => array( + 'srid' => 31370, + 'type' => 'MULTILINESTRING', + 'value' => array( + array(0, 0), + array(10, 0), + array(10, 10), + array(0, 10) + ), + 'dimension' => null + ) + ) + ); + } + + + // MULTIPOLYGON + public function testMultiPolygon() + { + $this->doTest( + array( + 'read' => 'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', + 'expected' => array( + 'srid' => null, + 'type' => 'MULTIPOLYGON', + 'value' => array( + array( + array(30, 20), + array(45, 40), + array(10, 40), + array(30, 20) + ), + array( + array(15, 5), + array(40, 10), + array(10, 20), + array(5, 10), + array(15, 5) + ) + ), + 'dimension' => null + ) + ) + ); + } + + + public function testMultilinestringSRID() + { + $this->doTest( + array( + 'read' => 'SRID=31370;MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))', + 'expected' => array( + 'srid' => 31370, + 'type' => 'MULTIPOLYGON', + 'value' => array( + array( + array(30, 20), + array(45, 40), + array(10, 40), + array(30, 20) + ), + array( + array(15, 5), + array(40, 10), + array(10, 20), + array(5, 10), + array(15, 5) + ) + ), + 'dimension' => null + ) + ) + ); + } + + + // GEOMETRYCOLLECTION + public function testGeometryCollection() + { + $this->doTest( + array( + 'read' => 'SRID=31370;GEOMETRYCOLLECTION(POINT(10 20),LINESTRING(30 10, 10 30, 40 40))', + 'expected' => array( + 'srid' => 31370, + 'type' => 'GEOMETRYCOLLECTION', + 'value' => array( + array( + 'type' => 'POINT', + 'value' => array(10, 20) + ), + array( + 'type' => 'LINESTRING', + 'value' => array( + array(30, 10), + array(10, 30), + array(40, 40) + ) + ) + ), + 'dimension' => null + ) + ) + ); + } + + private function doTest($test) + { + $adapter = new WKTAdapter(); + if (isset($test['expectedException'])) { + $this->expectException($test['expectedException']); + } + $response = $adapter->read($test['read']); + if (!isset($test['expectedException'])) { + $this->assertEquals($test['expected'], $response); + } + } + +} \ No newline at end of file From c90b9bc3569b410d9d96f3ebcba309c43e1b1570 Mon Sep 17 00:00:00 2001 From: DaanDeSmedt Date: Fri, 19 Jul 2019 11:35:48 +0200 Subject: [PATCH 2/2] Added meta Added README / LICENSE / EXAMPLES --- LICENSE | 21 +++++++++ README.md | 94 +++++++++++++++++++++++++++++++++++++++++ examples/WKTAdapter.php | 81 +++++++++++++++++++++++++++++++++++ phpunit.xml | 18 ++++++++ 4 files changed, 214 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 examples/WKTAdapter.php create mode 100644 phpunit.xml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f6f19e3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Daan De Smedt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9672fa7 --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +PHPWKTParser +=============== + +Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems. + + +EWKT (Extended Well-Known Text), a PostGIS-specific format that includes the spatial reference system identifier (SRID) and up to 4 ordinate values (XYZM), is also supported (ex: `SRID=31370;POINT(44 60)`). + + +`PHPWKTParser` provides a simple usage helper class to read WKT and EWKT and parse this text representation to a workable PHP array holding the parsed WKT/EWKT definition. Read and parse 2D, 3D and 4D WKT (Well Known Text) / EWKT (Extended Well-Known Text) object strings into geometry objects with this simple WKT PHP adapter library. + + + +## Installation + +Install the package through [composer](http://getcomposer.org): + +``` +composer require daandesmedt/phpwktadapter +``` + +Make sure, that you include the composer [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading) somewhere in your codebase. + + +## Supported geometry + +| Geometry Type | Example | +| --- | --- | +| POINT | POINT(30 10) | +| LNESTRING | LINESTRING(30 10, 10 30, 40 40) | +| POLYGON | POLYGON((0 0,10 0,10 10,0 10,0 0)) | +| MULTIPOINT | MULTIPOINTZM(0 0 10 10,10 0 0 0,10 10 0 0,20 20 0 10) | +| MULTILINESTRING | MULTILINESTRING((0 0,10 0,10 10,0 10)) | +| MULTIPOLYGON | MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20))) | +| GEOMETRYCOLLECTION | GEOMETRYCOLLECTION(POINT(10 20),LINESTRING(0 0,10 0)) | + + +## PHPWKTParser parsed and returned geometry array response + +The `read($wkt)` function of the `PHPWKTParser` adapter will return a associative array as representation of the parsed WKT/EWKT (in case of valid). + + +``` +array( + // the geometry object type + "type" => string, + // integer or float values for POINT - nested array (integer or float) for other geometry types + "value" => array, + // integer representing the EWKT SRID, null when not present + "srid" => integer | null, + // string (Z, M or ZM) representing the dimension, null when not present + "dimension" => string | null +) +``` + +## Working examples + +Working examples can be found in the `examples` folder. + + +## Sample usage + +```php +read('SRID=31370;POINT(30 10)'); +var_dump($res); +``` + +## Handling exceptions + +Invalid format in the specified WKT / EWKT will result in a `UnexpectedValueException` thrown by the `WKTAdapter` . + + +```php +read('SRID=31370;POINT(bad format)'); +} catch (UnexpectedValueException $e) { + var_dump($e->getMessage()); +} +``` \ No newline at end of file diff --git a/examples/WKTAdapter.php b/examples/WKTAdapter.php new file mode 100644 index 0000000..8d7bf75 --- /dev/null +++ b/examples/WKTAdapter.php @@ -0,0 +1,81 @@ +read('SRID=31370;POINT(bad format)'); +} catch (UnexpectedValueException $e) { + var_dump($e->getMessage()); +} + + +// POINT +// ######################################################### +$res = $adapter->read('SRID=31370;POINT(30 10)'); +$res = $adapter->read('SRID=31370;POINTZM(30 10 5 60)'); +$res = $adapter->read('SRID=31370;POINT ZM (30 10 5 60)'); +$res = $adapter->read('SRID=31370;POINTM(30 10 80)'); +$res = $adapter->read('SRID=31370;POINT M (30 10 80)'); +$res = $adapter->read('SRID=31370;POINT Z (30 10 80)'); + + +// POLYGON +// ######################################################### +$res = $adapter->read('SRID=31370;POLYGON((0 0,10 0,10 10,0 10,0 0))'); +var_dump($res); +exit; + +$res = $adapter->read('SRID=31370;POLYGON((0 0,10 0,10 10,0 10,0 0))'); +$res = $adapter->read('SRID=31370;POLYGONZM((0 0 0 1,10 0 0 1,10 10 0 1,0 10 0 1,0 0 0 1))'); +$res = $adapter->read('SRID=31370;POLYGONM((0 0 1,10 0 1,10 0 1,0 0 1,0 0 1))'); + + +// LINESTRING +// ######################################################### +$res = $adapter->read('SRID=31370;LINESTRING(30 10, 10 30, 40 40)'); +$res = $adapter->read('SRID=31370;LINESTRINGZM(15 15 0 0, 20 20 0 0)'); +$res = $adapter->read('SRID=31370;LINESTRINGM(15 15 0, 20 20 0)'); + + +// MULTIPOINT +// ######################################################### +$res = $adapter->read('SRID=31370;MULTIPOINT(0 10,10 10,10 20,10 30)'); +$res = $adapter->read('SRID=31370;MULTIPOINTZM(0 0 10 10,10 0 0 0,10 10 0 0,20 20 0 10)'); +$res = $adapter->read('SRID=31370;MULTIPOINTM(0 10 10,10 10 10,0 0 0,20 10 30)'); + + +// MULTILINESTRING +// ######################################################### +$res = $adapter->read('SRID=31370;MULTILINESTRING((0 0,10 0,10 10,0 10))'); +$res = $adapter->read('SRID=31370;MULTILINESTRING((0 0,10 0,10 10,0 10),(5 5,7 5,7 7,5 7))'); +$res = $adapter->read('SRID=31370;MULTILINESTRINGZM((0 0 10 10,10 0 0 0,10 10 0 0,20 20 0 10),(60 40 10 10,70 10 20 40))'); +$res = $adapter->read('SRID=31370;MULTILINESTRINGM((0 10 10,10 10 10,0 0 0,20 10 30))'); + + +// MULTIPOLYGON +// ######################################################### +$res = $adapter->read('SRID=31370;MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))'); +$res = $adapter->read('SRID=31370;MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))'); +$res = $adapter->read('SRID=31370;MULTIPOLYGONZM(((40 40 10 10, 20 45 10 10, 45 30 10 10, 40 40 10 10)), ((20 35 10 10, 10 30 10 10, 10 10 10 10, 30 5 10 10, 45 20 10 10, 20 35 10 10)))'); +$res = $adapter->read('SRID=31370;MULTIPOLYGONM(((40 40 10, 20 45 10, 45 30 10, 40 40 10)), ((20 35 10, 10 30 10, 10 10 10, 30 5 10, 45 20 10, 20 35 10)))'); + + +// GEOMETRYCOLLECTION +// ######################################################### +$res = $adapter->read('SRID=31370;GEOMETRYCOLLECTION(POINT(10 20),LINESTRING(0 0,10 0))'); +$res = $adapter->read('GEOMETRYCOLLECTION(POINT(10 20),POINT(0 10))'); +$res = $adapter->read('GEOMETRYCOLLECTIONM(POINT(10 20 0),POINT(10 0 10))'); +$res = $adapter->read('GEOMETRYCOLLECTIONZM(POINT(10 20 0 0),POINT(10 0 0 10))'); + + +// DUMP +// ######################################################### +var_dump($res); \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..8bc1fa7 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + + + tests/PHPWKTAdapter + + + + \ No newline at end of file