Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/longitude-one/wkb-parser
https://github.com/longitude-one/wkb-parser
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/longitude-one/wkb-parser
- Owner: longitude-one
- License: mit
- Created: 2024-04-01T16:38:29.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-27T07:02:05.000Z (10 months ago)
- Last Synced: 2024-09-13T11:36:36.552Z (5 months ago)
- Language: PHP
- Size: 200 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# longitude-one/wkb-parser


[](https://github.com/longitude-one/wkb-parser/blob/main/LICENSE)Parser library for 2D, 3D, and 4D Open Geospatial Consortium (OGC) WKB or PostGIS EWKB spatial object data.
[](https://github.com/longitude-one/wkb-parser/actions/workflows/ci.yml)
[](https://codeclimate.com/github/longitude-one/wkb-parser/maintainability)
[](https://codeclimate.com/github/longitude-one/wkb-parser/test_coverage)
[](https://github.com/longitude-one/wkb-parser/actions/workflows/ci.yml)
[](https://packagist.org/packages/longitude-one/wkb-parser)> [!NOTE]
> This package is the continuation of the now abandoned [creof/wkt-parser](https://github.com/creof/wkb-parser) package.## Installation
```bash
composer require longitude-one/wkb-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
$parser = new Parser($input);$value = $parser->parse();
```If many values need to be parsed, a single ```Parser``` instance can be used:
```php
$parser = new Parser();$value1 = $parser->parse($input1);
$value2 = $parser->parse($input2);
```### Input value
#### Encoding
The parser currently supports 3 WKB encodings:
- OGC v1.1
- OGC v1.2
- PostGIS EWKB#### Format
The parser supports a number of input formats:
- Binary string (as returned from database or ```pack('H*', $hexString)```)
- Bare hexadecimal text string (```'01010000003D0AD7A3.....'```)
- Hexadecimal test string prepended with ```x```, ```X```, ```0x```, or ```0X``` (```'0x01010000003D0AD7A3.....'```, etc.)## Return
The parser will return an array with the keys ```type```, ```value```, ```srid```, and ```dimension```.
- ```type``` string, the uppercase spatial object type (```POINT```, ```LINESTRING```, etc.) without any dimension.
- ```value``` array, contains integer or float values for points, nested arrays containing these based on spatial object type, or empty array for EMPTY geometry.
- ```srid``` integer, the SRID if present in EWKB value, ```null``` otherwise.
- ```dimension``` string, will contain ```Z```, ```M```, or ```ZM``` for the respective 3D and 4D objects, ```null``` otherwise.## Exceptions
The ```Reader``` and ```Parser``` will throw exceptions implementing interface ```CrEOF\Geo\WKB\Exception\ExceptionInterface```.
## References
- PostGIS EWKB - https://github.com/postgis/postgis/blob/master/doc/ZMSgeoms.txt
- OGC Simple Feature Access, Part 1 - http://www.opengeospatial.org/standards/sfa
- OGC Simple Feature Access, Part 2 - http://www.opengeospatial.org/standards/sfs