nemesis/laragis

Laravel的地缘空间库和实用工具集。这是从https://github.com/ralphschindler/laragis分叉而来的。

1.0.3 2017-04-11 09:13 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:05:55 UTC


README

LaraGis为Laravel提供地缘空间数据库和Eloquent功能。

功能

  • 简单的实体API,用于在模型属性中转换
  • 通过ST_AsGeoJSON()快速将MySql(非PHP用户空间)中的地缘空间数据序列化

安装

要开始使用Socialite,将以下内容添加到composer.json文件中作为依赖项

composer require ralphschindler/laragis

配置

安装Socialite库后,在config/app.php配置文件中注册LaraGis\LaraGisProvider

'providers' => [
    // Other service providers...

    LaraGis\LaraGisProvider::class,
],

基本用法

在基于Eloquent的模型中使用时,使用LaraGisTrait,并在$casts数组中使用laragis键指定要转换为地缘空间数据类型的列

class Place extends Model
{
    use LaraGisTrait;

    protected $table = 'places';

    protected $casts = [
        'coordinates' => 'laragis'
    ];
}
$place = App\Places::find(1);
$coordinates = $place->coordinates;
echo $coordinates->getLatitudeLongitude(); // "30, -90"

实体API

/**
 * @property double $latitude
 * @property double $longitude
 */
class Coordinates {
    public function __construct($latitude = null, $longitude = null);
    public function setLatitude($latitude);
    public function getLatitude();
    public function setLongitude($longitude);
    public function getLongitude();
    public function castToString($separator, $coordinatesOrder = self::LATITUDE_FIRST)
}

class Area implements \IteratorAggregate, \Countable {
    public function addCoordinates(Coordinates $coordinates);
    public function getCoordinates();
}