百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-postgis

> 编程语言
开源

laravel 的 Postgis 扩展。旨在使从 laravel 模型中处理几何图形变得简单。

381 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

laravel 的 Postgis 扩展。旨在使从 laravel 模型中处理几何图形变得简单。

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis

DEPRECATED

Consider using: https://github.com/clickbar/laravel-magellan

Features

  • Work with geometry classes instead of arrays.
$model->myPoint = new Point(1,2);  //lat, long
  • Adds helpers in migrations.
$table->polygon('myColumn');

Warning

This Package has been moved to a new owner and aims for Laravel 6/7/8/9 and PHP 7 support only soon!

Replace all your references to the new namespace:

MStaack\LaravelPostgis

Thanks to :

  • https://github.com/njbarrett
  • https://github.com/phaza
  • https://github.com/mirzap

Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are looking for anyone that wants to help out!

Installation

  • Use 3.* for Laravel 5
composer require "mstaack/laravel-postgis:3.*"
  • Use 5.* for Laravel 6/7/8/9
composer require mstaack/laravel-postgis

For laravel >=5.5 that's all. This package supports Laravel new Package Discovery.

If you are using Laravel increments('id'); $table->string('name'); $table->string('address')->unique(); $table->point('location'); // GEOGRAPHY POINT column with SRID of 4326 (these are the default values). $table->point('location2', 'GEOGRAPHY', 4326); // GEOGRAPHY POINT column with SRID of 4326 with optional parameters. $table->point('location3', 'GEOMETRY', 27700); // GEOMETRY column with SRID of 27700. $table->polygon('polygon'); // GEOGRAPHY POLYGON column with SRID of 4326. $table->polygon('polygon2', 'GEOMETRY', 27700); // GEOMETRY POLYGON column with SRID of 27700. $table->timestamps(); }); }

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('locations');
}

}

…

PHP use Illuminate\Database\Eloquent\Model; use MStaack\LaravelPostgis\Eloquent\PostgisTrait; use MStaack\LaravelPostgis\Geometries\Point;

class Location extends Model { use PostgisTrait;

protected $fillable = [
    'name',
    'address'
];

protected $postgisFields = [
    'location',
    'location2',
    'location3',
    'polygon',
    'polygon2'
];

protected $postgisTypes = [
    'location' => [
        'geomtype' => 'geography',
        'srid' => 4326
    ],
    'location2' => [
        'geomtype' => 'geography',
        'srid' => 4326
    ],
    'location3' => [
        'geomtype' => 'geometry',
        'srid' => 27700
    ],
    'polygon' => [
        'geomtype' => 'geography',
        'srid' => 4326
    ],
    'polygon2' => [
        'geomtype' => 'geometry',
        'srid' => 27700
    ]
]

}

$linestring = new LineString( [ new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(0, 0) ] );

$location1 = new Location(); $location1->name = 'Googleplex'; $location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043'; $location1->location = new Point(37.422009, -122.084047); $location1->location2 = new Point(37.422009, -122.084047); $location1->location3 = new Point(37.422009, -122.084047); $location1->polygon = new Polygon([$linestring]); $location1->polygon2 = new Polygon([$linestring]); $location1->save();

$location2 = Location::first(); $location2->location instanceof Point // true


Available geometry classes:

 * Point
 * MultiPoint
 * LineString
 * MultiLineString
 * Polygon
 * MultiPolygon
 * GeometryCollection

## Publishing config
A configuration file exists for overriding default values. To add to your project, run:

```sh
php artisan vendor:publish --provider="MStaack\LaravelPostgis\DatabaseServiceProvider" --tag="postgis"

Coordinate precision

The precision of stored/displayed coordinated can be customised in the config.

# config/postgis.php
return [
    ...
    'precision' => 6,
];

See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言