I needed to perform geospatial calculations and handle database interactions for my research masters. For this I wrote an independent PHP library which would handle geospatial datatypes as well as performing calculations.
Key features of the library include:
- Classes for common data types Point, LineString, Polygon, GeometryCollection, MultiPoint, MultiLineString and MultiPolygon.
- Different algorithms for calculating distances between points and lengths of lines including Haversine and Vincenty.
- Bearing calculations.
- Conversion of objects to and from WKT and GeoJSON.
- Loosely coupled spheroid (so it can be implemented to calculate distances on other bodies as well as Earth).
- Delegates calculations to the PHP Geospatial C extension if it exists.
This has been installed over 1,500 times on through composer, and is PSR-2 compliant.