@@ -33,20 +33,20 @@ In addition, `GeometryCollection` also has these functions:
33
33
$geometryCollection = new GeometryCollection([
34
34
new Polygon([
35
35
new LineString([
36
- new Point(180, 0 ),
37
- new Point(179, 1 ),
38
- new Point(178, 2 ),
39
- new Point(177, 3 ),
40
- new Point(180, 0 ),
36
+ new Point(0, 180 ),
37
+ new Point(1, 179 ),
38
+ new Point(2, 178 ),
39
+ new Point(3, 177 ),
40
+ new Point(0, 180 ),
41
41
]),
42
42
]),
43
- new Point(180, 0 ),
43
+ new Point(0, 180 ),
44
44
]),
45
45
]);
46
46
47
- echo $geometryCollection->getGeometries()[1]->latitude; // 180
47
+ echo $geometryCollection->getGeometries()[1]->latitude; // 0
48
48
// or access as an array:
49
- echo $geometryCollection[1]->latitude; // 180
49
+ echo $geometryCollection[1]->latitude; // 0
50
50
```
51
51
52
52
## Available spatial scopes
@@ -79,20 +79,20 @@ Retrieves the distance between 2 geometry objects. Uses [ST_Distance](https://de
79
79
<details ><summary >Example</summary >
80
80
81
81
``` php
82
- Place::create(['location' => new Point(0, 0)]);
82
+ Place::create(['location' => new Point(0, 0, 4326 )]);
83
83
84
84
$placeWithDistance = Place::query()
85
- ->withDistance('location', new Point(1, 1))
85
+ ->withDistance('location', new Point(1, 1, 4326 ))
86
86
->first();
87
87
88
- echo $placeWithDistance->distance; // 1.4142135623731
88
+ echo $placeWithDistance->distance; // 156897.79947260793
89
89
90
90
// when using alias:
91
91
$placeWithDistance = Place::query()
92
- ->withDistance('location', new Point(1, 1), 'distance_in_meters')
92
+ ->withDistance('location', new Point(1, 1, 4326 ), 'distance_in_meters')
93
93
->first();
94
94
95
- echo $placeWithDistance->distance_in_meters; // 1.4142135623731
95
+ echo $placeWithDistance->distance_in_meters; // 156897.79947260793
96
96
```
97
97
</details >
98
98
@@ -110,11 +110,11 @@ Filters records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman
110
110
<details ><summary >Example</summary >
111
111
112
112
``` php
113
- Place::create(['location' => new Point(0, 0)]);
114
- Place::create(['location' => new Point(100, 100 )]);
113
+ Place::create(['location' => new Point(0, 0, 4326 )]);
114
+ Place::create(['location' => new Point(50, 50, 4326 )]);
115
115
116
116
$placesCountWithinDistance = Place::query()
117
- ->whereDistance('location', new Point(1, 1), '<', 1.5 )
117
+ ->whereDistance('location', new Point(1, 1, 4326 ), '<', 160000 )
118
118
->count();
119
119
120
120
echo $placesCountWithinDistance; // 1
@@ -136,15 +136,15 @@ Orders records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman/
136
136
``` php
137
137
Place::create([
138
138
'name' => 'first',
139
- 'location' => new Point(0, 0),
139
+ 'location' => new Point(0, 0, 4326 ),
140
140
]);
141
141
Place::create([
142
142
'name' => 'second',
143
- 'location' => new Point(100, 100 ),
143
+ 'location' => new Point(50, 50, 4326 ),
144
144
]);
145
145
146
146
$places = Place::query()
147
- ->orderByDistance('location', new Point(1, 1), 'desc')
147
+ ->orderByDistance('location', new Point(1, 1, 4326 ), 'desc')
148
148
->get();
149
149
150
150
echo $places[0]->name; // second
@@ -165,20 +165,20 @@ Retrieves the spherical distance between 2 geometry objects. Uses [ST_Distance_S
165
165
<details ><summary >Example</summary >
166
166
167
167
``` php
168
- Place::create(['location' => new Point(0, 0)]);
168
+ Place::create(['location' => new Point(0, 0, 4326 )]);
169
169
170
170
$placeWithDistance = Place::query()
171
- ->withDistanceSphere('location', new Point(1, 1))
171
+ ->withDistanceSphere('location', new Point(1, 1, 4326 ))
172
172
->first();
173
173
174
- echo $placeWithDistance->distance; // 157249.0357231545
174
+ echo $placeWithDistance->distance; // 157249.59776850493
175
175
176
176
// when using alias:
177
177
$placeWithDistance = Place::query()
178
- ->withDistanceSphere('location', new Point(1, 1), 'distance_in_meters')
178
+ ->withDistanceSphere('location', new Point(1, 1, 4326 ), 'distance_in_meters')
179
179
->first();
180
180
181
- echo $placeWithDistance->distance_in_meters; // 157249.0357231545
181
+ echo $placeWithDistance->distance_in_meters; // 157249.59776850493
182
182
```
183
183
</details >
184
184
@@ -196,11 +196,11 @@ Filters records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mys
196
196
<details ><summary >Example</summary >
197
197
198
198
``` php
199
- Place::create(['location' => new Point(0, 0)]);
200
- Place::create(['location' => new Point(100, 100 )]);
199
+ Place::create(['location' => new Point(0, 0, 4326 )]);
200
+ Place::create(['location' => new Point(50, 50, 4326 )]);
201
201
202
202
$placesCountWithinDistance = Place::query()
203
- ->whereDistanceSphere('location', new Point(1, 1), '<', 160000)
203
+ ->whereDistanceSphere('location', new Point(1, 1, 4326 ), '<', 160000)
204
204
->count();
205
205
206
206
echo $placesCountWithinDistance; // 1
@@ -222,15 +222,15 @@ Orders records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mysq
222
222
``` php
223
223
Place::create([
224
224
'name' => 'first',
225
- 'location' => new Point(0, 0),
225
+ 'location' => new Point(0, 0, 4326 ),
226
226
]);
227
227
Place::create([
228
228
'name' => 'second',
229
- 'location' => new Point(100, 100),
229
+ 'location' => new Point(100, 100, 4326 ),
230
230
]);
231
231
232
232
$places = Place::query()
233
- ->orderByDistanceSphere('location', new Point(1, 1), 'desc')
233
+ ->orderByDistanceSphere('location', new Point(1, 1, 4326 ), 'desc')
234
234
->get();
235
235
236
236
echo $places[0]->name; // second
@@ -250,7 +250,7 @@ Filters records by the [ST_Within](https://dev.mysql.com/doc/refman/8.0/en/spati
250
250
<details ><summary >Example</summary >
251
251
252
252
``` php
253
- Place::create(['location' => new Point(0, 0)]);
253
+ Place::create(['location' => new Point(0, 0, 4326 )]);
254
254
255
255
Place::query()
256
256
->whereWithin('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'))
@@ -273,7 +273,7 @@ Filters records by the [ST_Contains](https://dev.mysql.com/doc/refman/8.0/en/spa
273
273
Place::create(['area' => Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'),]);
274
274
275
275
Place::query()
276
- ->whereContains('area', new Point(0, 0))
276
+ ->whereContains('area', new Point(0, 0, 4326 ))
277
277
->exists(); // true
278
278
```
279
279
</details >
@@ -290,7 +290,7 @@ Filters records by the [ST_Touches](https://dev.mysql.com/doc/refman/8.0/en/spat
290
290
<details ><summary >Example</summary >
291
291
292
292
``` php
293
- Place::create(['location' => new Point(0, 0)]);
293
+ Place::create(['location' => new Point(0, 0, 4326 )]);
294
294
295
295
Place::query()
296
296
->whereTouches('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[0,-1],[0,0],[-1,0],[-1,-1]]]}'))
@@ -310,7 +310,7 @@ Filters records by the [ST_Intersects](https://dev.mysql.com/doc/refman/8.0/en/s
310
310
<details ><summary >Example</summary >
311
311
312
312
``` php
313
- Place::create(['location' => new Point(0, 0)]);
313
+ Place::create(['location' => new Point(0, 0, 4326 )]);
314
314
315
315
Place::query()
316
316
->whereIntersects('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'))
@@ -350,7 +350,7 @@ Filters records by the [ST_Disjoint](https://dev.mysql.com/doc/refman/8.0/en/spa
350
350
<details ><summary >Example</summary >
351
351
352
352
``` php
353
- Place::create(['location' => new Point(0, 0)]);
353
+ Place::create(['location' => new Point(0, 0, 4326 )]);
354
354
355
355
Place::query()
356
356
->whereDisjoint('location', Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[-0.5,-1],[-0.5,-0.5],[-1,-0.5],[-1,-1]]]}'))
@@ -370,10 +370,10 @@ Filters records by the [ST_Equal](https://dev.mysql.com/doc/refman/8.0/en/spatia
370
370
<details ><summary >Example</summary >
371
371
372
372
``` php
373
- Place::create(['location' => new Point(0, 0)]);
373
+ Place::create(['location' => new Point(0, 0, 4326 )]);
374
374
375
375
Place::query()
376
- ->whereEquals('location', new Point(0, 0))
376
+ ->whereEquals('location', new Point(0, 0, 4326 ))
377
377
->exists(); // true
378
378
```
379
379
</details >
0 commit comments