vancuren/php-turf 问题修复 & 功能扩展

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

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

vancuren/php-turf

Composer 安装命令:

composer require vancuren/php-turf

包简介

A PHP library for geospatial analysis similar to Turf.js

README 文档

README

PHP Turf is a PHP library for geospatial analysis similar to Turf.js.

Installation

You can install PHP Turf via Composer. Run the following command in your terminal:

composer require vancuren/php-turf

Example

Here's a basic example demonstrating how to use PHP Turf to perform geospatial analysis:

<?php

*require* 'vendor/autoload.php';

use Vancuren\PhpTurf\Point;

*// Create some points*
$point1 = new Point([-73.9864, 40.7486]); *// New York, NY*
$point2 = new Point([-118.2437, 34.0522]); *// Los Angeles, CA*

*// Calculate distance between points*
$distance = Measurement::distance($point1, $point2);
echo "Distance between New York and Los Angeles: " . $distance . " kilometers\n";

Usage

Helpers

Point

Creates a Point feature from a coordinate.

$point1 = new Point([-73.9864, 40.7486]); // New York, NY*
$point2 = new Point([-118.2437, 34.0522]); // Los Angeles, CA*

Polygon

Creates a Polygon feature from an array of coordinates.

$coords = [[[0, 0],[0, 4],[3, 4],[3, 0],[0, 0]]];

$polygon = new Polygon($coords);

LineString

Creates a new line string

$points = [[0, 0],[1, 1],[2, 2]];

$lineString = new LineString($points);

FeatureCollection

Takes one or more Features and creates a FeatureCollection.

$features = [ 
    new Point([1,2]),
    new Point([1,3]),
    new Point([1,4]),
    new Point([1,5])
];

$featureCollection = new FeatureCollection($features);

Measurement

Area

Returns the polygon’s area

$coords = [[[0, 0],[0, 4],[3, 4],[3, 0],[0, 0]]];

$polygon = new Polygon($coords);
$area = Measurement::area($polygon);

Bearing

Calculate the bearing between two points

$point1 = new Point([-73.9864, 40.7486]); *// New York, NY*
$point2 = new Point([-118.2437, 34.0522]); *// Los Angeles, CA*

$bearing = Measurement::bearing($point1, $point2);

Center

Takes a Feature or FeatureCollection and returns the absolute center point of all features.

$points = [
    new Point([-73.9864, 40.7486]), // New York, NY
    new Point([-118.2437, 34.0522]), // Los Angeles, CA
    new Point([-87.6298, 41.8781]), // Chicago, IL
    new Point([-95.3698, 29.7604]) // Houston, TX
];

$featureCollection = new FeatureCollection($points);
$center = Measurement::center($featureCollection);

Destination

Calculate the destination point from a given point, distance, and bearing

$point = new Point([-73.9864, 40.7486]); *// New York, NY*
$distance = 3944; *// Roughly the distance to Los Angeles, CA*
$bearing = 273; *// Bearing to Los Angeles, CA*

$destination = Measurement::destination($point, $distance, $bearing);

Distance

Calculate the distance between two points

$point1 = new Point([-73.9864, 40.7486]); *// New York, NY*
$point2 = new Point([-118.2437, 34.0522]); *// Los Angeles, CA*

$distance = Measurement::distance($point1, $point2);

Midpoint

Calculate the midpoint between two points

$point1 = new Point([-73.9864, 40.7486]); *// New York, NY*
$point2 = new Point([-118.2437, 34.0522]); *// Los Angeles, CA*

$midpoint = Measurement::midpoint($point1, $point2);

Coordinate Mutation

TODO - Need to implement Coordinate Mutation ...

Transformation

TODO - Need to implement Transformation ...

Feature Conversion

TODO - Need to implement Feature Conversion ...

Misc

Nearest Point

Find the nearest point to a reference point

$referencePoint = new Point([-73.9864, 40.7486]); *// New York, NY*

$points = [
    new Point([-118.2437, 34.0522]), *// Los Angeles, CA*
    new Point([-87.6298, 41.8781]),  *// Chicago, IL*
    new Point([-95.3698, 29.7604])   *// Houston, TX*
];

$nearestPoint = Measurement::nearestPoint($referencePoint, $points);

Contains Point

Checks to see if a polygon contains a point.

$vertices = [[[0, 0],[0, 4],[3, 4],[3, 0],[0, 0]]];

$polygon = new Polygon($vertices);

$insidePoint = new Point([2, 2]);
$outsidePoint = new Point([5, 5]);

$isPointInside = $polygon->containsPoint($insidePoint); // TRUE
$isPointInside = $polygon->containsPoint($outsidePoint); // FALSE

Random

Misc

Get Points

Returns the points that create the line string.

$points = [
    [0, 0],
    [1, 1],
    [2, 2]
];

$lineString = new LineString($points);
$result = $lineString->getPoints();

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues if you encounter any problems or have suggestions for improvement.

Backers

Thank you to all our backers! 🙏

Become a backer

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

Become a sponsor

License

This project is licensed under the GNU AGPLv3 License. See the LICENSE file for details.

vancuren/php-turf 适用场景与选型建议

vancuren/php-turf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 376 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「geometry」 「math」 「analysis」 「gis」 「spatial」 「geospatial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vancuren/php-turf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vancuren/php-turf 我们能提供哪些服务?
定制开发 / 二次开发

基于 vancuren/php-turf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 376
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: AGPL-3.0-or-later
  • 更新时间: 2024-06-12