Oihana PHP Arango

geo

Table of Contents

Functions

distance()  : string
Return the distance between two coordinate pairs, in meters.
geoArea()  : string
Return the area of a GeoJSON Polygon or MultiPolygon, in square meters.
geoContains()  : string
Check whether one GeoJSON geometry fully contains another.
geoDistance()  : string
Return the distance between two GeoJSON geometries, in meters.
geoEquals()  : string
Check whether two GeoJSON geometries are equal.
geoInRange()  : string
Check whether the distance between two geometries falls within a range.
geoIntersects()  : string
Check whether two GeoJSON geometries intersect.
geoLineString()  : string
Build a GeoJSON LineString geometry.
geoMultiLineString()  : string
Build a GeoJSON MultiLineString geometry.
geoMultiPoint()  : string
Build a GeoJSON MultiPoint geometry.
geoMultiPolygon()  : string
Build a GeoJSON MultiPolygon geometry.
geoPoint()  : string
Build a GeoJSON Point geometry.
geoPolygon()  : string
Build a GeoJSON Polygon geometry.
isInPolygon()  : string
Check whether a coordinate lies inside a polygon (legacy).
near()  : string
Return the nearest documents of a collection to a coordinate (legacy).
within()  : string
Return documents of a collection within a radius of a coordinate (legacy).
withinRectangle()  : string
Return documents of a collection within a bounding rectangle (legacy).

Functions

distance()

Return the distance between two coordinate pairs, in meters.

distance(float|int|string $latitude1, float|int|string $longitude1, float|int|string $latitude2, float|int|string $longitude2) : string

This helper wraps the ArangoDB AQL function DISTANCE(latitude1, longitude1, latitude2, longitude2) which computes the great-circle (haversine) distance between two points given as separate scalar attributes. Unlike the GeoJSON functions, DISTANCE takes its coordinates in the latitude-first order.

This is the index-accelerated form when a geo index is declared over the two latitude / longitude attributes (geoJson: false), e.g. used in a FILTER DISTANCE(...) <= @radius or SORT DISTANCE(...) ASC LIMIT n.

Example AQL usage:

DISTANCE(doc.geo.latitude, doc.geo.longitude, 48.8566, 2.3522)
Parameters
$latitude1 : float|int|string

Latitude of the first point (or AQL expression).

$longitude1 : float|int|string

Longitude of the first point (or AQL expression).

$latitude2 : float|int|string

Latitude of the second point (or AQL expression).

$longitude2 : float|int|string

Longitude of the second point (or AQL expression).

Tags
example
use function oihana\arango\db\functions\geo\distance;

$expr = distance( 'doc.geo.latitude' , 'doc.geo.longitude' , 48.8566 , 2.3522 );
// Produces: 'DISTANCE(doc.geo.latitude,doc.geo.longitude,48.8566,2.3522)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#distance
geoDistance()

For the GeoJSON, longitude-first equivalent.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoArea()

Return the area of a GeoJSON Polygon or MultiPolygon, in square meters.

geoArea(array<string|int, mixed>|string $geo[, string|null $ellipsoid = null ]) : string

This helper wraps the ArangoDB AQL function GEO_AREA(geoJson, ellipsoid) which computes the area of a polygonal GeoJSON geometry. The optional ellipsoid ("sphere" or "wgs84") selects the reference model.

Example AQL usage:

GEO_AREA(doc.area)
GEO_AREA(doc.area, "wgs84")
Parameters
$geo : array<string|int, mixed>|string

The polygonal GeoJSON geometry (AQL expression or coordinates).

$ellipsoid : string|null = null

Optional reference ellipsoid: "sphere" (default) or "wgs84".

Tags
example
use function oihana\arango\db\functions\geo\geoArea;

$expr = geoArea( 'doc.area' , 'wgs84' );
// Produces: 'GEO_AREA(doc.area,"wgs84")'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_area
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoContains()

Check whether one GeoJSON geometry fully contains another.

geoContains(array<string|int, mixed>|string $container, array<string|int, mixed>|string $contained) : string

This helper wraps the ArangoDB AQL function GEO_CONTAINS(geoJsonA, geoJsonB) which returns true when geometry B is completely inside geometry A (a point inside a polygon, a polygon inside a larger polygon, …). Both arguments use the GeoJSON longitude-first convention.

Example AQL usage:

GEO_CONTAINS(doc.area, GEO_POINT(2.3522, 48.8566))
Parameters
$container : array<string|int, mixed>|string

