shabushabu / laravel-postgis
为Laravel提供的PostGIS查询表达式集合
v0.3.0
2024-07-21 10:48 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0
- tpetry/laravel-query-expressions: ^1.3
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- pestphp/pest-plugin-type-coverage: ^2.8
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-09-21 11:14:07 UTC
README
Laravel PostGIS
为Laravel选择PostGIS查询表达式集合。
支持的最小版本
安装
注意
请注意,这是一个新包,尽管经过了充分测试,但它应被视为预发布软件
在安装此包之前,您应安装并启用PostGIS扩展。
您可以通过composer安装此包
composer require shabushabu/laravel-postgis
用法
有关支持的PostGIS函数的完整列表,请参阅表达式文件夹。
我们接受对任何附加函数的pull请求!
表达式可用于查询或迁移。
由于PostGIS查询之间往往存在细微差别,因此ShabuShabu使用此包的方式是扩展特定模型的Eloquent构建器,并在其中使用表达式。
查询示例
获取几何列的GeoJSON表示形式
use ShabuShabu\PostGIS\Expressions\As; use Tpetry\QueryExpressions\Language\Alias; use ShabuShabu\PostGIS\Expressions\Enums\Option; Track::query() ->select(new Alias(new As\GeoJSON('geom', 6, Option::bbox), 'json')) ->where('trail_id', 27) ->value('json');
从线字符串zm获取高程剖面
use Tpetry\QueryExpressions\Language\Alias; use ShabuShabu\PostGIS\Expressions\Collect; use ShabuShabu\PostGIS\Expressions\Simplify; use ShabuShabu\PostGIS\Expressions\DumpPoints; use ShabuShabu\PostGIS\Expressions\Position\Elevation; use ShabuShabu\PostGIS\Expressions\Position\Timestamp; DB::query()->select([ new Alias(new Elevation('geom'), 'x'), new Alias(new Timestamp('geom'), 'y'), ])->from( Track::query()->select( new Alias(new DumpPoints(new Simplify(new Collect('geom'), 0.15)), 'geom') )->where('trail_id', 27), 't' );
迁移示例
从坐标列添加生成列
use ShabuShabu\PostGIS\Expressions\SetSRID; use ShabuShabu\PostGIS\Expressions\Position\MakePoint; Schema::create('locations', static function (Blueprint $table) { // all the other table columns... $table->decimal('lat', 10, 6)->nullable(); $table->decimal('lng', 10, 6)->nullable(); $table ->geometry('geom', 'point', 4326) ->storedAs(new SetSRID(new MakePoint('lng', 'lat'), 4326)); });
设置给定多边形的中心
use ShabuShabu\PostGIS\Expressions\Centroid; Schema::create('countries', static function (Blueprint $table) { // all the other table columns... $table->geometry('geom', 'multipolygon', 4326); $table ->geometry('center', 'point', 4326) ->storedAs(new Centroid('geom')); });
设置面积(平方公里)
use ShabuShabu\PostGIS\Expressions\Area; use Tpetry\QueryExpressions\Value\Value; use ShabuShabu\PostGIS\Expressions\Math\Round; use ShabuShabu\PostGIS\Expressions\Casts\AsNumeric; use ShabuShabu\PostGIS\Expressions\Casts\AsGeography; use Tpetry\QueryExpressions\Operator\Arithmetic\Divide; Schema::create('provinces', static function (Blueprint $table) { // all the other table columns... $table->geometry('geom', 'multipolygon', 4326); $table ->integer('area_km2') ->storedAs(new Round( new AsNumeric( new Divide( new Area(new AsGeography('geom')), new Value(1e+6) ) ) )); });
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献。
安全漏洞
有关如何报告安全漏洞,请参阅我们的安全策略。
鸣谢
免责声明
这是一个第三方包,ShabuShabu与Laravel或PostGIS无任何关联。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。