PHPackages                             clonix/geokit - 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. clonix/geokit

ActiveLibrary

clonix/geokit
=============

Geo-Toolkit for PHP

v2.0(5y ago)0101MITPHPPHP ^7.1

Since Jan 16Pushed 5y agoCompare

[ Source](https://github.com/maxiz22/geokit)[ Packagist](https://packagist.org/packages/clonix/geokit)[ Docs](https://github.com/jsor/geokit)[ RSS](/packages/clonix-geokit/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

Geokit
======

[](#geokit)

Geokit is a PHP toolkit to solve geo-related tasks like:

- Distance calculations.
- Heading, midpoint and endpoint calculations.
- Rectangular bounding box calculations.

[![Build Status](https://camo.githubusercontent.com/941ae9d7358d4fe5052d227ec5deda35b16db26a8893e1dcdf99ffb86a2780b4/68747470733a2f2f7472617669732d63692e6f72672f6a736f722f67656f6b69742e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/jsor/geokit?branch=master)[![Code Coverage](https://camo.githubusercontent.com/0a7b9165d6e787c46ad8ecc9625e48efb4bae380406cc3538866343a5c9127b0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a736f722f67656f6b69742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jsor/geokit/?branch=master)

- [Installation](#installation)
- [Reference](#reference)
    - [Math](#math)
        - [Distance calculations](#distance-calculations)
        - [Transformations](#transformations)
        - [Other calculations](#other-calculations)
    - [Distance](#distance)
    - [Position](#position)
    - [BoundingBox](#boundingbox)
    - [Polygon](#polygon)
- [License](#license)
- [Credits](#credits)

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

[](#installation)

Install the latest version with [Composer](https://getcomposer.org).

```
composer require geokit/geokit
```

Check the [Packagist page](https://packagist.org/packages/geokit/geokit) for all available versions.

Reference
---------

[](#reference)

### Math

[](#math)

A Math instance can be used to perform geographic calculations on Position and BoundingBox instances.

The [World Geodetic System 1984](http://en.wikipedia.org/wiki/World_Geodetic_System)(WGS84) is exclusively used as the coordinate reference system.

```
$math = new Geokit\Math();
```

#### Distance calculations

[](#distance-calculations)

A math instance provides two methods to calculate the distance between 2 points on the Earth's surface:

- `distanceHaversine(Geokit\Position $from, Geokit\Position $to)`: Calculates the approximate sea level great circle (Earth) distance between two points using the Haversine formula.
- `distanceVincenty(Geokit\Position $from, Geokit\Position $to)`: Calculates the geodetic distance between two points using the Vincenty inverse formula for ellipsoids.

```
$distance1 = $math->distanceHaversine($from, $to);
$distance2 = $math->distanceVincenty($from, $to);
```

Both methods return a [Distance](#distance) instance.

#### Transformations

[](#transformations)

The `circle()` method calculates a closed circle Polygon given a center, radius and steps for precision.

```
$circlePolygon = $math->circle(
    new Geokit\Position(8.50207515, 49.50042565),
    Geokit\Distance::fromString('5km'),
    32
);
```

#### Other calculations

[](#other-calculations)

Other useful methods are:

- `heading(Geokit\Position $from, Geokit\Position $to)`: Calculates the (initial) heading from the first point to the second point in degrees.
- `midpoint(Geokit\Position $from, Geokit\Position $to)`: Calculates an intermediate point on the geodesic between the two given points.
- `endpoint(Geokit\Position $start, float $heading, Geokit\Distance $distance)`: Calculates the destination point along a geodesic, given an initial heading and distance, from the given start point.

### Distance

[](#distance)

A Distance instance allows for a convenient representation of a distance unit of measure.

```
$distance = new Geokit\Distance(1000); // Defaults to meters
// or
$distance = new Geokit\Distance(1, Geokit\Distance::UNIT_KILOMETERS);

$meters = $distance->meters();
$kilometers = $distance->kilometers();
$miles = $distance->miles();
$yards = $distance->yards();
$feet = $distance->feet();
$inches = $distance->inches();
$nauticalMiles = $distance->nautical();
```

A Distance can also be created from a string with an optional unit.

```
$distance = Geokit\Distance::fromString('1000'); // Defaults to meters
$distance = Geokit\Distance::fromString('1000m');
$distance = Geokit\Distance::fromString('1km');
$distance = Geokit\Distance::fromString('100 miles');
$distance = Geokit\Distance::fromString('100 yards');
$distance = Geokit\Distance::fromString('1 foot');
$distance = Geokit\Distance::fromString('1 inch');
$distance = Geokit\Distance::fromString('234nm');
```

### Position

[](#position)

A `Position` is a fundamental construct representing a geographical position in `x` (or `longitude`) and `y` (or `latitude`) coordinates.

Note, that `x`/`y` coordinates are kept as is, while `longitude`/`latitude` are normalized.

- Longitudes range between -180 and 180 degrees, inclusive. Longitudes above 180 or below -180 are normalized. For example, 480, 840 and 1200 will all be normalized to 120 degrees.
- Latitudes range between -90 and 90 degrees, inclusive. Latitudes above 90 or below -90 are normalized. For example, 100 will be normalized to 80 degrees.

```
$position = new Geokit\Position(181, 91);

$x = $position->x(); // Returns 181.0
$y = $position->y(); // Returns 91.0
$longitude = $position->longitude(); // Returns -179.0, normalized
$latitude = $position->latitude(); // Returns 89.0, normalized
```

### BoundingBox

[](#boundingbox)

A BoundingBox instance represents a rectangle in geographical coordinates, including one that crosses the 180 degrees longitudinal meridian.

It is constructed from its left-bottom (south-west) and right-top (north-east) corner points.

```
$southWest = new Geokit\Position(2, 1);
$northEast = new Geokit\Position(2, 1);

$boundingBox = new Geokit\BoundingBox($southWest, $northEast);

$southWestPosition = $boundingBox->southWest();
$northEastPosition = $boundingBox->northEast();

$center = $boundingBox->center();

$span = $boundingBox->span();

$boolean = $boundingBox->contains($position);

$newBoundingBox = $boundingBox->extend($position);
$newBoundingBox = $boundingBox->union($otherBoundingBox);
```

With the `expand()` and `shrink()` methods, you can expand or shrink a BoundingBox instance by a distance.

```
$expandedBoundingBox = $boundingBox->expand(
    Geokit\Distance::fromString('10km')
);

$shrinkedBoundingBox = $boundingBox->shrink(
    Geokit\Distance::fromString('10km')
);
```

The `toPolygon()` method converts the BoundingBox to an equivalent Polygon instance.

```
$polygon = $boundingBox->toPolygon();
```

### Polygon

[](#polygon)

A Polygon instance represents a two-dimensional shape of connected line segments and may either be closed (the first and last point are the same) or open.

```
$polygon = new Geokit\Polygon([
    new Geokit\Position(0, 0),
    new Geokit\Position(1, 0),
    new Geokit\Position(1, 1)
]);

$closedPolygon = $polygon->close();

/** @var Geokit\Position $position */
foreach ($polygon as $position) {
}

$polygon->contains(Geokit\Position(0.5, 0.5)); // true

/** @var Geokit\BoundingBox $boundingBox */
$boundingBox = $polygon->toBoundingBox();
```

License
-------

[](#license)

Copyright (c) 2011-2019 Jan Sorgalla. Released under the [MIT License](LICENSE).

Credits
-------

[](#credits)

Geokit has been inspired and/or contains ported code from the following libraries:

- [OpenLayers](https://github.com/openlayers/openlayers)
- [GeoPy](https://github.com/geopy/geopy)
- [scalaz-geo](https://github.com/scalaz/scalaz-geo)
- [geojs](http://code.google.com/p/geojs)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.5% 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 ~455 days

Recently: every ~469 days

Total

7

Last Release

2134d ago

Major Versions

v0.1.0 → v1.0.02015-03-27

1.x-dev → v2.02020-07-10

PHP version history (3 changes)v0.1.0PHP &gt;=5.3.0

v1.0.0PHP &gt;=5.3.3

v2.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8eeda1000359576578d5d6bdee36f4803558ee2d2a29d96d197e683ae620d367?d=identicon)[clonix](/maintainers/clonix)

---

Top Contributors

[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (237 commits)")[![codigowww](https://avatars.githubusercontent.com/u/46723539?v=4)](https://github.com/codigowww "codigowww (1 commits)")[![bamarni](https://avatars.githubusercontent.com/u/1205386?v=4)](https://github.com/bamarni "bamarni (1 commits)")[![luka-dev](https://avatars.githubusercontent.com/u/43535027?v=4)](https://github.com/luka-dev "luka-dev (1 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![rossity](https://avatars.githubusercontent.com/u/21282907?v=4)](https://github.com/rossity "rossity (1 commits)")[![koenpunt](https://avatars.githubusercontent.com/u/351038?v=4)](https://github.com/koenpunt "koenpunt (1 commits)")

---

Tags

geometrygeographygeo

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/clonix-geokit/health.svg)

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

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[jsor/doctrine-postgis

Spatial and Geographic Data with PostGIS and Doctrine.

2191.6M1](/packages/jsor-doctrine-postgis)[geokit/geokit

Geo-Toolkit for PHP

251924.7k6](/packages/geokit-geokit)[brick/geo

GIS geometry library

245862.1k15](/packages/brick-geo)[creof/geo-parser

Parser for geography coordinate strings

624.4M15](/packages/creof-geo-parser)[creof/doctrine2-spatial

Doctrine2 multi-platform support for spatial types and functions

2763.3M11](/packages/creof-doctrine2-spatial)

PHPackages © 2026

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