The containing GeoJSON geometry (AQL expression or coordinates).

$contained : array<string|int, mixed>|string

The contained GeoJSON geometry (AQL expression or coordinates).

Tags
example
use function oihana\arango\db\functions\geo\geoContains;
use function oihana\arango\db\functions\geo\geoPoint;

$expr = geoContains( 'doc.area' , geoPoint( 48.8566 , 2.3522 ) );
// Produces: 'GEO_CONTAINS(doc.area,GEO_POINT(2.3522,48.8566))'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_contains
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoDistance()

Return the distance between two GeoJSON geometries, in meters.

geoDistance(array<string|int, mixed>|string $geo1, array<string|int, mixed>|string $geo2[, string|null $ellipsoid = null ]) : string

This helper wraps the ArangoDB AQL function GEO_DISTANCE(geoJson1, geoJson2, ellipsoid) which computes the shortest distance between two GeoJSON objects. Both arguments are GeoJSON geometries (built with geoPoint(), geoPolygon(), … or a document attribute), using the longitude-first coordinate convention. The optional ellipsoid ("sphere" or "wgs84") selects the reference model.

Example AQL usage:

GEO_DISTANCE(doc.geo, GEO_POINT(2.3522, 48.8566))
GEO_DISTANCE(doc.geo, @target, "wgs84")
Parameters
$geo1 : array<string|int, mixed>|string

First GeoJSON geometry (AQL expression or [longitude, latitude]).

$geo2 : array<string|int, mixed>|string

Second GeoJSON geometry (AQL expression or [longitude, latitude]).

$ellipsoid : string|null = null

Optional reference ellipsoid: "sphere" (default) or "wgs84".

Tags
example
use function oihana\arango\db\functions\geo\geoDistance;
use function oihana\arango\db\functions\geo\geoPoint;

$expr = geoDistance( 'doc.geo' , geoPoint( 48.8566 , 2.3522 ) );
// Produces: 'GEO_DISTANCE(doc.geo,GEO_POINT(2.3522,48.8566))'

$expr = geoDistance( 'doc.geo' , '@target' , 'wgs84' );
// Produces: 'GEO_DISTANCE(doc.geo,@target,"wgs84")'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_distance
distance()

For the latitude-first scalar equivalent.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoEquals()

Check whether two GeoJSON geometries are equal.

geoEquals(array<string|int, mixed>|string $geo1, array<string|int, mixed>|string $geo2) : string

This helper wraps the ArangoDB AQL function GEO_EQUALS(geoJsonA, geoJsonB) which returns true when both geometries describe the same shape. Both arguments use the GeoJSON longitude-first convention.

Example AQL usage:

GEO_EQUALS(doc.geo, GEO_POINT(2.3522, 48.8566))
Parameters
$geo1 : array<string|int, mixed>|string

First GeoJSON geometry (AQL expression or coordinates).

$geo2 : array<string|int, mixed>|string

Second GeoJSON geometry (AQL expression or coordinates).

Tags
example
use function oihana\arango\db\functions\geo\geoEquals;

$expr = geoEquals( 'doc.geo' , '@target' );
// Produces: 'GEO_EQUALS(doc.geo,@target)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_equals
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoInRange()

Check whether the distance between two geometries falls within a range.

geoInRange(array<string|int, mixed>|string $geo1, array<string|int, mixed>|string $geo2, float|int|string $low, float|int|string $high[, bool|null $includeLow = null ][, bool|null $includeHigh = null ]) : string

This helper wraps the ArangoDB AQL function GEO_IN_RANGE(geoJson1, geoJson2, low, high, includeLow, includeHigh) which returns true when the distance (in meters) between the two geometries lies between low and high. The boundary inclusion flags default to true on the ArangoDB side and are only emitted when explicitly provided. Both geometries use the GeoJSON longitude-first convention.

Example AQL usage:

GEO_IN_RANGE(doc.geo, @center, 1000, 5000)
GEO_IN_RANGE(doc.geo, @center, 1000, 5000, false, true)
Parameters
$geo1 : array<string|int, mixed>|string

First GeoJSON geometry (AQL expression or coordinates).

$geo2 : array<string|int, mixed>|string

Second GeoJSON geometry (AQL expression or coordinates).

$low : float|int|string

Lower distance bound, in meters (or AQL expression).

$high : float|int|string

Upper distance bound, in meters (or AQL expression).

