ArangoDB

Accessing Geo Indexes via Http




GET /_api/index (creates a geo-spatial index)

POST /_api/index?collection=collection-identifier

Creates a geo-spatial index in the collection collection-identifier, if it does not already exist. Expects an object containing the index details.

  • type: must be equal to "geo".
  • fields: A list with one or two attribute paths.

    If it is a list with one attribute path location, then a geo-spatial index on all documents is created using location as path to the coordinates. The value of the attribute must be a list with at least two double values. The list must contain the latitude (first value) and the longitude (second value). All documents, which do not have the attribute path or with value that are not suitable, are ignored.

    If it is a list with two attribute paths latitude and longitude, then a geo-spatial index on all documents is created using latitude and longitude as paths the latitude and the longitude. The value of the attribute latitude and of the attribute longitude must a double. All documents, which do not have the attribute paths or which values are not suitable, are ignored.
  • geoJson: If a geo-spatial index on a location is constructed and geoJson is true, then the order within the list is longitude followed by latitude. This corresponds to the format described in

    http://geojson.org/geojson-spec.html#positions
  • constraint: If constraint is true, then a geo-spatial constraint instead of an index is created.
  • ignoreNull: If a geo-spatial constraint is created and ignoreNull is true, then documents with a null in location or at least one null in latitude or longitude are ignored.

If the index does not already exists and could be created, then a HTTP 201 is returned. If the index already exists, then a HTTP 200 is returned.

If the collection-identifier is unknown, then a HTTP 404 is returned. It is possible to specify a name instead of an identifier.

Examples

Creating a geo index with a location attribute:

> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=95560976
{ "type" : "geo", "fields" : [ "b" ] }

HTTP/1.1 201 Created
content-type: application/json

{
  "code": 201,
  "geoJson": false,
  "fields": [
    "b"
  ],
  "id": "95560976/162222265",
  "type": "geo1",
  "constraint" : false,
  "isNewlyCreated": true,
  "error": false
}

Creating a geo index with latitude and longitude attributes:

> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=99886352
{ "type" : "geo", "fields" : [ "e", "f" ] }

HTTP/1.1 201 Created
content-type: application/json

{
  "code": 201,
  "fields": [
    "e",
    "f"
  ],
  "id": "99886352/165564601",
  "type": "geo2",
  "constraint" : false,
  "isNewlyCreated": true,
  "error": false
}


PUT /_api/simple/near (executes simple query "near")

PUT /_api/simple/near

The default will find at most 100 documents near a given coordinate. The returned list is sorted according to the distance, with the nearest document coming first. If there are near documents of equal distance, documents are chosen randomly from this set until the limit is reached.

In order to use the near operator, a geo index must be defined for the collection. This index also defines which attribute holds the coordinates for the document. If you have more then one geo-spatial index, you can use the geo field to select a particular index.

The call expects a JSON hash array as body with the following attributes:

  • collection: The identifier or name of the collection to query.
  • latitude: The latitude of the coordinate.
  • longitude: The longitude of the coordinate.
  • distance: If given, the attribute key used to store the distance. (optional)
  • skip: The number of documents to skip in the query. (optional)
  • limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)
  • geo: If given, the identifier of the geo-index to use. (optional)

Returns a cursor containing the result, see HTTP Interface for AQL Query Cursors for details.

Examples

Without distance:

> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/near
{ "collection" : "11172897562", "latitude" : 0, "longitude" : 0, "skip" : 1, "limit" : 2 }

HTTP/1.1 201 Created
content-type: application/json

{
  "hasMore": false,
  "count": 5,
  "result": [
    {
      "_id": "11172897562/11178271514",
      "loc": [ 0, -10 ],
      "_rev": 11178271514
    },
    {
      "_id": "11172897562/11177616154",
      "loc": [ -10, 0 ],
      "_rev": 11177616154
    }
  ],
  "code": 201,
  "error": false
}

With distance:

> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/near
{ "collection" : "11182465818", "latitude" : 0, "longitude" : 0, "limit" : 2, "distance" : "distance" }

HTTP/1.1 201 Created
content-type: application/json

{
  "hasMore": false,
  "count": 5,
  "result": [
    {
      "distance": 0,
      "_id": "11182465818/11187905306",
      "loc": [ 0, 0 ],
      "_rev": 11187905306
    },
    {
      "distance": 1111949.26644559,
      "_id": "11182465818/11187839770",
      "loc": [ 0, -10 ],
      "_rev": 11187839770
    }
  ],
  "code": 201,
  "error": false
}


PUT /_api/simple/within (executes simple query "within")

PUT /_api/simple/within

This will find all documents with in a given radius around the coordinate (latitude, longitude). The returned list is sorted by distance.

In order to use the within operator, a geo index must be defined for the collection. This index also defines which attribute holds the coordinates for the document. If you have more then one geo-spatial index, you can use the geo field to select a particular index.

The call expects a JSON hash array as body with the following attributes:

  • collection: The identifier or name of the collection to query.
  • latitude: The latitude of the coordinate.
  • longitude: The longitude of the coordinate.
  • radius: The maximal radius (in meters).
  • distance: If given, the result attribute key used to store the distance values (optional). If specified, distances are returned in meters.
  • skip: The documents to skip in the query. (optional)
  • limit: The maximal amount of documents to return. (optional)
  • geo: If given, the identifier of the geo-index to use. (optional)

Returns a cursor containing the result, see HTTP Interface for AQL Query Cursors for details.

Examples

Without distance:

> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/within
{ "collection" : "2076584128", "latitude" : 0, "longitude" : 0, "skip" : 1, "radius" : 1111950 }

HTTP/1.1 201 Created
content-type: application/json

{
  "result": [
    {
      "_id": "2076584128/2082744512",
      "loc": [ 10, 0 ],
      "_rev": 2082744512
    },
    {
      "_id": "2076584128/2082089152",
      "loc": [ 0, 10 ],
      "_rev": 2082089152
    },
    {
      "_id": "2076584128/2081302720",
      "loc": [ -10, 0 ],
      "_rev": 2081302720
    },
    {
      "_id": "2076584128/2081958080",
      "loc": [ 0, -10 ],
      "_rev": 2081958080
    }
  ],
  "code": 201,
  "hasMore": false,
  "count": 4,
  "error": false
}

With distance:

> curl --data @- -X PUT --dump - http://localhost:8529/_api/simple/within
{ "collection" : "2086152384", "latitude" : 0, "longitude" : 0, "distance" : "distance", "radius" : 1111950 }

HTTP/1.1 201 Created
content-type: application/json

{
  "result": [
    {
      "distance": 0,
      "_id": "2086152384/2091591872",
      "loc": [ 0, 0 ],
      "_rev": 2091591872
    },
    {
      "distance": 1111949.26644559,
      "_id": "2086152384/2090870976",
      "loc": [ -10, 0 ],
      "_rev": 2090870976
    },
    {
      "distance": 1111949.26644559,
      "_id": "2086152384/2091657408",
      "loc": [ 0, 10 ],
      "_rev": 2091657408
    },
    {
      "distance": 1111949.26644559,
      "_id": "2086152384/2092312768",
      "loc": [ 10, 0 ],
      "_rev": 2092312768
    },
    {
      "distance": 1111949.26644559,
      "_id": "2086152384/2091526336",
      "loc": [ 0, -10 ],
      "_rev": 2091526336
    }
  ],
  "code": 201,
  "hasMore": false,
  "count": 5,
  "error": false
}