https://github.com/longitude-one/wkt-parser
Hard fork of creof/wkt-parser
https://github.com/longitude-one/wkt-parser
Last synced: 2 months ago
JSON representation
Hard fork of creof/wkt-parser
- Host: GitHub
- URL: https://github.com/longitude-one/wkt-parser
- Owner: longitude-one
- License: mit
- Created: 2023-04-01T08:10:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-11T21:53:06.000Z (about 1 year ago)
- Last Synced: 2025-04-26T01:04:44.162Z (3 months ago)
- Language: PHP
- Size: 110 KB
- Stars: 7
- Watchers: 1
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Well-known text parser: longitude-one/wkt-parser


[](https://github.com/longitude-one/wkt-parser/blob/main/LICENSE)Lexer and parser library for 2D, 3D, and 4D WKT/EWKT spatial object strings.
[](https://github.com/longitude-one/wkt-parser/actions/workflows/ci.yml)
[](https://codeclimate.com/github/longitude-one/wkt-parser/maintainability)
[](https://codeclimate.com/github/longitude-one/wkt-parser/test_coverage)
[](https://coveralls.io/github/longitude-one/wkt-parser)
[](https://github.com/longitude-one/wkt-parser/actions/workflows/ci.yml)
[](https://packagist.org/packages/longitude-one/wkt-parser)> [!NOTE]
> This package is the continuation of the now abandoned [creof/wkt-parser](https://github.com/creof/wkt-parser) package.## Installation
```bash
composer require longitude-one/wkt-parser
```## Usage
There are two use patterns for the parser. The value to be parsed can be passed into the constructor, then parse()
called on the returned ```Parser``` object:```php
$input = 'POLYGON((0 0,10 0,10 10,0 10,0 0))';$parser = new Parser($input);
$value = $parser->parse();
```If many values need to be parsed, a single ```Parser``` instance can be used:
```php
$input1 = 'POLYGON((0 0,10 0,10 10,0 10,0 0))';
$input2 = 'POINT(0,0)';$parser = new Parser();
$value1 = $parser->parse($input1);
$value2 = $parser->parse($input2);
```## Return
The parser will return an array with the keys ```type```, ```value```, ```srid```, and ```dimension```.
- ```type``` string, the spatial object type (POINT, LINESTRING, etc.) without any dimension.
- ```value``` array, contains integer or float values for points, or nested arrays containing these based on spatial object type.
- ```srid``` integer, the SRID if EWKT value was parsed, ```null``` otherwise.
- ```dimension``` string, will contain ```Z```, ```M```, or ```ZM``` for the respective 3D and 4D objects, ```null``` otherwise.## Exceptions
The ```Lexer``` and ```Parser``` will throw exceptions implementing interface ```LongitudeOne\Geo\WKT\Exception\ExceptionInterface```.