|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
|
6
|
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
|
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression; |
|
9
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Geo AQL functions. |
|
13
|
|
|
* |
|
14
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-geo.html |
|
15
|
|
|
*/ |
|
16
|
|
|
trait HasGeoFunctions |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Calculate the distance between two coordinates with the Haversine formula. |
|
20
|
|
|
* |
|
21
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#distance |
|
22
|
|
|
* |
|
23
|
|
|
* @param mixed $latitude1 |
|
24
|
|
|
* @param mixed $longitude1 |
|
25
|
|
|
* @param mixed $latitude2 |
|
26
|
|
|
* @param mixed $longitude2 |
|
27
|
|
|
* |
|
28
|
|
|
* @return FunctionExpression |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function distance($latitude1, $longitude1, $latitude2, $longitude2): FunctionExpression |
|
31
|
|
|
{ |
|
32
|
2 |
|
return new FunctionExpression('DISTANCE', [$latitude1, $longitude1, $latitude2, $longitude2]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Return the area in m² for a polygon or multi-polygon on a sphere with the average Earth radius, or an ellipsoid. |
|
37
|
|
|
* |
|
38
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_area |
|
39
|
|
|
* |
|
40
|
|
|
* @param string|array<mixed>|object $geoJson |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function geoArea( |
|
43
|
|
|
string|array|object $geoJson, |
|
44
|
|
|
string|object $ellipsoid = "sphere" |
|
45
|
|
|
): FunctionExpression { |
|
46
|
1 |
|
return new FunctionExpression('GEO_AREA', [$geoJson, $ellipsoid]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Checks whether the GeoJSON object geoJsonA fully contains geoJsonB (Every point in B is also in A). |
|
51
|
|
|
* |
|
52
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_contains |
|
53
|
|
|
* |
|
54
|
|
|
* @param string|array<mixed>|object $geoJsonA |
|
55
|
|
|
* @param string|array<mixed>|object $geoJsonB |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function geoContains( |
|
58
|
|
|
string|array|object $geoJsonA, |
|
59
|
|
|
string|array|object $geoJsonB |
|
60
|
|
|
): FunctionExpression { |
|
61
|
1 |
|
return new FunctionExpression('GEO_CONTAINS', [$geoJsonA, $geoJsonB]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Return the distance between two GeoJSON objects, measured from the centroid of each shape. |
|
66
|
|
|
* |
|
67
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_distance |
|
68
|
|
|
* |
|
69
|
|
|
* @param string|array<mixed>|object $geoJsonA |
|
70
|
|
|
* @param string|array<mixed>|object $geoJsonB |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function geoDistance( |
|
73
|
|
|
string|array|object $geoJsonA, |
|
74
|
|
|
string|array|object $geoJsonB, |
|
75
|
|
|
string|QueryBuilder|Expression $ellipsoid = "sphere" |
|
76
|
|
|
): FunctionExpression { |
|
77
|
1 |
|
return new FunctionExpression('GEO_DISTANCE', [$geoJsonA, $geoJsonB, $ellipsoid]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Checks whether two GeoJSON objects are equal or not. |
|
82
|
|
|
* |
|
83
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_equals |
|
84
|
|
|
* |
|
85
|
|
|
* @param string|array<mixed>|object $geoJsonA |
|
86
|
|
|
* @param string|array<mixed>|object $geoJsonB |
|
87
|
|
|
* @return FunctionExpression |
|
88
|
|
|
*/ |
|
89
|
1 |
|
public function geoEquals( |
|
90
|
|
|
string|array|object $geoJsonA, |
|
91
|
|
|
string|array|object $geoJsonB |
|
92
|
|
|
): FunctionExpression { |
|
93
|
1 |
|
return new FunctionExpression('GEO_EQUALS', [$geoJsonA, $geoJsonB]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Checks whether the GeoJSON object geoJsonA intersects with geoJsonB |
|
98
|
|
|
* |
|
99
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_intersects |
|
100
|
|
|
* |
|
101
|
|
|
* @param string|array<mixed>|Object|object $geoJsonA |
|
102
|
|
|
* @param string|array<mixed>|Object|object $geoJsonB |
|
103
|
|
|
* @return FunctionExpression |
|
104
|
|
|
*/ |
|
105
|
1 |
|
public function geoIntersects(mixed $geoJsonA, mixed $geoJsonB): FunctionExpression |
|
106
|
|
|
{ |
|
107
|
1 |
|
return new FunctionExpression('GEO_INTERSECTS', [$geoJsonA, $geoJsonB]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Checks whether the distance between two GeoJSON objects lies within a given interval. |
|
113
|
|
|
* |
|
114
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_in_range |
|
115
|
|
|
* |
|
116
|
|
|
* @param array<mixed>|object|string $geoJsonA |
|
117
|
|
|
* @param array<mixed>|object|string $geoJsonB |
|
118
|
|
|
*/ |
|
119
|
2 |
|
public function geoInRange( |
|
120
|
|
|
array|object|string $geoJsonA, |
|
121
|
|
|
array|object|string $geoJsonB, |
|
122
|
|
|
int|float|QueryBuilder|Expression $low, |
|
123
|
|
|
int|float|QueryBuilder|Expression $high, |
|
124
|
|
|
bool|QueryBuilder|Expression $includeLow = null, |
|
125
|
|
|
bool|QueryBuilder|Expression $includeHigh = null, |
|
126
|
|
|
): FunctionExpression { |
|
127
|
2 |
|
$arguments = [ |
|
128
|
2 |
|
"geoJsonA" => $geoJsonA, |
|
129
|
2 |
|
"geoJsonB" => $geoJsonB, |
|
130
|
2 |
|
"low" => $low, |
|
131
|
2 |
|
"high" => $high, |
|
132
|
2 |
|
"includeLow" => $includeLow, |
|
133
|
2 |
|
"includeHigh" => $includeHigh |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
2 |
|
$arguments = $this->unsetNullValues($arguments); |
|
|
|
|
|
|
137
|
|
|
|
|
138
|
2 |
|
return new FunctionExpression('GEO_IN_RANGE', $arguments); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Construct a GeoJSON LineString. Needs at least two longitude/latitude pairs. |
|
143
|
|
|
* |
|
144
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_linestring |
|
145
|
|
|
* |
|
146
|
|
|
* @param array<mixed>|object $points |
|
147
|
|
|
* @return FunctionExpression |
|
148
|
|
|
*/ |
|
149
|
1 |
|
public function geoLineString(mixed $points): FunctionExpression |
|
150
|
|
|
{ |
|
151
|
1 |
|
return new FunctionExpression('GEO_LINESTRING', [$points]); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Construct a GeoJSON MultiLineString. |
|
156
|
|
|
* Needs at least two elements consisting valid LineStrings coordinate arrays. |
|
157
|
|
|
* |
|
158
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_multilinestring |
|
159
|
|
|
* |
|
160
|
|
|
* @param array<mixed>|object $points |
|
161
|
|
|
* @return FunctionExpression |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function geoMultiLineString(mixed $points): FunctionExpression |
|
164
|
|
|
{ |
|
165
|
1 |
|
return new FunctionExpression('GEO_MULTILINESTRING', [$points]); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Construct a valid GeoJSON Point. |
|
170
|
|
|
* |
|
171
|
|
|
* https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_multipoint |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function geoPoint( |
|
174
|
|
|
int|float|object $longitude, |
|
175
|
|
|
int|float|object $latitude |
|
176
|
|
|
): FunctionExpression { |
|
177
|
1 |
|
return new FunctionExpression('GEO_POINT', [$longitude, $latitude]); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Construct a GeoJSON LineString. Needs at least two longitude/latitude pairs. |
|
182
|
|
|
* |
|
183
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_multipoint |
|
184
|
|
|
* |
|
185
|
|
|
* @param array<mixed>|object $points |
|
186
|
|
|
* @return FunctionExpression |
|
187
|
|
|
*/ |
|
188
|
1 |
|
public function geoMultiPoint(mixed $points): FunctionExpression |
|
189
|
|
|
{ |
|
190
|
1 |
|
return new FunctionExpression('GEO_MULTIPOINT', [$points]); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Construct a GeoJSON Polygon. Needs at least one array representing a loop. |
|
196
|
|
|
* |
|
197
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_polygon |
|
198
|
|
|
* |
|
199
|
|
|
* @param array<mixed>|object $points |
|
200
|
|
|
* @return FunctionExpression |
|
201
|
|
|
*/ |
|
202
|
1 |
|
public function geoPolygon(mixed $points): FunctionExpression |
|
203
|
|
|
{ |
|
204
|
1 |
|
return new FunctionExpression('GEO_POLYGON', [$points]); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Construct a GeoJSON MultiPolygon. Needs at least two Polygons inside. |
|
209
|
|
|
* |
|
210
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-geo.html#geo_polygon |
|
211
|
|
|
* |
|
212
|
|
|
* @param array<mixed>|object $points |
|
213
|
|
|
* @return FunctionExpression |
|
214
|
|
|
*/ |
|
215
|
1 |
|
public function geoMultiPolygon(mixed $points): FunctionExpression |
|
216
|
|
|
{ |
|
217
|
1 |
|
return new FunctionExpression('GEO_MULTIPOLYGON', [$points]); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|