Download the PHP package angel-source-labs/laravel-spatial without Composer

On this page you can find all versions of the php package angel-source-labs/laravel-spatial. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-spatial

Spatial: GIS Spatial Extensions for Laravel

PHPUnit tests

Laravel package to easily work with GIS data types in PostGIS, MySQL 5.7, and MySQL 8.

Supported Compatibiltiy

Laravel

This package is tested against the following Laravel versions:

Databases

This package is tested against the following Databases

Database Platform SRID Supported Geography Type Supported
PostGIS 10.x - 14.x Postgres 10 Yes Yes
MySQL 5.7 MySQL 5.7 No No
MySQL 8.x MySQL 8 Yes No
Percona 5.7 MySQL 5.7 No No
Percona 8.x MySQL 8 Yes No
MariaDB 10.2 - 10.7 MySQL 5.7 No No

Future

Support for these databases may be available in a future release. This package has been designed to support these databases but the work is not complete.

History and Motivation

We really like the grimzy/laravel-mysql-spatial Laravel Eloquent API and we wanted to also be able to use Postgis. (See issue 137). The goal of this package is to provide an API compatible with the grimzy/laravel-mysql-spatial package that also supports postgis and additional database drivers.

This package is a fork and substantial refactoring of grimzy/laravel-mysql-spatial:

Historically, grimzy/laravel-mysql-spatial was itself a fork of njbarrett/laravel-postgis, which is now mstaack/laravel-postgis. These laravel-postgis pacakges provide access to postgis but do not provide the Laravel Eloquent Spatial analysis functions which were added by grimzy/laravel-mysql-spatial.

Installation

Add the package using composer:

Installation

Laravel 8.x, 9.x, 10.x, 11.x

Laravel 6.x, 7.x

Laravel 6.x, and 7.x require DBAL 2.x. Because DBAL is a require-dev dependency of laravel, its version constraint will not be resolved by composer when installing a child package. However, this is easy to solve by specifying DBAL 2.x as an additional dependency.

Note that Laravel 6.x, 7.x, 8.x, and 9.x are EOL. See https://laravelversions.com/en. These versions will continue to be supported by this package for as long as it is reasonably easy, thanks to github actions performing the testing.

To install for Laravel 6.x, and 7.x:

Quickstart

Create a migration

From the command line:

Then edit the migration you just created by adding at least one spatial data field.

Run the migration:

Create a model

From the command line:

Then edit the model you just created. It must use the SpatialTrait and define an array called $spatialFields with the name of the spatial data field(s) created in the migration:

Saving a model

Or if your database fields were created with a specific SRID:

Note: When saving collection Geometries (LineString, Polygon, MultiPoint, MultiLineString, and GeometryCollection), only the top-most geometry should have an SRID set in the constructor.

In the example above, when creating a new Polygon(), we only set the SRID on the Polygon and use the default for the LineString and the Point objects.

Retrieving a model

Geometry classes

Available Geometry classes

AngelSourceLabs\LaravelSpatial\Doctrine\Types OpenGIS Class
Point($lat, $lng, $srid = 0) Point
MultiPoint(Point[], $srid = 0) MultiPoint
LineString(Point[], $srid = 0) LineString
MultiLineString(LineString[], $srid = 0) MultiLineString
Polygon(LineString[], $srid = 0) (exterior and interior boundaries) Polygon
MultiPolygon(Polygon[], $srid = 0) MultiPolygon
GeometryCollection(Geometry[], $srid = 0) GeometryCollection

PlantUML Markup

Using Geometry classes

In order for your Eloquent Model to handle the Geometry classes, it must use the AngelSourceLabs\LaravelSpatial\Eloquent\SpatialTrait trait and define a protected property $spatialFields as an array of spatial data type column names (example in Quickstart).

IteratorAggregate and ArrayAccess

The collection Geometries (LineString, Polygon, MultiPoint, MultiLineString, and GeometryCollection) implement IteratorAggregate and ArrayAccess; making it easy to perform Iterator and Array operations. For example:

Helpers

From/To Well Known Text (WKT)
From/To String
From/To JSON (GeoJSON)

The Geometry classes implement JsonSerializable and Illuminate\Contracts\Support\Jsonable to help serialize into GeoJSON:

To deserialize a GeoJSON string into a Geometry class, you can use Geometry::fromJson($json_string) :

Scopes: Spatial analysis functions

Spatial analysis functions are implemented using Eloquent Local Scopes.

Available scopes:

Note that behavior and availability of spatial analysis functions differs in each database and database version.

Spatial function references:

Migrations

Columns

Available spatial type migration blueprints:

Spatial type references:

Spatial indexes

You can add or drop spatial indexes in your migrations with the spatialIndex and dropSpatialIndex blueprints.

Note about spatial indexes from the MySQL documentation:

For MyISAM and (as of MySQL 5.7.5) InnoDB tables, MySQL can create spatial indexes using syntax similar to that for creating regular indexes, but using the SPATIAL keyword. Columns in spatial indexes must be declared NOT NULL.

Also please read this important note regarding Index Lengths in the Laravel documentation.

For example, as a follow up to the Quickstart; from the command line, generate a new migration:

Then edit the migration file that you just created:

Tests

Start MySQL 5.7, MySQL8, Postgis Docker containers for tests.

run tests. Unit tests can be run without the database server docker containers.

Contributing

Recommendations and pull request are most welcome! Pull requests with tests are the best! There are still a lot of spatial functions to implement or creative ways to use spatial functions.

Credits

Originally inspired from grimzy/laravel-mysql-spatial and njbarrett's Laravel postgis package.

License

Spatial for Laravel is open-sourced software licensed under the MIT license.


All versions of laravel-spatial with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-pdo Version *
ext-json Version *
angel-source-labs/laravel-expressions Version ^1.0
doctrine/dbal Version ^2.6|^3.0
geo-io/wkb-parser Version ^1.0
jmikola/geojson Version ^1.0
laravel/framework Version >=6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package angel-source-labs/laravel-spatial contains the following files

Loading the files please wait ....