karomap/laravel-geo
Composer 安装命令:
composer require karomap/laravel-geo
包简介
Spatial OGC objects integration for Laravel 5.*
关键字:
README 文档
README
Geo Laravel
This is a fork from elevenlab/laravel-geo with some modifications for compatibility with Laravel 5.4+
Note: In this version you can use either geometry or geography column type for PostGIS with SRID.
Features
- GeoSpatial integration on Laravel 5.4+:
- Create geospatial columns using Schema and migrations
- Save and retrieve geospatial attributes using directly OpenGeoConsortium Spatial Objects (this package depends from PHP-OGC)
- Build spatial query directly with the laravel fluent query builder
- Supported types: Point, MultiPoint, Linestring, MultiLinestring, Polygon, MultiPolygon, GeometryCollection
- Supported drivers:
- Postgres: Posgis extension Extensions (geometry types)
- MySql: Extension for Spatial Data (geometry types)
Thanks to laravel-postgis for its original work.
Installation & Configuration
- Install using composer
$ composer require karomap/laravel-geo
- Replace under the Service Providers section ('providers' array) in
config/app.phpthis line
Illuminate\Database\DatabaseServiceProvider::class,
with this one:
Karomap\GeoLaravel\DatabaseServiceProvider::class
- If you need it, under the Alias section ('aliases' array) in config/app.php add this line:
'GeoModel' => Karomap\GeoLaravel\Eloquent\Model::class,
Quick Documentation
Create table with spatial references
To add a geospatial field to your migration you can use these methods:
- point, multipoint linestring, multilinestring, polygon, multipolygon, geometrycollection
Example (NB: the schema is over-simplified):
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Migrations\Migration; use Karomap\GeoLaravel\Database\Schema\Blueprint; // Replace "Illuminate\Database\Schema\Blueprint" class CreateNationsTable extends Migration { public function up() { Schema::create('nations', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->polygon('national_bounds'); $table->point('capital'); $table->multipolygon('regions_bounds'); $table->multipoint('regions_capitals'); $table->linestring('highway'); }); } }
Add spatial attributes to a Model
In order to handle dynamically geospatial attributes during CRUD operations, you need to:
- substitute the Eloquent Model abstract object with a custom Model
- define which attribute belongs to which geospatial type, defining the
$geometriesattribute (you can find here the available types)
<?php namespace App; use Karomap\GeoLaravel\Eloquent\Model as GeoModel; class Country extends GeoModel { protected $table = "countries"; protected $geometries = [ "polygons" => ['national_bounds'], "points" => ['capital'], "multipolygons" => ['regions_bounds'], "multipoints" => ['regions_capitals'], "linestrings" => ['highway'] ]; }
Manipulate spatial attributes of a Model
<?php use Karomap\PHPOGC\DataTypes\Point as Point; use Karomap\PHPOGC\DataTypes\Linestring as Linestring; use Karomap\PHPOGC\DataTypes\Polygon as Polygon; $rome = new Point(41.9102415,12.3959149); $milan = new Point(45.4628328,9.1076927); $naples = new Point(40.8540943,14.1765626); $regions_capital = new MultiPoint([$rome, $milan, $naples, ....]); $italy_bounds = new Polygon([new LineString(getPointArrayOfItalianBounds())]); $lazio = new LineString(getPointArrayOfLazioBounds()); $campania = new LineString(getPointArrayOfCampaniaBounds()); $lombardia = new LineString(getPointArrayOfLombardiaBounds()); $molise = new LineString(getPointArrayOfMoliseBounds()); # raise MoliseNotFoundException $regions_bounds = new MultiPolygon([$lazio, $campania, $lombardia, ....]); $a1 = new LineString(getPointArrayOfA1()); $italy = Country::create([ 'name' => 'Italy', 'capital' => $rome, 'national_bounds' => $italy_bounds, 'regions_bounds' => $regions_bounds, 'regions_capitals' => $regions_capital, 'highway' => $a1 ]); $italy = Country::whereName('Italy')->first(); echo get_class($italy->capital); // Karomap\PHPOGC\DataTypes\Point echo get_class($italy->national_bounds); // Karomap\PHPOGC\DataTypes\Polygon echo get_class($italy->regions_bounds); // Karomap\PHPOGC\DataTypes\Polygon echo get_class($italy->regions_capitals); // Karomap\PHPOGC\DataTypes\MultiPoint echo get_class($italy->highway); // Karomap\PHPOGC\DataTypes\LineString
Builds queries
There are two different groups of methods that are available, one to use the underlying database engine to perform spatial operations on existing objects, and another to build fluent queries and perform operations on database-resident data.
Given two OGCObjects, you can perform those operations:
-
intersection
-
difference
-
contains
-
intersects
-
touches
-
overlaps
-
centroid
-
distance
-
equals
Given an illuminate Query Builder object, you can use:
-
whereEquals
-
whereNotEquals
-
orWhereEquals
-
orWhereNotEquals
-
whereContains
-
whereNotContains
-
orWhereContains
-
orWhereNotContains
-
whereIntersects
-
whereNotIntersects
-
orWhereIntersects
-
orWhereNotIntersects
-
whereTouches
-
whereNotTouches
-
orWhereTouches
-
orWhereNotTouches
-
whereOverlaps
-
whereNotOverlaps
-
orWhereOverlaps
-
orWhereNotOverlaps
ToDo
- improve documentation
- add examples for "Build queries" section
- add manual installation guide
- add missing ST_functions
karomap/laravel-geo 适用场景与选型建议
karomap/laravel-geo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 190 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geo」 「laravel」 「spatial」 「geospatial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 karomap/laravel-geo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 karomap/laravel-geo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 karomap/laravel-geo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Show geo marker on a mapbox map
Show geo shape on a mapbox map with drawing capabilities
PHP FFI bindings for Uber's H3 hexagonal hierarchical geospatial indexing system
Add a weather widget to Flarum
Doctrine2 simple support for spatial types and functions
Laravel Geocode by address library
统计信息
- 总下载量: 190
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2018-02-24