Downloads
Stars
Version
This is a fork from elevenlab/laravel-geo with some modifications for compatibility with Lumen 5.6+
Thanks to https://github.com/njbarrett/laravel-postgis for its original work.
$ composer require anilahir/laravel-geo
Illuminate\Database\DatabaseServiceProvider::class,
with this one:
ElevenLab\GeoLaravel\DatabaseServiceProvider::class
'GeoModel' => ElevenLab\GeoLaravel\Model::class,
To add a geospatial field to your migration you can use these methods:
Example (NB: the schema is over-semplified):
<?php
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');
});
In order to handle dinamically geospatial attributes during CRUD operations, you need to:
$geometries
attribute (you can find here the available types)<?php namespace App;
use ElevenLab\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']
];
}
<?php
use ElevenLab\GeoLaravel\DataTypes\Point as Point;
use ElevenLab\GeoLaravel\DataTypes\Linestring as Linestring;
use ElevenLab\GeoLaravel\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); // ElevenLab\PHPOGC\DataTypes\Point
echo get_class($italy->national_bounds); // ElevenLab\PHPOGC\DataTypes\Polygon
echo get_class($italy->regions_bounds); // ElevenLab\PHPOGC\DataTypes\Polygon
echo get_class($italy->regions_capitals); // ElevenLab\PHPOGC\DataTypes\MultiPoint
echo get_class($italy->highway); // ElevenLab\PHPOGC\DataTypes\LineString
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