PHPackages                             shaozeming/lumen-postgis - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. shaozeming/lumen-postgis

ActiveLibrary[Database &amp; ORM](/categories/database)

shaozeming/lumen-postgis
========================

Postgis extensions for laravel+lumen. Aims to make it easy to work with geometries from laravel models

1.0(9y ago)165MITPHPPHP &gt;=5.5

Since Apr 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ShaoZeMing/lumen-postgis)[ Packagist](https://packagist.org/packages/shaozeming/lumen-postgis)[ RSS](/packages/shaozeming-lumen-postgis/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Laravel postgis extension
=========================

[](#laravel-postgis-extension)

[![Build Status](https://camo.githubusercontent.com/ea2a548689ab90dffff6985feb22a5e2c5cf9facd58c72a91fdafe40d86d31fb/68747470733a2f2f7472617669732d63692e6f72672f6e6a626172726574742f6c61726176656c2d706f73746769732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/njbarrett/laravel-postgis.svg?branch=master)[![Code Climate](https://camo.githubusercontent.com/879839c69b421d532b7d69ce0fe5442d72461160edc48e022f0619c7e1758539/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6e6a626172726574742f6c61726176656c2d706f73746769732f6261646765732f6770612e737667)](https://codeclimate.com/github/njbarrett/laravel-postgis)[![Coverage Status](https://camo.githubusercontent.com/1b7cb57d4a165b74c65d0dcc96d1fdcd19995539f6ae3d62ad3f1df6cfb4a804/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e6a626172726574742f6c61726176656c2d706f73746769732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/njbarrett/laravel-postgis?branch=master)

Solemnly declare
================

[](#solemnly-declare)

- This is based on [Phaza\\Laravel-Postgis](https://github.com/njbarrett/laravel-postgis) to modify Non-original;

修改位置
----

[](#修改位置)

1. 修改了readme.md 关于lumen5.4 安装的注册服务，需要注册两个服务(见下文)。
2. 添加了几何数据迁移命令`$table->geometry('geom')`;
3. 添加 $location1-&gt;location = new GeomPoint(37.422009, -122.084047); 实现gis几何数据直接利用模型插入

Features
--------

[](#features)

- Work with geometry classes instead of arrays. (`$myModel->myPoint = new Point(1,2)`)
- Adds helpers in migrations. (`$table->polygon('myColumn')`)

### Future plans

[](#future-plans)

- Geometry functions on the geometry classes (contains(), equals(), distance(), etc… (HELP!))

Versions
--------

[](#versions)

- Use for Laravel `5.3.*`;`5.4.*`
- Use for lumen `5.3.*`;`5.4.*`

Installation
------------

[](#installation)

```
composer require shaozeming/lumen-postgis 'dev-master'

```

laravel Next add the DatabaseServiceProvider to your `config/app.php` file.

```
    'Shaozeming\LumenPostgis\DatabaseServiceProvider',

```

That's all.

Lumen Next add the DatabaseServiceProvider to your `bootstrap/app.php` file.

```
     $app->register(Bosnadev\Database\DatabaseServiceProvider::class);   //多添加这个后，就可以解决问题。
     $app->register(Shaozeming\LumenPostgis\DatabaseServiceProvider::class);

```

That's all.

Usage
-----

[](#usage)

First of all, make sure to enable postgis.

```
CREATE EXTENSION postgis;

```

To verify that postgis is enabled

```
SELECT postgis_full_version();

```

### Migrations

[](#migrations)

Now create a model with a migration by running

```
php artisan make:model Location

```

If you don't want a model and just a migration run

```
php artisan make:migration create_locations_table

```

Open the created migrations with your editor.

```
use Illuminate\Database\Migrations\Migration;
use Shaozeming\LumenPostgis\Schema\Blueprint;

class CreateLocationsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name');
            $table->string('address')->unique();
            $table->point('location');
            $table->geometry('geom');
            $table->polygon('polygon');
            $table->timestamps();
        });
    }

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

}
```

Available blueprint geometries:

- point
- geometry
- multipoint
- linestring
- multilinestring
- polygon
- multipolygon
- geometrycollection

other methods:

- enablePostgis
- disablePostgis

### Models

[](#models)

All models which are to be PostGis enabled **must** use the *PostgisTrait*.

You must also define an array called `$postgisFields` which defines what attributes/columns on your model are to be considered geometry objects.

```
use Illuminate\Database\Eloquent\Model;
use Shaozeming\LumenPostgis\Eloquent\PostgisTrait;
use Shaozeming\LumenPostgis\Geometries\Point;

class Location extends Model
{
    use PostgisTrait;

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

    protected $postgisFields = [
        'location',
        'polygon',
    ];

}

$location1 = new Location();
$location1->name = 'Googleplex';
$location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043';
$location1->location = new Point(37.422009, -122.084047);
$location1->geom = new GeomPoint(37.422009, -122.084047);  //这个可以执行成功实现ORM操作gis几何数据。
$location1->save();

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

Available geometry classes:

- Point
- Geometry
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3354d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/27b8938a70163fe95a1bea9ead4bfa7386b3fef2e00dd6c55bc1b3a20351fc72?d=identicon)[ShaoZeMing](/maintainers/ShaoZeMing)

---

Top Contributors

[![ShaoZeMing](https://avatars.githubusercontent.com/u/19376576?v=4)](https://github.com/ShaoZeMing "ShaoZeMing (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shaozeming-lumen-postgis/health.svg)

```
[![Health](https://phpackages.com/badges/shaozeming-lumen-postgis/health.svg)](https://phpackages.com/packages/shaozeming-lumen-postgis)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.4M2](/packages/glushkovds-phpclickhouse-laravel)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

276.8k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
