Skip to content

Commit f841bf1

Browse files
committed
Added documentation. Updated readme. Updated composer.json.
1 parent 625a99c commit f841bf1

File tree

4 files changed

+70
-21
lines changed

4 files changed

+70
-21
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Laravel package to easily work with [MySQL Spatial Data Types](https://dev.mysql
1111

1212
Please check the documentation for your MySQL version. MySQL's Extension for Spatial Data was added in MySQL 5.5 but many Spatial Functions were changed in 5.6 and 5.7.
1313

14+
**Versions**
15+
16+
- `1.x.x`: MySQL 5.6 (also supports MySQL 5.5 but not all spatial analysis functions)
17+
- `2.x.x`: MySQL 5.7 and 8.0
18+
1419
## Installation
1520

1621
Add the package using composer:
@@ -19,6 +24,12 @@ Add the package using composer:
1924
composer require grimzy/laravel-mysql-spatial
2025
```
2126

27+
For MySQL 5.6 and 5.5:
28+
29+
```shell
30+
composer require grimzy/laravel-mysql-spatial:^1.0
31+
```
32+
2233
Register the service provider in `config/app.php`:
2334

2435
```php
@@ -211,14 +222,35 @@ class UpdatePlacesTable extends Migration
211222

212223
Available geometry classes:
213224

214-
- Point
215-
- LineString
216-
- Polygon
217-
- MultiPoint
218-
- MultiLineString
219-
- MultiPolygon
220-
- GeometryCollection
221-
225+
- `Point($lat, $lng)`
226+
- `MultiPoint(Point[])`
227+
- `LineString(Point[])`
228+
- `MultiLineString(LineString[])`
229+
- `Polygon(LineString[])`
230+
- `MultiPolygon(Polygon[])`
231+
- `GeometryCollection(Geometry[])` *(a collection of spatial models)*
232+
233+
## Scopes: Spatial analysis functions
234+
235+
Spatial analysis functions are implemented using [Eloquent Local Scopes](https://laravel.com/docs/5.4/eloquent#local-scopes).
236+
237+
Available scopes:
238+
239+
- `distance($geometryColumn, $geometry, $distance)`
240+
- `distanceExcludingSelf($geometryColumn, $geometry, $distance)`
241+
- `distanceSphere($geometryColumn, $geometry, $distance)`
242+
- `distanceSphereExcludingSelf($geometryColumn, $geometry, $distance)`
243+
- `comparison($geometryColumn, $geometry, $relationship)`
244+
- `within($geometryColumn, $polygon)`
245+
- `crosses($geometryColumn, $geometry)`
246+
- `contains($geometryColumn, $geometry)`
247+
- `disjoint($geometryColumn, $geometry)`
248+
- `equals($geometryColumn, $geometry)`
249+
- `intersects($geometryColumn, $geometry)`
250+
- `overlaps($geometryColumn, $geometry)`
251+
- `touches($geometryColumn, $geometry)`
252+
253+
*Note that behavior and availability of MySQL spatial analysis functions differs in each MySQL version (cf. [documentation](https://dev.mysql.com/doc/refman/5.7/en/spatial-function-reference.html)).*
222254

223255
## Credits
224256

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"extra": {
3737
"branch-alias": {
38-
"dev-master": "1.0.x-dev"
38+
"dev-mysql-5.6": "1.0.x-dev"
3939
}
4040
}
4141
}

src/Eloquent/SpatialTrait.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77
use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
88
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
99

10+
/**
11+
* Trait SpatialTrait
12+
*
13+
* @method static distance($geometryColumn, $geometry, $distance)
14+
* @method static distanceExcludingSelf($geometryColumn, $geometry, $distance)
15+
* @method static distanceSphere($geometryColumn, $geometry, $distance)
16+
* @method static distanceSphereExcludingSelf($geometryColumn, $geometry, $distance)
17+
* @method static comparison($geometryColumn, $geometry, $relationship)
18+
* @method static within($geometryColumn, $polygon)
19+
* @method static crosses($geometryColumn, $geometry)
20+
* @method static contains($geometryColumn, $geometry)
21+
* @method static disjoint($geometryColumn, $geometry)
22+
* @method static equals($geometryColumn, $geometry)
23+
* @method static intersects($geometryColumn, $geometry)
24+
* @method static overlaps($geometryColumn, $geometry)
25+
* @method static touches($geometryColumn, $geometry)
26+
*/
1027
trait SpatialTrait
1128
{
1229
/*

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql()
194194
public function testScopeDistance()
195195
{
196196
$point = new Point(1, 2);
197-
$query = TestModel::Distance('point', $point, 10);
197+
$query = TestModel::distance('point', $point, 10);
198198

199199
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
200200
$q = $query->getQuery();
@@ -205,7 +205,7 @@ public function testScopeDistance()
205205
public function testScopeDistanceExcludingSelf()
206206
{
207207
$point = new Point(1, 2);
208-
$query = TestModel::Distance('point', $point, 10, true);
208+
$query = TestModel::distance('point', $point, 10, true);
209209

210210
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
211211
$q = $query->getQuery();
@@ -217,7 +217,7 @@ public function testScopeDistanceExcludingSelf()
217217
public function testScopeDistanceValue()
218218
{
219219
$point = new Point(1, 2);
220-
$query = TestModel::DistanceValue('point', $point);
220+
$query = TestModel::distanceValue('point', $point);
221221

222222
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
223223
$q = $query->getQuery();
@@ -257,7 +257,7 @@ private function buildTestPolygon()
257257

258258
public function testScopeComparison()
259259
{
260-
$query = TestModel::Comparison('point', $this->buildTestPolygon(), 'within');
260+
$query = TestModel::comparison('point', $this->buildTestPolygon(), 'within');
261261

262262
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
263263
$q = $query->getQuery();
@@ -267,7 +267,7 @@ public function testScopeComparison()
267267

268268
public function testScopeWithin()
269269
{
270-
$query = TestModel::Within('point', $this->buildTestPolygon());
270+
$query = TestModel::within('point', $this->buildTestPolygon());
271271

272272
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
273273
$q = $query->getQuery();
@@ -277,7 +277,7 @@ public function testScopeWithin()
277277

278278
public function testScopeCrosses()
279279
{
280-
$query = TestModel::Crosses('point', $this->buildTestPolygon());
280+
$query = TestModel::crosses('point', $this->buildTestPolygon());
281281

282282
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
283283
$q = $query->getQuery();
@@ -287,7 +287,7 @@ public function testScopeCrosses()
287287

288288
public function testScopeContains()
289289
{
290-
$query = TestModel::Contains('point', $this->buildTestPolygon());
290+
$query = TestModel::contains('point', $this->buildTestPolygon());
291291

292292
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
293293
$q = $query->getQuery();
@@ -297,7 +297,7 @@ public function testScopeContains()
297297

298298
public function testScopeDisjoint()
299299
{
300-
$query = TestModel::Disjoint('point', $this->buildTestPolygon());
300+
$query = TestModel::disjoint('point', $this->buildTestPolygon());
301301

302302
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
303303
$q = $query->getQuery();
@@ -307,7 +307,7 @@ public function testScopeDisjoint()
307307

308308
public function testScopeEquals()
309309
{
310-
$query = TestModel::Equals('point', $this->buildTestPolygon());
310+
$query = TestModel::equals('point', $this->buildTestPolygon());
311311

312312
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
313313
$q = $query->getQuery();
@@ -317,7 +317,7 @@ public function testScopeEquals()
317317

318318
public function testScopeIntersects()
319319
{
320-
$query = TestModel::Intersects('point', $this->buildTestPolygon());
320+
$query = TestModel::intersects('point', $this->buildTestPolygon());
321321

322322
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
323323
$q = $query->getQuery();
@@ -327,7 +327,7 @@ public function testScopeIntersects()
327327

328328
public function testScopeOverlaps()
329329
{
330-
$query = TestModel::Overlaps('point', $this->buildTestPolygon());
330+
$query = TestModel::overlaps('point', $this->buildTestPolygon());
331331

332332
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
333333
$q = $query->getQuery();
@@ -337,7 +337,7 @@ public function testScopeOverlaps()
337337

338338
public function testScopeDoesTouch()
339339
{
340-
$query = TestModel::DoesTouch('point', $this->buildTestPolygon());
340+
$query = TestModel::doesTouch('point', $this->buildTestPolygon());
341341

342342
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
343343
$q = $query->getQuery();

0 commit comments

Comments
 (0)