back1ng/point-in-mkad

There is no license information available for the latest version (v1.1.3) of this package.

Detect, if point in Moscow Ring Road (MKAD)

v1.1.3 2023-01-30 17:39 UTC

This package is auto-updated.

Last update: 2024-04-09 11:53:53 UTC


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);