roman-franko/yii2-spatial
Composer 安装命令:
composer require roman-franko/yii2-spatial
包简介
Yii2 ActiveRecord supporting MySQL spatial data
README 文档
README
ActiveRecord with spatial attributes. Those attributes are transformed from the internal MySQL format to GeoJSON format after finding, and vice versa before storing.
Yii-spatial can also be used to find the model or models which are nearest to a given location.
Notice that this extension is intended to be used with a MySQL or MariaDB database exclusively.
Version 1.1.0 is compatible with MySQL 5.7 and MariaDB 10.3.
Installation
Install Yii2-spatial with Composer. Either add the following to the require section of your composer.json file:
"romanfranko/yii2-spatial": "*"
Or run:
composer require romanfranko/yii2-spatial "*"
You can manually install Yii2-spatial by downloading the source in ZIP-format.
Usage
Simply use a romanfranko\spatial\ActiveRecord as base class for your models, like so:
<?php
use romanfranko\spatial\ActiveRecord;
class MySpatialModel extends ActiveRecord
{
// ...
}
Notice: if you override find() in a romanfranko\spatial\ActiveRecord-derived class, be sure to return a romanfranko\spatial\ActiveQuery and not an 'ordinary' yii\db\ActiveQuery.
ActiveRecord method
featureProperties()
public function featureProperties($field, $geometry)
Override this function to add properties to the GeoJSON encoded attribute.
$fieldis the attribute name.$geometryis an array with the GeoJSON-information, like decoded JSON.
The default implementation adds the ActiveRecord's primary key as the property 'id'.
ActiveQuery method
nearest()
public function nearest($from, $attribute, $radius)
Change the query so that it finds the model(s) nearest to the point given by $from.
$from-string|arraystring: GeoJSON representation of searchPointorFeature.array: location in the form[<lng>, <lat>](twofloats).
$attribute-stringattribute name ofPointin the model.$radius-numbersearch radius in kilometers. Default100.
Example usages:
$here = [4.9, 52.3]; // longitude and latitude of my place
$here2 = '{"type":"Point","coordinates":[4.9,52.3]}'; // another representation
$nearestModel = <model>::find()->nearest($here, <attributeName>, 200)->one(); // search radius is 200 km
$fiveNearestModels = <model>::find()->nearest($here, <attributeName>)->limit(5)->all(); // search radius is 100 km (default)
$dataProvider = new ActiveDataProvider([ 'query' => <model>::find()->nearest($here, <attributeName>) ]);
Thanks
- fpolito for finding a very subtle bug.
roman-franko/yii2-spatial 适用场景与选型建议
roman-franko/yii2-spatial 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geo」 「data」 「db」 「mysql」 「map」 「extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 roman-franko/yii2-spatial 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 roman-franko/yii2-spatial 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 roman-franko/yii2-spatial 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Dibi is Database Abstraction Library for PHP
Show geo marker on a mapbox map
Show geo shape on a mapbox map with drawing capabilities
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
统计信息
- 总下载量: 53
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-20