PHPackages                             aeris/spatial - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aeris/spatial

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aeris/spatial
=============

Representations of spatial data

v1.3.1(10y ago)47.2k↓72.4%[1 issues](https://github.com/aerisweather/Spatial/issues)BSDPHP

Since Apr 6Pushed 10y ago10 watchersCompare

[ Source](https://github.com/aerisweather/Spatial)[ Packagist](https://packagist.org/packages/aeris/spatial)[ RSS](/packages/aeris-spatial/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (7)Used By (0)

Spatial
=======

[](#spatial)

Representations of spatial data.

Installation
============

[](#installation)

```
composer require aeris/spatial

```

Components
==========

[](#components)

GeometryConverter
-----------------

[](#geometryconverter)

The `GeometryConverter` component may be used to convert geometry data between different formats. The following conversions are currently supported:

- GeoJson Polygon to WKT
- GeoJson MultiPolygon to WKT

Additional conversions can be made by using `Geometry` objects directly, via the `ConvertibleGeometryInterface::FromArray()` and `ConvertibleGeometryInterface::toWkt()` methods (see [Geometry](#geometry) component documentation)

### Examples

[](#examples)

```
use Aeris\Spatial\GeometryConverter;

$geoJson = json_encode([
  'type' => 'Polygon',
  'coordinates' => [
    [
      [100, 0],
      [101, 0],
      [101, 1],
      [100, 1],
      [100, 0],
    ]
  ]
]);
$wkt = GeometryConverter::geoJsonToWkt($geoJson);

$this->assertEquals(
  'POLYGON((100 0,101 0,101 1,100 1,100 0))',
  $wkt
);
```

Geometry
--------

[](#geometry)

`Geometry` components are object representations of spatial data structures. Objects implementing `\Aeris\Spatial\Geometry\ConvertibleGeometryInterface` may be easily converted between array and WKT (string) formats using the `FromArray(array $data)` and `toWkt()` methods

Some `Geometry` components may implement additional conversion methods. For example, `\Aeris\Spatial\Geometry\MultiPolygon` implements a `FromFeatureCollection()` method, which makes it easy to convert a GeoJson feature collection to a `MultiPolygon` object.

### Examples

[](#examples-1)

The following example demonstrates converting a GeoJson FeatureCollection into a MultiPolygon object.

```
$geoJson = [
  'type' => 'FeatureCollection',
  'features' => [
    [
      'type' => 'Feature',
      'geometry' => [
        'type' => 'Polygon',
        'coordinates' => [
          [
            [100, 0],
            [100, 100],
            [0, 100],
            [0, 0],
            [100, 0],
          ]
        ]
      ],
    ],
    [
      'type' => 'Feature',
      'geometry' => [
        'type' => 'Polygon',
        'coordinates' => [
          [
            [200, 0],
            [200, 200],
            [0, 200],
            [0, 0],
            [200, 0]
          ]
        ]
      ]
    ]
  ],
];

$mPoly = MultiPolygon::FromFeatureCollection($geoJson);

$this->assertEquals([
  Polygon::FromArray([
    [
      [100, 0],
      [100, 100],
      [0, 100],
      [0, 0],
      [100, 0]
    ]
  ]),
  Polygon::FromArray([
    [
      [200, 0],
      [200, 200],
      [0, 200],
      [0, 0],
      [200, 0]
    ]
  ])
], $mPoly->getPolygons());
```

You could then use the MultiPolygon object to execute a MySql spatial query:

```
$myQuery = 'SELECT * FROM `places` ' .
 'WHERE ST_CONTAINS(GeomFromText(' . $mPoly->toWKT() . '), `places`.`point`)'
```

Util
----

[](#util)

The `Aeris\Spatial\Util` namespace contains some utility function for working with spatial components.

### `Util\bearing`

[](#utilbearing)

Returns the direction (in degrees) between two coordinates.

```
$minneapolis = new Coordinate(-93.251953125, 44.9336963896947);
$chicago = new Coordinate(-87.71484375, 41.80407814427237);

Util\bearing($minneapolis, $chicago); // 125.93766052151
Util\bearing($chicago, $minneapolis); // 309.74293632484
```

### `Util\compassDirection`

[](#utilcompassdirection)

Returns the compass rose direction between two coordinates.

```
$minneapolis = new Coordinate(-93.251953125, 44.9336963896947);
$edenPrarie = new Coordinate(-93.4768295288086, 44.85148787683413);

Util\compassDirection($minneapolis, $edenPrarie); // 'SW'
Util\compassDirection($edenPrarie, $minneapolis); // 'NE'
```

Possible return values:

- NNE
- NE
- ENE
- E
- ESE
- SE
- SSE
- S
- SSW
- SW
- WSW
- W
- WNW
- NW
- NNW
- N

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Total

6

Last Release

3958d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f62ce003cf97458c12d531fc991ed04bec11c735bba4c37cff0190221c1b53db?d=identicon)[eschwartz](/maintainers/eschwartz)

---

Top Contributors

[![four43](https://avatars.githubusercontent.com/u/517006?v=4)](https://github.com/four43 "four43 (5 commits)")[![eschwartz](https://avatars.githubusercontent.com/u/1153371?v=4)](https://github.com/eschwartz "eschwartz (2 commits)")

### Embed Badge

![Health badge](/badges/aeris-spatial/health.svg)

```
[![Health](https://phpackages.com/badges/aeris-spatial/health.svg)](https://phpackages.com/packages/aeris-spatial)
```

###  Alternatives

[incoming/incoming

Transform loose and complex input into consistent, strongly-typed data structures

21987.7k](/packages/incoming-incoming)[dudapiotr/zftable

Flexible tool to generate table

7531.2k](/packages/dudapiotr-zftable)[phonetworks/pho-lib-graph

A general purpose graph library in PHP

556.0k1](/packages/phonetworks-pho-lib-graph)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
