承接 rkondratuk/geo-math-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rkondratuk/geo-math-php

最新稳定版本:1.0.1

Composer 安装命令:

composer require rkondratuk/geo-math-php

包简介

Geo calculations library

README 文档

README

PHP library for calculations in the Cartesian or polar coordinate system.

Requirements

  • PHP: >=5.4

Add to composer

composer require rkondratuk/geo-math-php:^1

Example:

<?php

use PhpGeoMath\Model\GeoSegment;
use PhpGeoMath\Model\Cartesian3dPoint;
use PhpGeoMath\Model\Polar3dPoint;

/*
 * Create polar point (in polar coordinates)
 */

// Rockefeller center coordinates
$latitude = 40.758742779050706;
$longitude = -73.97855507715238;

$polarPoint1 = new Polar3dPoint(
    $latitude, $longitude, Polar3dPoint::EARTH_RADIUS_IN_METERS
);

// Empire State Building coordinates
$polarPoint2 = new Polar3dPoint(
    40.74843388072615, -73.98566565776102, Polar3dPoint::EARTH_RADIUS_IN_METERS
);

// The Morgan Library & Museum coordinates
$polarPoint3 = new Polar3dPoint(
    40.74919365249446, -73.98133456388013, Polar3dPoint::EARTH_RADIUS_IN_METERS
);

/*
 * Create cartesian point (in cartesian coordinates)
 */
$x = 1001;
$y = 205;
$z = 512;

$cartesianPoint1 = new Cartesian3dPoint($x, $y, $z);

/*
 * Convert coordinates in alternative coordinates system
 */

$convertedCartesianPoint1 = $polarPoint1->buildCartesian3DPoint();
$convertedPolarPoint1 = $cartesianPoint1->buildPolar3dPoint();

/*
 * Calc GEO distance (by GEO arc) between two points
 */
$geoDistance = $polarPoint2->calcGeoDistanceToPoint($polarPoint1);

/*
 * Calc the nearest point (point-x) from GEO segment [point-1, point-2] to some GEO point (3)
 * Point (point-x) placed between [point-1, point-2]
 */
$arcSegmentFirst = new GeoSegment($polarPoint1, $polarPoint2);
$nearestPolarPointX = $arcSegmentFirst->calcNearestPoint($polarPoint3);

/*
 * Shortest distance from point-3 to segment [point-1, point-2] 
 * is distance between point-3 and point-x
 */
$nearestGeoDistance = $nearestPolarPointX->calcGeoDistanceToPoint($polarPoint3);

// Use Earth radius in miles for calculations in miles
Polar3dPoint::EARTH_RADIUS_IN_MILES;

Bitcoin address for donates: bc1qwa5wmta36e8a2wrvpa9jyplgzg4pjad7grwm29

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-14