Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries
Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries
Geotools can be found on Packagist. The recommended way to install Geotools is through composer.
Run the following on the command line:
composer require league/geotools
Important: you should use the 0.4 version if you use Geocoder 2.x or/and PHP 5.3.
And install dependencies:
composer install
Now you can add the autoloader, and you will have access to the library:
<?php
require 'vendor/autoload.php';
The default geodetic datum is WGS84 and coordinates are in decimal degrees.
Here are the available ellipsoids: AIRY, AUSTRALIAN_NATIONAL, BESSEL_1841, BESSEL_1841_NAMBIA,
CLARKE_1866, CLARKE_1880, EVEREST, FISCHER_1960_MERCURY, FISCHER_1968, GRS_1967, GRS_1980,
HELMERT_1906, HOUGH, INTERNATIONAL, KRASSOVSKY, MODIFIED_AIRY, MODIFIED_EVEREST,
MODIFIED_FISCHER_1960, SOUTH_AMERICAN_1969, WGS60, WGS66, WGS72, and WGS84.
If you need to use an other ellipsoid, just create an array like this:
<?php
$myEllipsoid = \League\Geotools\Coordinate\Ellipsoid::createFromArray([
'name' => 'My Ellipsoid', // The name of the Ellipsoid
'a' => 123.0, // The semi-major axis (equatorial radius) in meters
'invF' => 456.0 // The inverse flattening
]);
Geotools is built atop Geocoder. It means it's possible to use the
\Geocoder\Model\Address directly but it's also possible to use a string or a simple array with its
latitude and longitude.
It supports valid and acceptable geographic coordinates like:
Latitudes below -90.0 or above 90.0 degrees are capped through \League\Geotools\Coordinate\Coordinate::normalizeLatitude().
Longitudes below -180.0 or above 180.0 degrees are wrapped through \League\Geotools\Coordinate\Coordinate::normalizeLongitude().
…
It provides methods (and aliases) to convert decimal degrees WGS84 coordinates to degrees minutes seconds or decimal minutes WGS84 coordinates. You can format the output string easily.
You can also convert them in the Universal Transverse Mercator (UTM) projection (Southwest coast of Norway and the region of Svalbard are covered).
…
Here is the mapping:
Decimal minutes Latitude Longitude Positive or negative sign%P
%p
Direction
%L
%l
Degrees
%D
%d
Decimal minutes
%N
%n
Degrees minutes seconds
Latitude
Longitude
Positive or negative sign
%P
%p
Direction
%L
%l
Degrees
%D
%d
Minutes
%M
%m
Seconds
%S
%s
It provides a very handy way to batch geocode and reverse geocoding requests in serie or in parallel against a set of providers. Thanks to Geocoder and React libraries.
It's possible to batch one request (a string) or a set of request (an array) against one provider or set of providers.
You can use a provided cache engine or use your own by setting a cache object which should implement
League\Geotools\Cache\CacheInterface and extend League\Geotools\Cache\AbstractCache if needed.
At the moment Geotools supports any PSR-6 cache.
NB: Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your(s) geocoding provider(s).
…
You should get 24 results (4 values to geocode against 6 providers) something like:
…
Batch reverse geocoding is something like:
…
If you want to batch it in serie, replace the method parallel() by serie().
To optimize batch requests you need to register providers according to their capabilities and what you're looking for (geocode street addresses, geocode IPv4, geocode IPv6 or reverse geocoding), please read more at the Geocoder library doc.
It provides methods to compute the distance in meter (by default), km, mi or ft between two coordinates using flat (most performant), great circle, haversine or vincenty (most accurate) algorithms.
Those coordinates should be in the same ellipsoid.
…
It provides methods to compute the initial and final bearing in degrees, the initial and final cardinal direction,
the middle point and the destination point. The middle and the destination points returns a
\League\Geotools\Coordinate\Coordinate object with the same ellipsoid.
…
It provides methods to get the geo hash and its bounding box's coordinates (SouthWest & NorthEast) of a coordinate and the coordinate and its bounding box's coordinates (SouthWest & NorthEast) of a geo hash.
…
You can also get information about neighbor points (image).
…
Represent a location with 10m accuracy using a 10 character code that includes features to prevent errors in entering the code. Read more about the algorithm here.
<?php
$tenten = new \League\Geotools\Tests\Geohash\TenTen;
$tenten->encode(new Coordinate([51.09559, 1.12207])); // MEQ N6G 7NY5
Represents a segment with a direction. You can find if two vertexes are on the same line.
<?php
$vertexA->setFrom(48.8234055);
$vertexA->setTo(2.3072664);
$vertexB->setFrom(48.8234055);
$vertexB->setTo(2.3072664);
$vertexA->isOnSameLine($vertexB);
It helps you to know if a point (coordinate) is in a Polygon or on the Polygon's boundaries and if this in on a Polygon's vertex.
First you need to create the polygon, you can provide:
CoordinateCoordinateCollection…
It provides command lines to compute methods provided by Distance, Point, Geohash and Convert classes. Thanks to the Symfony Console Component.
…
Compute street addresses, IPv4s or IPv6s geocoding and reverse geocoding right in your console.
It's possible to define and precise your request through these options:
--provider: bing_maps, yahoo, maxmind... google_maps is the default one. See the full list
here.--raw: the result output in RAW format, shows Adapter, Provider and Arguments if any.--json: the result output in JSON string format.--args: this option accepts multiple values (e.g. --args="API_KEY" --args="LOCALE") if your provider needs or
can have arguments.--dumper: this option is available for geocoding, gpx, geojson, kml, wkb and wkt by default.
Read more here.--format: this option is available for reverse geocoding, see the mapping
here.…
The last command will show an output like this:
…
To run unit tests, you'll need the cURL extension and a set of dependencies, you can install them using Composer:
$ php composer.phar install --dev
Once installed, just launch the following command:
$ phpunit --coverage-text
Please see CONTRIBUTING for details.
Bugs and feature request are tracked on GitHub
Contributor Cod
No open issues yet, or sync has not completed.