Skip to content

Commit 8bd0ccb

Browse files
committed
Removed st_distance_sphere()
1 parent 45efeeb commit 8bd0ccb

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

src/Eloquent/SpatialTrait.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,6 @@ public function scopeDistance($query, $distance, $geometry, $column_name, $exclu
8383
return $query;
8484
}
8585

86-
public function scopeDistanceSphere($query, $distance, $geometry, $column_name, $exclude_self = false)
87-
{
88-
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) <= {$distance}");
89-
90-
if ($exclude_self) {
91-
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) != 0");
92-
}
93-
94-
return $query;
95-
}
96-
9786
public function scopeDistanceValue($query, $geometry, $column_name)
9887
{
9988
$columns = $query->getQuery()->columns;
@@ -104,16 +93,6 @@ public function scopeDistanceValue($query, $geometry, $column_name)
10493
$query->selectRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
10594
}
10695

107-
public function scopeDistanceSphereValue($query, $geometry, $column_name)
108-
{
109-
$columns = $query->getQuery()->columns;
110-
111-
if (! $columns) {
112-
$query->select('*');
113-
}
114-
$query->selectRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
115-
}
116-
11796
public function scopeBounding($query, Geometry $bounds, $column_name)
11897
{
11998
return $query->whereRaw("st_intersects(GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,6 @@ public function testScopeDistanceExcludingSelf()
214214
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
215215
}
216216

217-
public function testScopeDistanceSphere()
218-
{
219-
$point = new Point(1, 2);
220-
$query = TestModel::DistanceSphere(10, $point, 'point');
221-
222-
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
223-
$q = $query->getQuery();
224-
$this->assertNotEmpty($q->wheres);
225-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
226-
}
227-
228-
public function testScopeDistanceSphereExcludingSelf()
229-
{
230-
$point = new Point(1, 2);
231-
$query = TestModel::DistanceSphere(10, $point, 'point', true);
232-
233-
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
234-
$q = $query->getQuery();
235-
$this->assertNotEmpty($q->wheres);
236-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) <= 10", $q->wheres[0]['sql']);
237-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) != 0", $q->wheres[1]['sql']);
238-
}
239-
240217
public function testScopeDistanceValue()
241218
{
242219
$point = new Point(1, 2);
@@ -263,32 +240,6 @@ public function testScopeDistanceValueWithSelect()
263240
$this->assertContains("st_distance(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
264241
}
265242

266-
public function testScopeDistanceSphereValue()
267-
{
268-
$point = new Point(1, 2);
269-
$query = TestModel::DistanceSphereValue($point, 'point');
270-
271-
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
272-
$q = $query->getQuery();
273-
$this->assertNotEmpty($q->columns);
274-
$this->assertContains("*", $q->columns[0]);
275-
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
276-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
277-
}
278-
279-
public function testScopeDistanceSphereValueWithSelect()
280-
{
281-
$point = new Point(1, 2);
282-
$query = TestModel::select('some_column')->distanceSphereValue($point, 'point');
283-
284-
$this->assertInstanceOf(\Grimzy\LaravelMysqlSpatial\Eloquent\Builder::class, $query);
285-
$q = $query->getQuery();
286-
$this->assertNotEmpty($q->columns);
287-
$this->assertContains("some_column", $q->columns[0]);
288-
$this->assertInstanceOf(\Illuminate\Database\Query\Expression::class, $q->columns[1]);
289-
$this->assertContains("st_distance_sphere(`point`, GeomFromText('POINT(2 1)')) as distance", $q->columns[1]->getValue());
290-
}
291-
292243
private function buildTestPolygon(){
293244
$point1 = new Point(1, 1);
294245
$point2 = new Point(1, 2);

0 commit comments

Comments
 (0)