$includeLow : bool|null = null

Whether the lower bound is inclusive (ArangoDB default: true).

$includeHigh : bool|null = null

Whether the upper bound is inclusive (ArangoDB default: true).

Tags
example
use function oihana\arango\db\functions\geo\geoInRange;

$expr = geoInRange( 'doc.geo' , '@center' , 1000 , 5000 );
// Produces: 'GEO_IN_RANGE(doc.geo,@center,1000,5000)'

$expr = geoInRange( 'doc.geo' , '@center' , 1000 , 5000 , false , true );
// Produces: 'GEO_IN_RANGE(doc.geo,@center,1000,5000,false,true)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_in_range
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoIntersects()

Check whether two GeoJSON geometries intersect.

geoIntersects(array<string|int, mixed>|string $geo1, array<string|int, mixed>|string $geo2) : string

This helper wraps the ArangoDB AQL function GEO_INTERSECTS(geoJsonA, geoJsonB) which returns true when the two geometries share at least one point. Both arguments use the GeoJSON longitude-first convention.

Example AQL usage:

GEO_INTERSECTS(doc.area, @zone)
Parameters
$geo1 : array<string|int, mixed>|string

First GeoJSON geometry (AQL expression or coordinates).

$geo2 : array<string|int, mixed>|string

Second GeoJSON geometry (AQL expression or coordinates).

Tags
example
use function oihana\arango\db\functions\geo\geoIntersects;

$expr = geoIntersects( 'doc.area' , '@zone' );
// Produces: 'GEO_INTERSECTS(doc.area,@zone)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_intersects
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoLineString()

Build a GeoJSON LineString geometry.

geoLineString(array<string|int, mixed>|string $points) : string

This helper wraps the ArangoDB AQL function GEO_LINESTRING(points) which constructs a valid GeoJSON LineString from an ordered array of [longitude, latitude] pairs, following the GeoJSON longitude-first convention.

Example AQL usage:

GEO_LINESTRING([ [2.35, 48.85], [4.83, 45.76] ])
Parameters
$points : array<string|int, mixed>|string

An array of [longitude, latitude] pairs, or an AQL expression.

Tags
example
use function oihana\arango\db\functions\geo\geoLineString;

$expr = geoLineString( [ [ 2.35 , 48.85 ] , [ 4.83 , 45.76 ] ] );
// Produces: 'GEO_LINESTRING([[2.35,48.85],[4.83,45.76]])'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_linestring
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoMultiLineString()

Build a GeoJSON MultiLineString geometry.

geoMultiLineString(array<string|int, mixed>|string $lines) : string

This helper wraps the ArangoDB AQL function GEO_MULTILINESTRING(lines) which constructs a valid GeoJSON MultiLineString from an array of line strings. Each line is an array of [longitude, latitude] pairs, following the GeoJSON longitude-first convention.

Example AQL usage:

GEO_MULTILINESTRING([ [ [2.35,48.85], [4.83,45.76] ], [ [1.44,43.60], [5.37,43.29] ] ])
Parameters
$lines : array<string|int, mixed>|string

An array of line strings, or an AQL expression.

Tags
example
use function oihana\arango\db\functions\geo\geoMultiLineString;

$expr = geoMultiLineString( 'doc.routes' );
// Produces: 'GEO_MULTILINESTRING(doc.routes)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_multilinestring
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoMultiPoint()

Build a GeoJSON MultiPoint geometry.

geoMultiPoint(array<string|int, mixed>|string $points) : string

This helper wraps the ArangoDB AQL function GEO_MULTIPOINT(points) which constructs a valid GeoJSON MultiPoint from an array of coordinate pairs. Each coordinate pair must already follow the GeoJSON longitude-first convention ([longitude, latitude]).

Example AQL usage:

GEO_MULTIPOINT([ [2.35, 48.85], [4.83, 45.76] ])
Parameters
$points : array<string|int, mixed>|string

An array of [longitude, latitude] pairs, or an AQL expression.

Tags
example
use function oihana\arango\db\functions\geo\geoMultiPoint;

$expr = geoMultiPoint( [ [ 2.35 , 48.85 ] , [ 4.83 , 45.76 ] ] );
// Produces: 'GEO_MULTIPOINT([[2.35,48.85],[4.83,45.76]])'

$expr = geoMultiPoint( 'doc.points' );
// Produces: 'GEO_MULTIPOINT(doc.points)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_multipoint
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoMultiPolygon()

