laravel / ideas

Issues board used for Laravel internals discussions.
940 stars 28 forks source link

[Feature Proposal] Spatial Queries in Eloquent #1253

Open davidpiesse opened 6 years ago

davidpiesse commented 6 years ago

Add Spatial relationship queries to core Eloquent.

MySQL, PostGres (w/ PostGIS), and SqlServer all have the ability to do spatial queries such as overlaps, crosses, intersects, and contains.

The proposal is to add a set of Eloquent queries that enable this functionality for example in a Eloquent Model:

public function scopeWithin($query, $someArea){
    $query->within('polygon_prop', $someArea);
}

The basis is that you have to declare the input property for a model that is a spatial field (point, linestring, polygon) and the geometry you are comparing it to.

List of new Queries that test a relationship between two geometries:

michaeldyrynda commented 6 years ago

I’d be interested in seeing what this looks like as a package first. I’m not sure the use case is common enough to include it in the framework, but a package would certainly be a good spot for it (there may already be one)

davidpiesse commented 6 years ago

@michaeldyrynda Thanks for the comment - I hope we get more opinions on this too! There is some out there in disparate packages such as https://github.com/grimzy/laravel-mysql-spatial https://github.com/eleven-lab/laravel-geo https://github.com/apptimists/laravel-spatial

All do it a different way and none are all encompassing of the underlying DB options. My falling off the fence into the 'inclusion in core' garden - was that we now have spatial types included already - this is just the next step on from this.

amsanket22 commented 4 years ago

Yes I am also of the same opinion, we should support at least basic geometry function as we need to rely on DB::raw() most of the times or on third party packages, so why not support these functions officially from the framework itself?