Search by

longitude-one / spatial-encoder

Alexandre-T

This library encode any spatial interfaces into different binary or string format.

Package info

github.com/longitude-one/spatial-encoder

pkg:composer/longitude-one/spatial-encoder

Fund package maintenance!

Ko Fi

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 6

1.0.0-RC.0 2026-09-22 19:03 UTC

This package is auto-updated.

Last update: 2026-11-13 23:43:03 UTC


README

Release PHP License CI Coverage Monthly downloads Documentation

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.