Build a GeoJSON MultiPolygon geometry.

geoMultiPolygon(array<string|int, mixed>|string $polygons) : string

This helper wraps the ArangoDB AQL function GEO_MULTIPOLYGON(polygons) which constructs a valid GeoJSON MultiPolygon from an array of polygons. Each polygon is itself an array of linear rings of [longitude, latitude] pairs, following the GeoJSON longitude-first convention.

Example AQL usage:

GEO_MULTIPOLYGON([ [ [ [0,0],[1,0],[1,1],[0,0] ] ] ])
Parameters
$polygons : array<string|int, mixed>|string

An array of polygons, or an AQL expression.

Tags
example
use function oihana\arango\db\functions\geo\geoMultiPolygon;

$expr = geoMultiPolygon( 'doc.areas' );
// Produces: 'GEO_MULTIPOLYGON(doc.areas)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_multipolygon
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoPoint()

Build a GeoJSON Point geometry.

geoPoint(float|int|string $latitude, float|int|string $longitude) : string

This helper wraps the ArangoDB AQL function GEO_POINT(longitude, latitude) which constructs a valid GeoJSON Point. Coordinates are accepted here in the human-friendly (latitude, longitude) order and reordered internally to the GeoJSON longitude-first convention expected by ArangoDB.

Example AQL usage:

GEO_POINT(2.3522, 48.8566)            // Paris, as [lng, lat]
GEO_POINT(doc.geo.longitude, doc.geo.latitude)
Parameters
$latitude : float|int|string

The latitude, or an AQL expression resolving to it.

$longitude : float|int|string

The longitude, or an AQL expression resolving to it.

Tags
example
use function oihana\arango\db\functions\geo\geoPoint;

$expr = geoPoint( 48.8566 , 2.3522 );
// Produces: 'GEO_POINT(2.3522,48.8566)'

$expr = geoPoint( 'doc.geo.latitude' , 'doc.geo.longitude' );
// Produces: 'GEO_POINT(doc.geo.longitude,doc.geo.latitude)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_point
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

geoPolygon()

Build a GeoJSON Polygon geometry.

geoPolygon(array<string|int, mixed>|string $points) : string

This helper wraps the ArangoDB AQL function GEO_POLYGON(points) which constructs a valid GeoJSON Polygon. The outer ring (and any holes) is an array of linear rings, each a closed list of [longitude, latitude] pairs (first and last coordinate must be equal). Coordinates must already follow the GeoJSON longitude-first convention.

Example AQL usage:

GEO_POLYGON([ [ [0,0], [1,0], [1,1], [0,1], [0,0] ] ])
Parameters
$points : array<string|int, mixed>|string

An array of linear rings, or an AQL expression.

Tags
example
use function oihana\arango\db\functions\geo\geoPolygon;

$expr = geoPolygon( [ [ [ 0 , 0 ] , [ 1 , 0 ] , [ 1 , 1 ] , [ 0 , 0 ] ] ] );
// Produces: 'GEO_POLYGON([[[0,0],[1,0],[1,1],[0,0]]])'

$expr = geoPolygon( 'doc.area' );
// Produces: 'GEO_POLYGON(doc.area)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#geo_polygon
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

isInPolygon()

Check whether a coordinate lies inside a polygon (legacy).

isInPolygon(array<string|int, mixed>|string $polygon, float|int|string $latitude, float|int|string $longitude) : string

This helper wraps the ArangoDB AQL function IS_IN_POLYGON(polygon, latitude, longitude) which returns true when the point is inside the polygon. The polygon is a plain array of [latitude, longitude] pairs, and — unlike the GeoJSON functions — the point is given in the latitude-first order.

This is a legacy function kept for completeness; prefer geoContains() with proper GeoJSON geometries and a geo index for new code.

Example AQL usage:

IS_IN_POLYGON([ [48.8, 2.2], [48.9, 2.2], [48.9, 2.4] ], doc.geo.latitude, doc.geo.longitude)
Parameters
$polygon : array<string|int, mixed>|string

The polygon as an array of [latitude, longitude] pairs, or an AQL expression.

$latitude : float|int|string

Latitude of the point to test (or AQL expression).

$longitude : float|int|string

Longitude of the point to test (or AQL expression).

Tags
example
use function oihana\arango\db\functions\geo\isInPolygon;

