back1ng / point-in-mkad
Detect, if point in Moscow Ring Road (MKAD)
Installs: 2 442
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- hannesvdvreken/pip: ^1.1
- mjaschen/phpgeo: ^4.2
Requires (Dev)
- ergebnis/phpstan-rules: ^1.0
- friendsofphp/php-cs-fixer: ^3.13
- infection/infection: ^0.26.16
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.8
- phpstan/phpstan-strict-rules: ^1.4
- phpunit/phpunit: ^9
- rector/rector: ^0.15.1
- thecodingmachine/phpstan-strict-rules: ^1.0
- vimeo/psalm: ^4.29
README
Detect, if point in polygon, by default - in Moscow Ring Road (MKAD)
Available polygons:
- Moscow Ring Road
- St. Petersburg Ring Road.
- Yekaterinburg Ring Road.
Using:
<?php use Back1ng\PointInMkad\Detector; use Location\Coordinate; $detector = new Detector(); $desiredCoordinate = new Coordinate(55.720375, 37.639101); if ($detector->isPointInPolygon($desiredCoordinate)) { // do smth... }
Choose closest point of polygon
To select the closest point from the Moscow Ring Road to yours, use the following method
<?php use Back1ng\PointInMkad\Detector; // creating detector... $detector->getClosestPoint($desiredCoordinate); // Will return Location\Coordinate
You can also determine the distance from the outline polygon to your point
This method uses the implementation of calculator (Vincents formula by default), to calculate the distance in meters as accurately as possible
<?php use Back1ng\PointInMkad\Detector; // creating detector... $detector->getDistanceFromOutlinePolygonToCoordinate($desiredCoordinate): float;
Implementing your own polygon
Need to create a class from Back1ng\PointInMkad\CoordinatePolygon
and override parent method get()
<?php use Back1ng\PointInMkad\Polygons\CoordinatePolygon; class CustomPolygon extends CoordinatePolygon { public function get(): array { return [ [1, 0], [1, 1], [0, 1], ] } }
Then you can validate this polygon and get centroid.
$polygon = new CustomPolygon(); $polygon->isValid(); // true $polygon->getCentroid(); // Location\Coordinate
How to use new polygon?
$polygon = new CustomPolygon(); $detector = new \Back1ng\PointInMkad\Detector(coordinates: $polygon);