Class: GeoJSON

GeoJSON

Representation of a GeoJSON value. Since GeoJSON values are JSON objects they need to be wrapped in the GeoJSON class so that the client can distinguish them from other types of objects.

For more information, please refer to the section on ⇑Geospatial Data Type in the Aerospike technical documentation.


new GeoJSON(value)

Creates a new GeoJSON instance.

Parameters:
Name Type Description
value Object | string

GeoJSON value; the constructor accepts either a string representation of the JSON object, or a JS object.

Source:
Example
const Aerospike = require('aerospike')
const GeoJSON = Aerospike.GeoJSON
const Key = Aerospike.Key

Aerospike.connect((error, client) => {
  if (error) throw error
  let key = new Key('test', 'demo', 'bob')
  let location = new GeoJSON({type: 'Point', coordinates: [103.913, 1.308]})
  client.put(key, {loc: location}, (error) => {
    if (error) throw error
    client.close()
  })
})

Methods


<static> Circle(lng, lat, radius)

Helper function to create a new GeoJSON geometry object representing a circle with the given coordinates and radius.

Parameters:
Name Type Description
lng number

Longitude of the center point.

lat number

Latitude of the center point.

radius number

Radius in meters.

Source:
See:
Returns:

a GeoJSON representation of the circle.

Type
GeoJSON
Example
const Aerospike = require('aerospike')
const GeoJSON = Aerospike.GeoJSON

let point = GeoJSON.Circle(103.913, 1.308, 5000)

<static> Point(lng, lat)

Helper function to create a new GeoJSON object representing the point with the given coordinates.

Parameters:
Name Type Description
lng number

Longitude

lat number

Latitude

Source:
Returns:

a GeoJSON representation of the point

Type
GeoJSON
Example
const Aerospike = require('aerospike')
const GeoJSON = Aerospike.GeoJSON

let point = GeoJSON.Point(103.913, 1.308)

<static> Polygon(coordinates)

Helper function to create a new GeoJSON object representing the polygon with the given coordinates.

Parameters:
Name Type Argument Description
coordinates Array.<number> <repeatable>

one or more coordinate pairs (lng, lat) describing the polygon.

Source:
Returns:

a GeoJSON representation of the polygon.

Type
GeoJSON
Example
const Aerospike = require('aerospike')
const GeoJSON = Aerospike.GeoJSON

let polygon = GeoJSON.Polygon([102.913, 0.308], [102.913, 2.308], [104.913, 2.308], [104.913, 0.308], [102.913, 0.308])

toJSON()

Returns the GeoJSON value as a JS object.

Source:
Returns:
Type
Object

toString()

Returns the GeoJSON value as a string

Source:
Returns:
Type
string

value()

Alias for GeoJSON#toJSON. Returns the GeoJSON value as a JS object.

Source:
Returns:
Type
Object