Class 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.

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()
})
})
})

Constructors

Properties

Methods

Constructors

  • Creates a new GeoJSON instance.

    Parameters

    • json: string | object

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

    Returns GeoJSON

Properties

str?: string
Circle: (new (lng: number, lat: number, radius: number) => any)

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

Type declaration

    • new (lng, lat, radius): any
    • Parameters

      • lng: number

        Longitude of the center point.

      • lat: number

        Latitude of the center point.

      • radius: number

        Radius in meters.

      Returns any

      a GeoJSON representation of the circle.

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

let point = GeoJSON.Circle(103.913, 1.308, 5000)
Point: (new (lng: number, lat: number) => any)

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

Type declaration

    • new (lng, lat): any
    • Parameters

      • lng: number

        Longitude

      • lat: number

        Latitude

      Returns any

      a GeoJSON representation of the point

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

let point = GeoJSON.Point(103.913, 1.308)
Polygon: (new (...coordinates: number[][]) => any)

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

Type declaration

    • new (...coordinates): any
    • Parameters

      • Rest...coordinates: number[][]

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

      Returns any

      a GeoJSON representation of the polygon.

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])

Methods

MMNEPVFCICPMFPCPTTAAATR