Skip to content

Commit 445bb61

Browse files
committed
Add spatial queries
1 parent b7760d1 commit 445bb61

File tree

1 file changed

+116
-0
lines changed
  • library/src/main/java/io/appwrite

1 file changed

+116
-0
lines changed

library/src/main/java/io/appwrite/Query.kt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,122 @@ class Query(
304304
*/
305305
fun and(queries: List<String>) = Query("and", null, queries.map { it.fromJson<Query>() }).toJson()
306306

307+
/**
308+
* Filter resources where attribute is at a specific distance from the given coordinates.
309+
*
310+
* @param attribute The attribute to filter on.
311+
* @param values The coordinate values.
312+
* @param distance The distance value.
313+
* @param meters Whether the distance is in meters.
314+
* @returns The query string.
315+
*/
316+
fun distanceEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceEqual", attribute, listOf(values, distance, meters)).toJson()
317+
318+
/**
319+
* Filter resources where attribute is not at a specific distance from the given coordinates.
320+
*
321+
* @param attribute The attribute to filter on.
322+
* @param values The coordinate values.
323+
* @param distance The distance value.
324+
* @param meters Whether the distance is in meters.
325+
* @returns The query string.
326+
*/
327+
fun distanceNotEqual(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceNotEqual", attribute, listOf(values, distance, meters)).toJson()
328+
329+
/**
330+
* Filter resources where attribute is at a distance greater than the specified value from the given coordinates.
331+
*
332+
* @param attribute The attribute to filter on.
333+
* @param values The coordinate values.
334+
* @param distance The distance value.
335+
* @param meters Whether the distance is in meters.
336+
* @returns The query string.
337+
*/
338+
fun distanceGreaterThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceGreaterThan", attribute, listOf(values, distance, meters)).toJson()
339+
340+
/**
341+
* Filter resources where attribute is at a distance less than the specified value from the given coordinates.
342+
*
343+
* @param attribute The attribute to filter on.
344+
* @param values The coordinate values.
345+
* @param distance The distance value.
346+
* @param meters Whether the distance is in meters.
347+
* @returns The query string.
348+
*/
349+
fun distanceLessThan(attribute: String, values: List<Any>, distance: Number, meters: Boolean = true) = Query("distanceLessThan", attribute, listOf(values, distance, meters)).toJson()
350+
351+
/**
352+
* Filter resources where attribute intersects with the given geometry.
353+
*
354+
* @param attribute The attribute to filter on.
355+
* @param values The coordinate values.
356+
* @returns The query string.
357+
*/
358+
fun intersects(attribute: String, values: List<Any>) = Query("intersects", attribute, values).toJson()
359+
360+
/**
361+
* Filter resources where attribute does not intersect with the given geometry.
362+
*
363+
* @param attribute The attribute to filter on.
364+
* @param values The coordinate values.
365+
* @returns The query string.
366+
*/
367+
fun notIntersects(attribute: String, values: List<Any>) = Query("notIntersects", attribute, values).toJson()
368+
369+
/**
370+
* Filter resources where attribute crosses the given geometry.
371+
*
372+
* @param attribute The attribute to filter on.
373+
* @param values The coordinate values.
374+
* @returns The query string.
375+
*/
376+
fun crosses(attribute: String, values: List<Any>) = Query("crosses", attribute, values).toJson()
377+
378+
/**
379+
* Filter resources where attribute does not cross the given geometry.
380+
*
381+
* @param attribute The attribute to filter on.
382+
* @param values The coordinate values.
383+
* @returns The query string.
384+
*/
385+
fun notCrosses(attribute: String, values: List<Any>) = Query("notCrosses", attribute, values).toJson()
386+
387+
/**
388+
* Filter resources where attribute overlaps with the given geometry.
389+
*
390+
* @param attribute The attribute to filter on.
391+
* @param values The coordinate values.
392+
* @returns The query string.
393+
*/
394+
fun overlaps(attribute: String, values: List<Any>) = Query("overlaps", attribute, values).toJson()
395+
396+
/**
397+
* Filter resources where attribute does not overlap with the given geometry.
398+
*
399+
* @param attribute The attribute to filter on.
400+
* @param values The coordinate values.
401+
* @returns The query string.
402+
*/
403+
fun notOverlaps(attribute: String, values: List<Any>) = Query("notOverlaps", attribute, values).toJson()
404+
405+
/**
406+
* Filter resources where attribute touches the given geometry.
407+
*
408+
* @param attribute The attribute to filter on.
409+
* @param values The coordinate values.
410+
* @returns The query string.
411+
*/
412+
fun touches(attribute: String, values: List<Any>) = Query("touches", attribute, values).toJson()
413+
414+
/**
415+
* Filter resources where attribute does not touch the given geometry.
416+
*
417+
* @param attribute The attribute to filter on.
418+
* @param values The coordinate values.
419+
* @returns The query string.
420+
*/
421+
fun notTouches(attribute: String, values: List<Any>) = Query("notTouches", attribute, values).toJson()
422+
307423
/**
308424
* Parse the value to a list of values.
309425
*

0 commit comments

Comments
 (0)