$expr = isInPolygon( '@area' , 'doc.geo.latitude' , 'doc.geo.longitude' );
// Produces: 'IS_IN_POLYGON(@area,doc.geo.latitude,doc.geo.longitude)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#is_in_polygon
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

near()

Return the nearest documents of a collection to a coordinate (legacy).

near(string $collection, float|int|string $latitude, float|int|string $longitude[, int|string|null $limit = null ][, string|null $distanceName = null ]) : string

This helper wraps the ArangoDB AQL function NEAR(collection, latitude, longitude, limit, distanceName) which returns up to limit documents ordered by ascending distance from the given point. The collection must have a geo index. The coordinate is given in the latitude-first order.

This is a legacy function; prefer a geo index combined with SORT DISTANCE(doc.lat, doc.lng, @lat, @lng) ASC LIMIT n for new code.

Example AQL usage:

FOR place IN NEAR(places, 48.8566, 2.3522, 10, "distance") RETURN place
Parameters
$collection : string

The target collection name (AQL identifier).

$latitude : float|int|string

Latitude of the reference point (or AQL expression).

$longitude : float|int|string

Longitude of the reference point (or AQL expression).

$limit : int|string|null = null

Optional maximum number of documents to return.

$distanceName : string|null = null

Optional attribute name to store the computed distance (requires $limit).

Tags
example
use function oihana\arango\db\functions\geo\near;

$expr = near( 'places' , 48.8566 , 2.3522 , 10 , 'distance' );
// Produces: 'NEAR(places,48.8566,2.3522,10,"distance")'
see
https://docs.arangodb.com/stable/aql/functions/geo/#near
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

within()

Return documents of a collection within a radius of a coordinate (legacy).

within(string $collection, float|int|string $latitude, float|int|string $longitude, float|int|string $radius[, string|null $distanceName = null ]) : string

This helper wraps the ArangoDB AQL function WITHIN(collection, latitude, longitude, radius, distanceName) which returns all documents located within radius meters of the given point, ordered by ascending distance. The collection must have a geo index. The coordinate is given in the latitude-first order.

This is a legacy function; prefer a geo index combined with FILTER DISTANCE(doc.lat, doc.lng, @lat, @lng) <= @radius for new code.

Example AQL usage:

FOR place IN WITHIN(places, 48.8566, 2.3522, 5000, "distance") RETURN place
Parameters
$collection : string

The target collection name (AQL identifier).

$latitude : float|int|string

Latitude of the reference point (or AQL expression).

$longitude : float|int|string

Longitude of the reference point (or AQL expression).

$radius : float|int|string

The search radius, in meters (or AQL expression).

$distanceName : string|null = null

Optional attribute name to store the computed distance.

Tags
example
use function oihana\arango\db\functions\geo\within;

$expr = within( 'places' , 48.8566 , 2.3522 , 5000 , 'distance' );
// Produces: 'WITHIN(places,48.8566,2.3522,5000,"distance")'
see
https://docs.arangodb.com/stable/aql/functions/geo/#within
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

withinRectangle()

Return documents of a collection within a bounding rectangle (legacy).

withinRectangle(string $collection, float|int|string $latitude1, float|int|string $longitude1, float|int|string $latitude2, float|int|string $longitude2) : string

This helper wraps the ArangoDB AQL function WITHIN_RECTANGLE(collection, latitude1, longitude1, latitude2, longitude2) which returns all documents located inside the rectangle defined by two opposite corners. The collection must have a geo index. Coordinates are given in the latitude-first order.

This is a legacy function; prefer a geo index combined with GeoJSON geoContains() over a polygon for new code.

Example AQL usage:

FOR place IN WITHIN_RECTANGLE(places, 48.80, 2.25, 48.90, 2.40) RETURN place
Parameters
$collection : string

The target collection name (AQL identifier).

$latitude1 : float|int|string

Latitude of the first corner (or AQL expression).

$longitude1 : float|int|string

Longitude of the first corner (or AQL expression).

$latitude2 : float|int|string

Latitude of the opposite corner (or AQL expression).

$longitude2 : float|int|string

Longitude of the opposite corner (or AQL expression).

Tags
example
use function oihana\arango\db\functions\geo\withinRectangle;

$expr = withinRectangle( 'places' , 48.80 , 2.25 , 48.90 , 2.40 );
// Produces: 'WITHIN_RECTANGLE(places,48.8,2.25,48.9,2.4)'
see
https://docs.arangodb.com/stable/aql/functions/geo/#within_rectangle
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results