longitude-one / spatial-encoder
This library encode any spatial interfaces into different binary or string format.
Fund package maintenance!
Requires
- php: ^8.4
- longitude-one/spatial-types: 0.0.1-alpha.2
Requires (Dev)
- jetbrains/phpstorm-attributes: ^1.1
- phpunit/phpunit: ^13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-13 23:43:03 UTC
README
Encode LongitudeOne spatial objects as text or binary data. Choose a strategy for the target format; both mutable and immutable objects are accepted.
Installation
composer require longitude-one/spatial-encoder:^1.0.0-RC.0
Usage
use LongitudeOne\SpatialEncoder\Encoder; use LongitudeOne\SpatialEncoder\Strategy\WktTextStrategy; use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\PointImmutable; $encoder = new Encoder(new WktTextStrategy()); echo $encoder->encode(new PointImmutable(1, 2, 4326)); // POINT (1 2)
Documentation
Read the official documentation.
See the strategy guide for format comparisons, examples and limitations.
Output formats
| Format | Strategy |
|---|---|
| WKT | WktTextStrategy |
| EWKT | EwktTextStrategy |
| ISO WKB | WkbBinaryStrategy |
| PostGIS EWKB | EwkbBinaryStrategy |
| MySQL internal binary | MySQLBinaryStrategy |
| GeoJSON | GeoJsonStrategy |
Encoding does not establish geometric validity. Validate before encoding when your application requires valid geometries. Coordinates are preserved without reprojection or axis swapping; supported types and dimensions depend on the strategy.
To add a format, implement StrategyInterface and pass it to Encoder.
Contributing
See Contributing for development setup, checks and contribution guidelines.