2017 © Pedro PelĂĄez
 

library laravel-geo

Spatial OGC objects integration for Laravel 5.*

image

anilahir/laravel-geo

Spatial OGC objects integration for Laravel 5.*

  • Tuesday, June 5, 2018
  • by anil4baps
  • Repository
  • 1 Watchers
  • 0 Stars
  • 79 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 13 Versions
  • 1480 % Grown

The README.md

Geo Laravel

This is a fork from elevenlab/laravel-geo with some modifications for compatibility with Lumen 5.6+, (*1)

Features

  • GeoSpatial integration on Laravel 5.2+:
    • 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 (geography types)

Thanks to https://github.com/njbarrett/laravel-postgis for its original work., (*2)

Installation & Configuration

1) Install using composer, (*3)

$ composer require anilahir/laravel-geo

2) Replace under the Service Providers section ('providers' array) in config/app.php this line, (*4)

Illuminate\Database\DatabaseServiceProvider::class,

with this one:, (*5)

ElevenLab\GeoLaravel\DatabaseServiceProvider::class

3) If you need it, under the Alias section ('aliases' array) in config/app.php add this line:, (*6)

'GeoModel'      => ElevenLab\GeoLaravel\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, (*7)

Example (NB: the schema is over-semplified):, (*8)

<?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');
});

Add spatial attributes to a Model

In order to handle dinamically 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 $geometries attribute (you can find here the available types), (*9)

<?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']
    ];
}

Manipulate spatial attributes of a Model

<?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

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., (*10)

Given two OGCObjects, you can perform those operations:, (*11)

  • intersection, (*12)

  • difference, (*13)

  • contains, (*14)

  • intersects, (*15)

  • touches, (*16)

  • overlaps, (*17)

  • centroid, (*18)

  • distance, (*19)

  • equals, (*20)

Given an illuminate Query Builder object, you can use:, (*21)

  • whereEquals, (*22)

  • whereNotEquals, (*23)

  • orWhereEquals, (*24)

  • orWhereNotEquals, (*25)

  • whereContains, (*26)

  • whereNotContains, (*27)

  • orWhereContains, (*28)

  • orWhereNotContains, (*29)

  • whereIntersects, (*30)

  • whereNotIntersects, (*31)

  • orWhereIntersects, (*32)

  • orWhereNotIntersects, (*33)

  • whereTouches, (*34)

  • whereNotTouches, (*35)

  • orWhereTouches, (*36)

  • orWhereNotTouches, (*37)

  • whereOverlaps, (*38)

  • whereNotOverlaps, (*39)

  • orWhereOverlaps, (*40)

  • orWhereNotOverlaps, (*41)

ToDo

  • improve documentation
    • add examples for "Build queries" section
    • add manual installation guide
  • add missing ST_functionsĂč
  • add unit tests

The Versions

05/06 2018

dev-master

9999999-dev

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GPL-3.0-only

The Requires

 

The Development Requires

by Anil Ahir

laravel geo spatial geospatial

05/06 2018

1.1.2

1.1.2.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GPL-3.0-only

The Requires

 

The Development Requires

by Anil Ahir

laravel geo spatial geospatial

18/04 2018

1.1.1

1.1.1.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GPL-3.0-only

The Requires

 

The Development Requires

by Anil Ahir

laravel geo spatial geospatial

21/07 2017

1.1

1.1.0.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

18/07 2017

1.0.8

1.0.8.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

27/04 2017

1.0.7

1.0.7.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

19/04 2017

1.0.6

1.0.6.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

13/04 2017

1.0.5

1.0.5.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

27/03 2017

1.0.4

1.0.4.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

27/03 2017

1.0.3

1.0.3.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

20/03 2017

1.0.2

1.0.2.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

GNU GPL v3.0

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

17/03 2017

1.0.1

1.0.1.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

MIT

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial

17/03 2017

1.0

1.0.0.0

Spatial OGC objects integration for Laravel 5.*

  Sources   Download

MIT

The Requires

 

The Development Requires

by Lorenzo Giustozzi

laravel geo spatial geospatial