back1ng/point-in-mkad 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

back1ng/point-in-mkad

最新稳定版本:v1.1.3

Composer 安装命令:

composer require back1ng/point-in-mkad

包简介

Detect, if point in Moscow Ring Road (MKAD)

关键字:

README 文档

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

统计信息

  • 总下载量: 2.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-10-18