PHPackages                             artisanweblab/geojson - 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. artisanweblab/geojson

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

artisanweblab/geojson
=====================

GeoJSON implementation for PHP

01.5kPHP

Since Nov 4Pushed 3y agoCompare

[ Source](https://github.com/ArtisanWebLab/geojson)[ Packagist](https://packagist.org/packages/artisanweblab/geojson)[ RSS](/packages/artisanweblab-geojson/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

GeoJson PHP Library
===================

[](#geojson-php-library)

This library implements the [GeoJSON format specification](http://www.geojson.org/geojson-spec.html).

The `GeoJson` namespace includes classes for each data structure defined in the GeoJSON specification. Core GeoJSON objects include geometries, features, and collections. Geometries range from primitive points to more complex polygons. Classes also exist for bounding boxes and coordinate reference systems.

Installation
------------

[](#installation)

```
$ composer require "artisanweblab/geojson"

```

Usage
-----

[](#usage)

Classes in this library are immutable.

### GeoJson Constructors

[](#geojson-constructors)

Geometry objects are constructed using a single coordinates array. This may be a tuple in the case of a `Point`, an array of tuples for a `LineString`, etc. Constructors for each class will validate the coordinates array and throw an `InvalidArgumentException` on error.

More primitive geometry objects may also be used for constructing complex objects. For instance, a `LineString` may be constructed from an array of `Point` objects.

Feature objects are constructed from a geometry object, associative properties array, and an identifier, all of which are optional.

Feature and geometry collection objects are constructed from an array of their respective types.

### JSON Serialization

[](#json-serialization)

```
use ArtisanWebLab\GeoJson\Geometry\Point;
$point = Point::latLng([50.4019514, 30.3926095]);
$json = json_encode($point);
```

Printing the `$json` variable would yield (sans whitespace):

```
{
    "type": "Point",
    "coordinates": [30.3926095, 50.4019514]
}
```

### JSON Unserialization

[](#json-unserialization)

The core `GeoJson` class implements an internal `JsonUnserializable` interface, which defines a static factory method, `jsonUnserialize()`, that can be used to create objects from the return value of `json_decode()`.

```
use ArtisanWebLab\GeoJson\GeoJson;
$json = '{ "type": "Point", "coordinates": [30.3926095, 50.4019514] }';
$point = GeoJson::jsonUnserialize($json);
```

If errors are encountered during unserialization, an `UnserializationException`will be thrown by `jsonUnserialize()`. Possible errors include:

- Missing properties (e.g. `type` is not present)
- Unexpected values (e.g. `coordinates` property is not an array)
- Unsupported `type` string when parsing a GeoJson object or CRS

### Polyline Decoder

[](#polyline-decoder)

```
$origin = 'Маріїнський палац, 5A, вулиця Михайла Грушевського, Київ, 01008';
$destination = 'Києво-Печерська лавра, вулиця Лаврська, 15, Київ, 01015';

$request = Http::get('https://maps.googleapis.com/maps/api/directions/json', [
    'origin'      => $origin,
    'destination' => $destination,
    'language'    => 'ua',
    'key'         => '...',
]);
$response = $request->json();

$lineStrings = [];

foreach ($response['routes'] as $route) {
    $polylineFromGoogleMapsAPI = $route['overview_polyline']['points'];
    $lineStrings[] = GeoJson::decodePolyline($polylineFromGoogleMapsAPI);
}
```

```
{
    "type":"LineString",
    "coordinates":[
        [30.5385,50.4478],
        [30.53711,50.44677],
        //..
        [30.55699,50.43555],
        [30.55701,50.43553]
    ]
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ccbd6b66f4496f505930e8154d0858a3a63304907315ff409d6fcef678222d?d=identicon)[ArtisanWebLab](/maintainers/ArtisanWebLab)

---

Top Contributors

[![OleksandrWebLab](https://avatars.githubusercontent.com/u/20097205?v=4)](https://github.com/OleksandrWebLab "OleksandrWebLab (2 commits)")

### Embed Badge

![Health badge](/badges/artisanweblab-geojson/health.svg)

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

###  Alternatives

[obs/esdk-obs-php

OBS PHP SDK

58121.1k3](/packages/obs-esdk-obs-php)

PHPackages © 2026

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