longitude-one / spatial-types
This library implements PHP spatial types: their interfaces and their geometric and geographic classes.
Requires
- php: ^8.4
- ext-mbstring: *
- doctrine/deprecations: ^1.1.3
- longitude-one/geo-parser: ^4.1
- longitude-one/spatial-core: ^1.1
- symfony/validator: ^8.1
Requires (Dev)
- ext-pcov: *
- phpunit/phpunit: ^13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-13 10:08:45 UTC
README
PHP library providing spatial types and their geometric and geographic classes.
If you want to persist spatial data in a database, you should use the longitude-one/doctrine2-spatial package.
Current status
Installation
composer require longitude-one/spatial-types
Usage
use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\LineString; use LongitudeOne\SpatialTypes\Types\Dimension2\Geometry\Point; $point = new Point(1, 2); echo $point->getX(); // 1 echo $point->getY(); // 2 $lineString = new LineString([ new Point(1, 2, 4326), new Point(3, 4, 4326), new Point(5, 6, 4326), ], 4326); $lineString->getSrid(); // 4326
For the complete catalogue of concrete types, constructors, accessors, and mutability rules, see Instantiable spatial types.
Type class hierarchy
The following tree describes class inheritance in Types, rather than the
file layout. Intermediate abstract classes are hidden; only
AbstractSpatialType and instantiable classes are shown. {Dimension2, Dimension3m, Dimension3z, Dimension4zm} represents one branch for each listed
coordinate dimension and {Geometry, Geography} one concrete class for each
spatial model. For the complete hierarchy, including intermediate abstract
classes, see Type class hierarchy.
AbstractSpatialType
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Point
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\LineString
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Polygon
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\Triangle
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPoint
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiLineString
├── Dimension{2,3m,3z,4zm}\{Geometry,Geography}\MultiPolygon
├── Dimension{3z,4zm}\{Geometry,Geography}\PolyhedralSurface
├── Dimension{2,3m,3z,4zm}\Geometry\GeometryCollection
└── Dimension{2,3m,3z,4zm}\Geography\GeographyCollection
Types not yet available
CircularString, CompoundCurve, CurvePolygon, MultiCurve,
MultiSurface and TIN do not yet have
instantiable classes. See Instantiable spatial types
for the complete coverage matrix.
Immutability
Spatial values are immutable and safe to share: their coordinates, SRID, and
aggregate membership are set at construction time and never changed through
the public API. Use withCoordinates() with an immutable Value\Coordinates
value to represent another location, or withSpatialReference() to associate
the same coordinates with another declared reference. Both return new objects.
LineString, Polygon, Triangle, and PolyhedralSurface also provide
withArrayOfCoordinates() to create a new instance with replacement
coordinates. This preserves their family, dimension, and SRID without changing
the source object.
This prevents a value shared by other aggregates from silently changing them. See Immutability for the rationale, examples, and the complete contract.
Spatial reference system (SRS)
Every spatial object has a Reference\SpatialReference. Its legacy integer
projection remains available through getSrid(), while getSpatialReference()
preserves the optional authority (for example EPSG:4326). Constructors and
factories accept either a legacy integer or a SpatialReference instance.
All members of an aggregate must have exactly the same spatial reference
system, including the unnamed reference represented by identifier 0. It is
not a wildcard. Use withSpatialReference() (or the legacy withSrid()) only
to relabel coordinates; neither method performs a reprojection.
See Spatial reference systems for the strict aggregate rule, its ISO/IEC 13249-3 basis, and the distinction between declaring a reference and transforming coordinates.