Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.
Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.
Consider using: https://github.com/clickbar/laravel-magellan
$model->myPoint = new Point(1,2); //lat, long$table->polygon('myColumn');This Package has been moved to a new owner and aims for Laravel 6/7/8/9 and PHP 7 support only soon!
Replace all your references to the new namespace:
MStaack\LaravelPostgisThanks to :
Fluent in Laravel Packages and Postgres/Postgis? Consider contributing! We are looking for anyone that wants to help out!
composer require "mstaack/laravel-postgis:3.*"composer require mstaack/laravel-postgisFor laravel >=5.5 that's all. This package supports Laravel new Package Discovery.
If you are using Laravel increments('id'); $table->string('name'); $table->string('address')->unique(); $table->point('location'); // GEOGRAPHY POINT column with SRID of 4326 (these are the default values). $table->point('location2', 'GEOGRAPHY', 4326); // GEOGRAPHY POINT column with SRID of 4326 with optional parameters. $table->point('location3', 'GEOMETRY', 27700); // GEOMETRY column with SRID of 27700. $table->polygon('polygon'); // GEOGRAPHY POLYGON column with SRID of 4326. $table->polygon('polygon2', 'GEOMETRY', 27700); // GEOMETRY POLYGON column with SRID of 27700. $table->timestamps(); }); }
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('locations');
}}
…PHP use Illuminate\Database\Eloquent\Model; use MStaack\LaravelPostgis\Eloquent\PostgisTrait; use MStaack\LaravelPostgis\Geometries\Point;
class Location extends Model { use PostgisTrait;
protected $fillable = [
'name',
'address'
];
protected $postgisFields = [
'location',
'location2',
'location3',
'polygon',
'polygon2'
];
protected $postgisTypes = [
'location' => [
'geomtype' => 'geography',
'srid' => 4326
],
'location2' => [
'geomtype' => 'geography',
'srid' => 4326
],
'location3' => [
'geomtype' => 'geometry',
'srid' => 27700
],
'polygon' => [
'geomtype' => 'geography',
'srid' => 4326
],
'polygon2' => [
'geomtype' => 'geometry',
'srid' => 27700
]
]
}
$linestring = new LineString( [ new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(0, 0) ] );
$location1 = new Location(); $location1->name = 'Googleplex'; $location1->address = '1600 Amphitheatre Pkwy Mountain View, CA 94043'; $location1->location = new Point(37.422009, -122.084047); $location1->location2 = new Point(37.422009, -122.084047); $location1->location3 = new Point(37.422009, -122.084047); $location1->polygon = new Polygon([$linestring]); $location1->polygon2 = new Polygon([$linestring]); $location1->save();
$location2 = Location::first(); $location2->location instanceof Point // true
Available geometry classes:
* Point
* MultiPoint
* LineString
* MultiLineString
* Polygon
* MultiPolygon
* GeometryCollection
## Publishing config
A configuration file exists for overriding default values. To add to your project, run:
```sh
php artisan vendor:publish --provider="MStaack\LaravelPostgis\DatabaseServiceProvider" --tag="postgis"The precision of stored/displayed coordinated can be customised in the config.
# config/postgis.php
return [
...
'precision' => 6,
];See http://wiki.gis.com/wiki/index.php/Decimal_degrees#Accuracy for more information
No open issues yet, or sync has not completed.