Download the PHP package opensource-labs-gh/laravel-geo-utils without Composer
On this page you can find all versions of the php package opensource-labs-gh/laravel-geo-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opensource-labs-gh/laravel-geo-utils
More information about opensource-labs-gh/laravel-geo-utils
Files in opensource-labs-gh/laravel-geo-utils
Package laravel-geo-utils
Short Description A Laravel utility package for geographic polygon point checks with support for both PHP algorithms and MySQL spatial functions.
License MIT
Informations about the package laravel-geo-utils
Laravel Geo Utils
A comprehensive Laravel utility package for geographic operations, including polygon point checks, distance calculations, and spatial data manipulation. This package provides both pure PHP implementations and MySQL spatial function integration.
Features
- ๐ฏ Point-in-Polygon Detection: Ray-casting algorithm implementation
- ๐ Optimized Performance: Bounding box pre-filtering for faster checks
- ๐๏ธ MySQL Spatial Support: Leverage MySQL's built-in spatial functions
- ๐ Distance Calculations: Haversine formula for accurate distance measurement
- ๐ WKT Conversion: Convert between array and Well-Known Text formats
- โก Laravel Integration: Service provider, facade, and Artisan commands
- ๐งช Comprehensive Testing: Full test coverage with PHPUnit
- ๐ ๏ธ CLI Tools: Command-line testing and validation tools
Installation
Install the package via Composer:
The package will automatically register its service provider and facade.
Publishing Configuration
Optionally, you can publish the configuration file:
Usage
Basic Point-in-Polygon Check
Optimized Point-in-Polygon Check
For better performance with large polygons, use the optimized version that includes bounding box pre-filtering:
MySQL Spatial Functions
Use MySQL's built-in spatial functions for potentially better performance:
Distance Calculations
Calculate distances between two points using the Haversine formula:
Bounding Box Operations
Get the bounding box of a polygon:
WKT Conversion
Convert array coordinates to Well-Known Text format:
Artisan Commands
The package includes a command-line tool for testing and validation:
Basic Point-in-Polygon Test
Custom Polygon and Point Test
Distance Calculation Test
Bounding Box Test
Configuration
The package includes a configuration file with the following options:
API Reference
GeoHelper Methods
| Method | Parameters | Return | Description |
|---|---|---|---|
isPointInPolygon() |
array $polygon, array $point |
bool |
Check if point is inside polygon using ray-casting |
isPointInPolygonOptimized() |
array $polygon, array $point |
bool |
Optimized point-in-polygon with bounding box pre-check |
isPointInPolygonMySQL() |
string $polygonWkt, float $lat, float $lng |
bool |
MySQL spatial function point-in-polygon check |
calculateDistance() |
array $point1, array $point2, string $unit |
float |
Calculate distance between two points |
getBoundingBox() |
array $polygon |
array |
Get polygon bounding box |
isPointInBoundingBox() |
array $boundingBox, array $point |
bool |
Check if point is in bounding box |
arrayToWktPolygon() |
array $polygon |
string |
Convert array coordinates to WKT format |
Data Formats
Point Format:
Polygon Format:
Bounding Box Format:
Performance Considerations
-
Bounding Box Optimization: For large polygons, use
isPointInPolygonOptimized()which performs a quick bounding box check before the full polygon test. -
MySQL Spatial Functions: When working with large datasets, consider using
isPointInPolygonMySQL()which leverages MySQL's optimized spatial functions. - Coordinate Precision: Adjust
coordinate_precisionin config based on your needs - higher precision means more accuracy but potentially slower performance.
Error Handling
The package validates input data and throws InvalidArgumentException for:
- Polygons with fewer than 3 points
- Invalid coordinate values (latitude not between -90 and 90, longitude not between -180 and 180)
- Missing required array keys ('lat', 'lng')
- Invalid distance units
- Empty WKT strings
Testing
Run the package tests:
Or run tests with coverage:
Contributing
Please see CONTRIBUTING.md for details on how to contribute to this project.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Mawuli Agbenyo
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG.md for more information about recent changes.
Support
- ๐ง Email: [email protected]
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
Made with โค๏ธ by Opensource Labs Ghana
All versions of laravel-geo-utils with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0