1
0
Fork 0
arangodb/Documentation/Books/Manual/appendix-deprecated-simple-...

71 lines
2.2 KiB
Markdown

---
layout: default
description: It is recommended to use AQL instead, see Geo functions
---
Geo Queries
===========
{% hint 'warning' %}
It is recommended to use AQL instead, see [**Geo functions**](aql/functions-geo.html).
{% endhint %}
The ArangoDB allows to select documents based on geographic coordinates. In
order for this to work, a geo-spatial index must be defined. This index will
use a very elaborate algorithm to lookup neighbors that is a magnitude faster
than a simple R* index.
In general a geo coordinate is a pair of latitude and longitude, which must
both be specified as numbers. A geo index can be created on coordinates that
are stored in a single list attribute with two elements like *[-10, +30]*
(latitude first, followed by longitude) or on coordinates stored in two
separate attributes.
For example, to index the following documents, an index can be created on the
*position* attribute of the documents:
db.test.save({ position: [ -10, 30 ] });
db.test.save({ position: [ 10, 45.5 ] });
db.test.ensureIndex({ type: "geo", fields: [ "position" ] });
If coordinates are stored in two distinct attributes, the index must be created
on the two attributes:
db.test.save({ latitude: -10, longitude: 30 });
db.test.save({ latitude: 10, longitude: 45.5 });
db.test.ensureIndex({ type: "geo", fields: [ "latitude", "longitude" ] });
In order to find all documents within a given radius around a coordinate use
the *within* operator. In order to find all documents near a given document
use the *near* operator.
It is possible to define more than one geo-spatial index per collection. In
this case you must give a hint using the *geo* operator which of indexes
should be used in a query.
Near
----
<!-- js/common/modules/@arangodb/arango-collection-common.js-->
{% docublock collectionNear %}
Within
------
<!-- js/common/modules/@arangodb/arango-collection-common.js-->
{% docublock collectionWithin %}
Geo
---
<!-- js/common/modules/@arangodb/arango-collection-common.js-->
{% docublock collectionGeo %}
Related topics
--------------
Other ArangoDB geographic features are described in:
- [AQL Geo functions](aql/functions-geo.html)
- [Geo-Spatial indexes](indexing-geo.html)