@@ -22,8 +22,7 @@ public function withDistance(
22
22
ExpressionContract |Geometry |string $ column ,
23
23
ExpressionContract |Geometry |string $ geometryOrColumn ,
24
24
string $ alias = 'distance '
25
- ): self
26
- {
25
+ ): self {
27
26
if (! $ this ->getQuery ()->columns ) {
28
27
$ this ->select ('* ' );
29
28
}
@@ -45,8 +44,7 @@ public function whereDistance(
45
44
ExpressionContract |Geometry |string $ geometryOrColumn ,
46
45
string $ operator ,
47
46
int |float $ value
48
- ): self
49
- {
47
+ ): self {
50
48
$ this ->whereRaw (
51
49
sprintf (
52
50
'ST_DISTANCE(%s, %s) %s ? ' ,
@@ -64,8 +62,7 @@ public function orderByDistance(
64
62
ExpressionContract |Geometry |string $ column ,
65
63
ExpressionContract |Geometry |string $ geometryOrColumn ,
66
64
string $ direction = 'asc '
67
- ): self
68
- {
65
+ ): self {
69
66
$ this ->orderByRaw (
70
67
sprintf (
71
68
'ST_DISTANCE(%s, %s) %s ' ,
@@ -82,8 +79,7 @@ public function withDistanceSphere(
82
79
ExpressionContract |Geometry |string $ column ,
83
80
ExpressionContract |Geometry |string $ geometryOrColumn ,
84
81
string $ alias = 'distance '
85
- ): self
86
- {
82
+ ): self {
87
83
if (! $ this ->getQuery ()->columns ) {
88
84
$ this ->select ('* ' );
89
85
}
@@ -105,8 +101,7 @@ public function whereDistanceSphere(
105
101
ExpressionContract |Geometry |string $ geometryOrColumn ,
106
102
string $ operator ,
107
103
int |float $ value
108
- ): self
109
- {
104
+ ): self {
110
105
$ this ->whereRaw (
111
106
sprintf (
112
107
'ST_DISTANCE_SPHERE(%s, %s) %s ? ' ,
@@ -124,8 +119,7 @@ public function orderByDistanceSphere(
124
119
ExpressionContract |Geometry |string $ column ,
125
120
ExpressionContract |Geometry |string $ geometryOrColumn ,
126
121
string $ direction = 'asc '
127
- ): self
128
- {
122
+ ): self {
129
123
$ this ->orderByRaw (
130
124
sprintf (
131
125
'ST_DISTANCE_SPHERE(%s, %s) %s ' ,
@@ -141,8 +135,7 @@ public function orderByDistanceSphere(
141
135
public function whereWithin (
142
136
ExpressionContract |Geometry |string $ column ,
143
137
ExpressionContract |Geometry |string $ geometryOrColumn ,
144
- ): self
145
- {
138
+ ): self {
146
139
$ this ->whereRaw (
147
140
sprintf (
148
141
'ST_WITHIN(%s, %s) ' ,
@@ -157,8 +150,7 @@ public function whereWithin(
157
150
public function whereNotWithin (
158
151
ExpressionContract |Geometry |string $ column ,
159
152
ExpressionContract |Geometry |string $ geometryOrColumn ,
160
- ): self
161
- {
153
+ ): self {
162
154
$ this ->whereRaw (
163
155
sprintf (
164
156
'ST_WITHIN(%s, %s) = 0 ' ,
@@ -173,8 +165,7 @@ public function whereNotWithin(
173
165
public function whereContains (
174
166
ExpressionContract |Geometry |string $ column ,
175
167
ExpressionContract |Geometry |string $ geometryOrColumn ,
176
- ): self
177
- {
168
+ ): self {
178
169
$ this ->whereRaw (
179
170
sprintf (
180
171
'ST_CONTAINS(%s, %s) ' ,
@@ -189,8 +180,7 @@ public function whereContains(
189
180
public function whereNotContains (
190
181
ExpressionContract |Geometry |string $ column ,
191
182
ExpressionContract |Geometry |string $ geometryOrColumn ,
192
- ): self
193
- {
183
+ ): self {
194
184
$ this ->whereRaw (
195
185
sprintf (
196
186
'ST_CONTAINS(%s, %s) = 0 ' ,
@@ -205,8 +195,7 @@ public function whereNotContains(
205
195
public function whereTouches (
206
196
ExpressionContract |Geometry |string $ column ,
207
197
ExpressionContract |Geometry |string $ geometryOrColumn ,
208
- ): self
209
- {
198
+ ): self {
210
199
$ this ->whereRaw (
211
200
sprintf (
212
201
'ST_TOUCHES(%s, %s) ' ,
@@ -221,8 +210,7 @@ public function whereTouches(
221
210
public function whereIntersects (
222
211
ExpressionContract |Geometry |string $ column ,
223
212
ExpressionContract |Geometry |string $ geometryOrColumn ,
224
- ): self
225
- {
213
+ ): self {
226
214
$ this ->whereRaw (
227
215
sprintf (
228
216
'ST_INTERSECTS(%s, %s) ' ,
@@ -237,8 +225,7 @@ public function whereIntersects(
237
225
public function whereCrosses (
238
226
ExpressionContract |Geometry |string $ column ,
239
227
ExpressionContract |Geometry |string $ geometryOrColumn ,
240
- ): self
241
- {
228
+ ): self {
242
229
$ this ->whereRaw (
243
230
sprintf (
244
231
'ST_CROSSES(%s, %s) ' ,
@@ -253,8 +240,7 @@ public function whereCrosses(
253
240
public function whereDisjoint (
254
241
ExpressionContract |Geometry |string $ column ,
255
242
ExpressionContract |Geometry |string $ geometryOrColumn ,
256
- ): self
257
- {
243
+ ): self {
258
244
$ this ->whereRaw (
259
245
sprintf (
260
246
'ST_DISJOINT(%s, %s) ' ,
@@ -269,8 +255,7 @@ public function whereDisjoint(
269
255
public function whereOverlaps (
270
256
ExpressionContract |Geometry |string $ column ,
271
257
ExpressionContract |Geometry |string $ geometryOrColumn ,
272
- ): self
273
- {
258
+ ): self {
274
259
$ this ->whereRaw (
275
260
sprintf (
276
261
'ST_OVERLAPS(%s, %s) ' ,
@@ -285,8 +270,7 @@ public function whereOverlaps(
285
270
public function whereEquals (
286
271
ExpressionContract |Geometry |string $ column ,
287
272
ExpressionContract |Geometry |string $ geometryOrColumn ,
288
- ): self
289
- {
273
+ ): self {
290
274
$ this ->whereRaw (
291
275
sprintf (
292
276
'ST_EQUALS(%s, %s) ' ,
@@ -302,8 +286,7 @@ public function whereSrid(
302
286
ExpressionContract |Geometry |string $ column ,
303
287
string $ operator ,
304
288
int |float $ value
305
- ): self
306
- {
289
+ ): self {
307
290
$ this ->whereRaw (
308
291
sprintf (
309
292
'ST_SRID(%s) %s ? ' ,
@@ -316,6 +299,21 @@ public function whereSrid(
316
299
return $ this ;
317
300
}
318
301
302
+ public function withCentroid (
303
+ ExpressionContract |Geometry |string $ column ,
304
+ string $ alias = 'centroid ' ,
305
+ ): self {
306
+ $ this ->selectRaw (
307
+ sprintf (
308
+ 'ST_CENTROID(%s) AS %s ' ,
309
+ $ this ->toExpressionString ($ column ),
310
+ $ this ->getGrammar ()->wrap ($ alias ),
311
+ )
312
+ );
313
+
314
+ return $ this ;
315
+ }
316
+
319
317
protected function toExpressionString (ExpressionContract |Geometry |string $ geometryOrColumnOrExpression ): string
320
318
{
321
319
$ grammar = $ this ->getGrammar ();
0 commit comments