@@ -33,20 +33,20 @@ In addition, `GeometryCollection` also has these functions:
3333$geometryCollection = new GeometryCollection([
3434 new Polygon([
3535 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 ),
4141 ]),
4242 ]),
43- new Point(180, 0 ),
43+ new Point(0, 180 ),
4444 ]),
4545]);
4646
47- echo $geometryCollection->getGeometries()[1]->latitude; // 180
47+ echo $geometryCollection->getGeometries()[1]->latitude; // 0
4848// or access as an array:
49- echo $geometryCollection[1]->latitude; // 180
49+ echo $geometryCollection[1]->latitude; // 0
5050```
5151
5252## Available spatial scopes
@@ -79,20 +79,20 @@ Retrieves the distance between 2 geometry objects. Uses [ST_Distance](https://de
7979<details ><summary >Example</summary >
8080
8181``` php
82- Place::create(['location' => new Point(0, 0)]);
82+ Place::create(['location' => new Point(0, 0, 4326 )]);
8383
8484$placeWithDistance = Place::query()
85- ->withDistance('location', new Point(1, 1))
85+ ->withDistance('location', new Point(1, 1, 4326 ))
8686 ->first();
8787
88- echo $placeWithDistance->distance; // 1.4142135623731
88+ echo $placeWithDistance->distance; // 156897.79947260793
8989
9090// when using alias:
9191$placeWithDistance = Place::query()
92- ->withDistance('location', new Point(1, 1), 'distance_in_meters')
92+ ->withDistance('location', new Point(1, 1, 4326 ), 'distance_in_meters')
9393 ->first();
9494
95- echo $placeWithDistance->distance_in_meters; // 1.4142135623731
95+ echo $placeWithDistance->distance_in_meters; // 156897.79947260793
9696```
9797</details >
9898
@@ -110,11 +110,11 @@ Filters records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman
110110<details ><summary >Example</summary >
111111
112112``` 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 )]);
115115
116116$placesCountWithinDistance = Place::query()
117- ->whereDistance('location', new Point(1, 1), '<', 1.5 )
117+ ->whereDistance('location', new Point(1, 1, 4326 ), '<', 160000 )
118118 ->count();
119119
120120echo $placesCountWithinDistance; // 1
@@ -136,15 +136,15 @@ Orders records by distance. Uses [ST_Distance](https://dev.mysql.com/doc/refman/
136136``` php
137137Place::create([
138138 'name' => 'first',
139- 'location' => new Point(0, 0),
139+ 'location' => new Point(0, 0, 4326 ),
140140]);
141141Place::create([
142142 'name' => 'second',
143- 'location' => new Point(100, 100 ),
143+ 'location' => new Point(50, 50, 4326 ),
144144]);
145145
146146$places = Place::query()
147- ->orderByDistance('location', new Point(1, 1), 'desc')
147+ ->orderByDistance('location', new Point(1, 1, 4326 ), 'desc')
148148 ->get();
149149
150150echo $places[0]->name; // second
@@ -165,20 +165,20 @@ Retrieves the spherical distance between 2 geometry objects. Uses [ST_Distance_S
165165<details ><summary >Example</summary >
166166
167167``` php
168- Place::create(['location' => new Point(0, 0)]);
168+ Place::create(['location' => new Point(0, 0, 4326 )]);
169169
170170$placeWithDistance = Place::query()
171- ->withDistanceSphere('location', new Point(1, 1))
171+ ->withDistanceSphere('location', new Point(1, 1, 4326 ))
172172 ->first();
173173
174- echo $placeWithDistance->distance; // 157249.0357231545
174+ echo $placeWithDistance->distance; // 157249.59776850493
175175
176176// when using alias:
177177$placeWithDistance = Place::query()
178- ->withDistanceSphere('location', new Point(1, 1), 'distance_in_meters')
178+ ->withDistanceSphere('location', new Point(1, 1, 4326 ), 'distance_in_meters')
179179 ->first();
180180
181- echo $placeWithDistance->distance_in_meters; // 157249.0357231545
181+ echo $placeWithDistance->distance_in_meters; // 157249.59776850493
182182```
183183</details >
184184
@@ -196,11 +196,11 @@ Filters records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mys
196196<details ><summary >Example</summary >
197197
198198``` 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 )]);
201201
202202$placesCountWithinDistance = Place::query()
203- ->whereDistanceSphere('location', new Point(1, 1), '<', 160000)
203+ ->whereDistanceSphere('location', new Point(1, 1, 4326 ), '<', 160000)
204204 ->count();
205205
206206echo $placesCountWithinDistance; // 1
@@ -222,15 +222,15 @@ Orders records by spherical distance. Uses [ST_Distance_Sphere](https://dev.mysq
222222``` php
223223Place::create([
224224 'name' => 'first',
225- 'location' => new Point(0, 0),
225+ 'location' => new Point(0, 0, 4326 ),
226226]);
227227Place::create([
228228 'name' => 'second',
229- 'location' => new Point(100, 100),
229+ 'location' => new Point(100, 100, 4326 ),
230230]);
231231
232232$places = Place::query()
233- ->orderByDistanceSphere('location', new Point(1, 1), 'desc')
233+ ->orderByDistanceSphere('location', new Point(1, 1, 4326 ), 'desc')
234234 ->get();
235235
236236echo $places[0]->name; // second
@@ -250,7 +250,7 @@ Filters records by the [ST_Within](https://dev.mysql.com/doc/refman/8.0/en/spati
250250<details ><summary >Example</summary >
251251
252252``` php
253- Place::create(['location' => new Point(0, 0)]);
253+ Place::create(['location' => new Point(0, 0, 4326 )]);
254254
255255Place::query()
256256 ->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
273273Place::create(['area' => Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}'),]);
274274
275275Place::query()
276- ->whereContains('area', new Point(0, 0))
276+ ->whereContains('area', new Point(0, 0, 4326 ))
277277 ->exists(); // true
278278```
279279</details >
@@ -290,7 +290,7 @@ Filters records by the [ST_Touches](https://dev.mysql.com/doc/refman/8.0/en/spat
290290<details ><summary >Example</summary >
291291
292292``` php
293- Place::create(['location' => new Point(0, 0)]);
293+ Place::create(['location' => new Point(0, 0, 4326 )]);
294294
295295Place::query()
296296 ->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
310310<details ><summary >Example</summary >
311311
312312``` php
313- Place::create(['location' => new Point(0, 0)]);
313+ Place::create(['location' => new Point(0, 0, 4326 )]);
314314
315315Place::query()
316316 ->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
350350<details ><summary >Example</summary >
351351
352352``` php
353- Place::create(['location' => new Point(0, 0)]);
353+ Place::create(['location' => new Point(0, 0, 4326 )]);
354354
355355Place::query()
356356 ->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
370370<details ><summary >Example</summary >
371371
372372``` php
373- Place::create(['location' => new Point(0, 0)]);
373+ Place::create(['location' => new Point(0, 0, 4326 )]);
374374
375375Place::query()
376- ->whereEquals('location', new Point(0, 0))
376+ ->whereEquals('location', new Point(0, 0, 4326 ))
377377 ->exists(); // true
378378```
379379</details >
0 commit comments