Laravel Geo

GeoSpatial integration on Laravel 5.2+ that supports MySQL and PostgreSQL.
Alternatives To Laravel Geo
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Grafana54,5242524a day ago3,297September 23, 20223,288agpl-3.0TypeScript
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
Nocodb35,0063a day ago110September 06, 2022409agpl-3.0TypeScript
🔥 🔥 🔥 Open Source Airtable Alternative
Metabase31,818
21 hours ago1June 08, 20222,779otherClojure
The simplest, fastest way to get business intelligence and analytics to everyone in your company :yum:
Dbeaver31,150
a day ago1,741apache-2.0Java
Free universal database tool and SQL client
Typeorm30,8121,9942,164a day ago650September 20, 20221,914mitTypeScript
ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Prisma29,95144221 hours ago4,993September 24, 20222,798apache-2.0TypeScript
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
Graphql Engine29,4531a day ago17June 22, 20222,096apache-2.0TypeScript
Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
Sequelize27,652
a day ago836mitJavaScript
Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
Redash22,826
a day ago2May 05, 2020774bsd-2-clausePython
Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.
Directus20,69950a day ago55September 22, 2022349gpl-3.0TypeScript
The Modern Data Stack 🐰 — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
Alternatives To Laravel Geo
Select To Compare


Alternative Project Comparisons
Readme

THIS PROJECT IS NO LONGER ACTIVELY MANTAINED

Please refer to the official Laravel documentation since the framework now supports Geo Spatial databases.

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 njbarrett/laravel-postgis for its original work.

Installation & Configuration

  1. Install using composer
$ composer require elevenlab/laravel-geo
  1. Replace under the Service Providers section ('providers' array) in config/app.php this line
Illuminate\Database\DatabaseServiceProvider::class,

with this one:

ElevenLab\GeoLaravel\DatabaseServiceProvider::class
  1. If you need it, under the Alias section ('aliases' array) in config/app.php add this line:
'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

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

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

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.

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ù
  • add unit tests
Popular Postgresql Projects
Popular Mysql Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Php
Laravel
Mysql
Postgresql
Spatial
Geospatial
Postgis
Query Builder