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.

Constructor

new GeoJSON(value)

Creates a new GeoJSON instance.

Source:
Example
const Aerospike = require('aerospike')
const GeoJSON = Aerospike.GeoJSON
const Key = Aerospike.Key
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
  hosts: '192.168.33.10:3000',
  // Timeouts disabled, latency dependent on server location. Configure as needed.
  policies: {
    read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
    write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),

  }
}
Aerospike.connect(config, (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.get(key, (error, record) => {
      if (error) throw error
      console.log(record.bins.loc) // => {"type":"Point","coordinates":[103.913,1.308]}
      client.close()
    })
  })
})
Parameters:
Name Type Description
value Object | string

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

Methods

toJSON() → {Object}

Description:
  • Returns the GeoJSON value as a JS object.

Source:
Returns:
Type
Object

toString() → {string}

Description:
  • Returns the GeoJSON value as a string

Source:
Returns:
Type
string

value() → {Object}

Description:
Source:
Returns:
Type
Object

(static) Circle(lng, lat, radius) → {GeoJSON}

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

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

let point = GeoJSON.Circle(103.913, 1.308, 5000)
Parameters:
Name Type Description
lng number

Longitude of the center point.

lat number

Latitude of the center point.

radius number

Radius in meters.

Returns:

a GeoJSON representation of the circle.

Type
GeoJSON

(static) Point(lng, lat) → {GeoJSON}

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

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

let point = GeoJSON.Point(103.913, 1.308)
Parameters:
Name Type Description
lng number

Longitude

lat number

Latitude

Returns:

a GeoJSON representation of the point

Type
GeoJSON

(static) Polygon(…coordinates) → {GeoJSON}

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

Source:
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])
Parameters:
Name Type Attributes Description
coordinates Array.<number> <repeatable>

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

Returns:

a GeoJSON representation of the polygon.

Type
GeoJSON