sam-it/cs2cs
Composer 安装命令:
composer require sam-it/cs2cs
包简介
Cs2cs wrapper for PHP
README 文档
README
Coordinate transformation via PHP and cs2cs
Usage
$cs2cs = new SamIT\Proj4\Cs2cs([
'proj' => 'sterea',
'lat_0' => 52.15616055555555,
'lon_0' => 5.38763888888889,
'k' => 0.9999079,
'x_0' => 155000,
'y_0' => 463000,
'ellps' => 'bessel',
'towgs84' => implode(',', [565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725]),
'no_defs',
], [
'proj' => 'longlat',
'datum' => 'WGS84',
'no_defs'
], []);
$x = 236296.709;
$y = 590744.631;
$cs2cs->transform($x, $y, function($x, $y, $lon, $lat) use (&$count) {
$count++;
});
$cs2cs->close();
Explanation
Cs2cs uses output buffering, instead of writing a line immediately after reading a line from stdin, it waits until its output buffer is full and gets flushed automatically.
To efficiently transform many coordinates, we instead pass a callback that gets called with the result when it becomes available.
Short function doc:
transform($x, $y, $callback)
Sets up a callback that gets called when the transformation of $x and $y is complete.
close()
Terminates the cs2cs process, reads all remaining data. This will call all remaining callbacks.
read($timeout = 0)
Attempts to read data from cs2cs and fires the appropriate callbacks. Mostly used internally. If a timeout is set it will block until data becomes available. Using this can cause deadlocks.
blockingTransform($x, $y)
If you really need to do the transformation synchronously you can use this.
This will write dummy data to cs2cs and force it to flush its buffers.
If you just need to transform a single coordinate use transform() followed by flush() instead.
Using this effectively writes 4000 bytes instead of ~25. This is ~10000x slower then doing it asynchronously.
Cloning
In case you want to do this even faster (not tested!) the object supports cloning. When a cs2cs object is cloned it creates a new cs2cs process.
Benchmark, blocking vs async.
Synchronous, note the run size of 100.
[Runcount] => 50
[Runsize] => 100
[Blocking] => 1
[Average:] => 1.0074578237534
[Minimum:] => 0.94923281669617
[Maximum:] => 1.6763138771057
Asynchronous, note the runsize of 10000.
[Runcount] => 50
[Runsize] => 10000
[Blocking] =>
[Average:] => 0.19135624885559
[Minimum:] => 0.17859697341919
[Maximum:] => 0.20333218574524
Conclusion: go async.
sam-it/cs2cs 适用场景与选型建议
sam-it/cs2cs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「proj4」 「coordinate」 「transformation」 「cs2cs」 「proj」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sam-it/cs2cs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sam-it/cs2cs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sam-it/cs2cs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP-Class for geographic coordinates transformation using proj4 definitions, thanks to a translation from Proj4JS
Transform data for serialization
Entry GPS Coordinates plugin for Craft CMS
This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.
Doctrine2 simple support for spatial types and functions
A module for the Fermat math library which adds coordinate systems.
统计信息
- 总下载量: 1.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-07