1. Go to this page and download the library: Download shabushabu/laravel-postgis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shabushabu / laravel-postgis example snippets
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');
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)
)
)
));
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.