longitude-one / spatial-decoder
Decode spatial data from various representations into SpatialInterface objects.
Fund package maintenance!
Requires
- php: ^8.4
- doctrine/lexer: ^3.0.2
- longitude-one/spatial-core: ^1.4.0
- longitude-one/spatial-types: ^1.0.0-RC.1
- symfony/options-resolver: ^5.4 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- ext-dom: *
- phpunit/phpunit: ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 20:52:58 UTC
README
Decode serialized spatial data into LongitudeOne spatial objects. Choose a strategy for the input format, then validate the resulting geometry explicitly when your application requires geometric validity.
Installation
composer require longitude-one/spatial-decoder:^1.0.0-RC.0
Requires PHP 8.4 or later and longitude-one/spatial-core ^1.4.0.
Composer installs the compatible dependencies automatically.
Usage
use LongitudeOne\SpatialDecoder\Decoder; use LongitudeOne\SpatialDecoder\Strategy\WktDecoderStrategy; $decoder = new Decoder(new WktDecoderStrategy()); $point = $decoder->decode('POINT (1 2)'); // $point->toArray() === [1, 2]
Documentation
Read the official documentation.
See the decoding guide for EWKT, EWKB, WKB geometries, curves, dimensions and unsupported types.
Input formats
Built-in strategies decode WKT and EWKT, plus XY, XYZ, XYM and XYZM Points, LineStrings and Polygons, MultiPoint, MultiLineString, MultiPolygon, CircularString, CompoundCurve, Triangle and nested GeometryCollection in raw WKB (both byte orders), including EMPTY geometries. PolyhedralSurface supports XYZ and XYZM only. Other WKB geometry types are not yet supported. EWKB supports the same types and dimensions, with optional SRIDs at every geometry header; see EWKB decoding for its limits. MySQL internal binary is not supported.
Decoding and geometric validation
By default, WKT, EWKT, WKB and EWKB produce immutable Geometry objects, including collection members, independently of the shared factory's mutable/immutable mode. See Strategy configuration to select Geography or mutable output.
The decoder checks syntax, numeric ordinates, dimensions and supported types. It preserves geometrically invalid structures such as unclosed polygon rings; decoding success does not establish geometric validity. Malformed representations still raise an exception. See the validation boundary.
Contributing
See Contributing for development setup, checks and contribution guidelines.