longitude-one / doctrine-spatial
Doctrine multi-platform support for spatial types and functions, compliant with Doctrine 2.19, 3.1, and dev ones (3.2 and 4.0).
Requires
- php: ^8.1
- ext-mbstring: *
- doctrine/orm: ^2.19|^3.1
- longitude-one/geo-parser: ^3.0.1
- longitude-one/wkb-parser: ^3.0.0
- longitude-one/wkt-parser: ^3.0.0
Requires (Dev)
- cache/array-adapter: ^1.1
- composer/semver: ^3.4
- dg/bypass-finals: ^1.3
- monolog/monolog: ^2.0
- phpunit/phpcov: ^9
- phpunit/phpunit: ^10.0
Replaces
This package is auto-updated.
Last update: 2026-07-19 07:26:28 UTC
README
Doctrine Spatial is a Doctrine ORM/DBAL extension for working with spatial data in PHP applications.
It provides support for spatial types and functions across multiple database engines, while keeping the integration close to Doctrine’s native entity and query model.
Why use it?
- Map geometry and geography data with Doctrine entities.
- Use spatial predicates and functions directly in DQL.
- Support PostgreSQL/PostGIS, MySQL, MariaDB, and SQL Server.
- Keep database-specific behavior explicit and well documented.
Current status
Documentation
The documentation covers installation, configuration, entity mapping, spatial queries, and contribution guidelines.
It also includes a glossary for the main spatial types and functions supported by the library.
Compatibility
PHP and Doctrine ORM
| doctrine-spatial | PHP | Doctrine ORM. | Status |
|---|---|---|---|
| 5.0 | 8.1+ | ^2.9, ^3.1 |
Stable (security fixes). |
| 5.1 | 8.2+ | ^2.19, ^3.1 |
Next version (development) |
| 5.2 | 8.3+ | ^2.19, ^3.1 |
Slated for Jan 1, 2027. |
| 6.0 | 8.5+ | ^3.6, ^4.x-dev |
In development. |
Security fixes follow the PHP support roadmap.
Database compatibility
The versions below reflect the database stack used for the test matrix.
| doctrine-spatial | MySQL. | MariaDB | PostgreSQL | PostGIS | SQL Server | Status |
|---|---|---|---|---|---|---|
| 5.0 | 5.7, 8.0 | 10.6 | 18 | 3.6 | ❌ | Stable (security fixes). |
| 5.1 | 8.4 | 10.11 | 18 | 3.6 | 2017 | Next version (development) |
| 5.2 | 8.4 | 10.11 | 18 | 3.6 | 2017 | Next version (development) |
| 6.0 | 8.4 | 10.11 | 18 | 3.6 | 2017 | in development. |
Known limitations
longitude-one/doctrine-spatial cannot currently store the SRID on MySQL or SQL Server. Internally, the extension uses Well-Known Text (WKT) to bridge database values, but this does not allow both WKT and SRID to be passed together through Doctrine’s persistence model. Extended Well-Known Text (EWKT) solves this for PostGIS, but it is not supported by other database engines.
This limitation can be worked around in practice by using the spatial functions ST_SetSRID and ST_SRID when needed, so the SRID can still be handled at the query level even if it is not persisted directly with the value.
Project origins
This library was originally created by Derek J. Lambert. Alexandre Tranchant later forked it from creof/doctrine-spatial after the original project appeared to be inactive since 2017.
Branch strategy
The repository follows a structured release model:
- main — Stable 5.0 releases with bug fixes and security updates.
- 5.1.x-dev — Controlled deprecations to ease the transition toward 6.0.
- 5.2.x-dev — This branch will drop compatibility with PHP 8.2 and the dedicated code path for it.
- 6.0.x-dev — Major changes and new features, potentially including breaking changes.
Contributing
Contributions, bug reports, and documentation improvements are welcome. Please refer to the documentation for the development workflow and test commands.