Download the PHP package mjaschen/phpgeo without Composer
On this page you can find all versions of the php package mjaschen/phpgeo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mjaschen/phpgeo
More information about mjaschen/phpgeo
Files in mjaschen/phpgeo
Package phpgeo
Short Description Simple Yet Powerful Geo Library
License MIT
Homepage https://phpgeo.marcusjaschen.de/
Informations about the package phpgeo
phpgeo - A Simple Geo Library for PHP
phpgeo provides abstractions to geographical coordinates (including support for different ellipsoids) and allows you to calculate geographical distances between coordinates with high precision.
Requirements
Minimum required PHP version is 8.1. phpgeo is tested up to PHP 8.3.
New features will only go into the main branch and won't be backported.
It's possible to install older versions of phpgeo for older PHP versions. Please refer to the following table for the compatibility matrix:
PHP Version | phpgeo Version | Support Status | Composer Install |
---|---|---|---|
8.3 | 5.x | ✅ active | composer require mjaschen/phpgeo |
8.2 | 5.x | ✅ active | composer require mjaschen/phpgeo |
8.1 | 5.x | ✅ active | composer require mjaschen/phpgeo |
8.0 | 4.x | ⚠️ security only | composer require mjaschen/phpgeo:^4.0 |
7.4 | 4.x | ⚠️ security only | composer require mjaschen/phpgeo:^4.0 |
7.3 | 4.x | ⚠️ security only | composer require mjaschen/phpgeo:^4.0 |
7.2 | 3.x | ❌ end of life | composer require mjaschen/phpgeo:^3.0 |
7.1 | 2.x | ❌ end of life | composer require mjaschen/phpgeo:^2.0 |
7.0 | 2.x | ❌ end of life | composer require mjaschen/phpgeo:^2.0 |
5.6 | 1.x | ❌ end of life | composer require mjaschen/phpgeo:^1.0 |
5.5 | 1.x | ❌ end of life | composer require mjaschen/phpgeo:^1.0 |
5.4 | 1.x | ❌ end of life | composer require mjaschen/phpgeo:^1.0 |
Documentation
The documentation is available at phpgeo.marcusjaschen.de.
Installation
Using Composer, just add it to your composer.json
by running:
Upgrading
Update the version constraint in the project's composer.json
and
run composer update
or require the new version by running:
Upgrading to 5.x
phpgeo has some breaking changes in the 5.x release line. Please refer to the following list to see what has changed and what you need to do to upgrade your code.
Change | Description | Action |
---|---|---|
setPoint1() and setPoint2() methods removed from Line |
The Line class now is immutable. |
Use the constructor to create a new instance of Line . |
removed support for PHP 7.3, 7.4 and 8.0 | Older PHP versions are no longer supported. | Upgrade to at least PHP 8.1. |
License
Starting with version 2.0.0 phpgeo is licensed under the MIT license. Older versions were GPL-licensed.
Features
Info: Please visit the documentation site for complete and up-to-date documentation with many examples!
phpgeo provides the following features (follow the links for examples):
- abstractions of several geometry objects (coordinate/point, line, polyline/GPS track, polygon
- support for different ellipsoids, e.g. WGS-84
- length/distance/perimeter calculations with different implementations (Haversine, Vincenty)
- Geofence calculation, i.e. answering the question "Is this point contained in that area/polygon?" and other intersection checks between different geometries
- formatting and output of geometry objects
(GeoJSON, nice strings, e. g.
18° 54′ 41″ -155° 40′ 42″
) - calculation of bearing angle between two points (spherical or with Vincenty's formula)
- calculation of a destination point for a given starting point, bearing angle, and distance (spherical or with Vincenty's formula)
- calculation of the perpendicular distance between a point and a line
- calculation of the Cardinal Distances between two points
- getting segments of a polyline /polygon,
- reversing direction of polyline/polygon
Examples/Usage
This list is incomplete, please visit the documentation site for the full monty of documentation and examples!
Distance between two coordinates (Vincenty's Formula)
Use the calculator object directly:
or call the getDistance()
method of a Coordinate object by injecting a calculator object:
Simplifying a polyline
Polylines can be simplified to save storage space or bandwidth. Simplification is done with the Ramer–Douglas–Peucker algorithm (AKA Douglas-Peucker algorithm).
Polygon contains a point (e.g. "GPS geofence")
phpgeo has a polygon implementation which can be used to determinate if a point is contained in it or not.
A polygon consists of at least three points. Points are instances of the Coordinate
class.
Warning: The calculation gives wrong results if the polygons has points on both sides of the 180/-180 degrees meridian.
Formatted output of coordinates
You can format a coordinate in different styles.
Decimal Degrees
Degrees/Minutes/Seconds (DMS)
GeoJSON
Development
Run Tests
Before submitting a pull request, please be sure to run all checks and tests and ensure everything is green.
- lint PHP files for syntax errors:
composer ci:lint
- run static analysis with Psalm and report errors:
composer ci:psalm
- run unit tests with PHPUnit:
composer ci:tests
To run all checks and tests at once, just use composer ci
.
Of course, it's possible to use the test runners directly, e.g. for PHPUnit:
Psalm:
Running GitHub Actions locally
It's possible to run the whole CI test matrix locally with act:
Credits
- Marcus Jaschen all contributors
- Chris Veness - JavaScript implementation of the Vincenty formula for distance calculation
- Ersts,P.J., Horning, N., and M. Polin[Internet] Perpendicular Distance Calculator(version 1.2.2) Documentation. American Museum of Natural History, Center for Biodiversity and Conservation. Available from http://biodiversityinformatics.amnh.org/open_source/pdc. Accessed on 2013-07-07.
- W. Randolph Franklin, PNPOLY - Point Inclusion in Polygon Test Documentation