Skip to content

digidem/hyperdb-osm-observations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hyperdb-osm-observations

Create and manage observations of OSM data.

For the purposes of this module, an "observation" is defined as a record of some observed fact about a geospatial object at a specific point in time. To this end, every observation is associated with another OSM element, and has a timestamp set to the local time at its moment of creation.

This module provides some convenience functions for retrieving this data.

Usage

var hyperdb = require('hyperdb')
var hyperosm = require('hyperdb-osm')
var osmObservations = require('hyperdb-osm-observations')
var geo = require('grid-point-store')
var memdb = require('memdb')
var ram = require('random-access-memory')

var db = hyperdb(ram, { valueEncoding: 'json' })
var osm = hyperosm({
  db: db,
  index: memdb(),
  pointstore: geo(memdb())
})
var obs = osmObservations(osm)

var node = {
  type: 'node',
  lat: '100',
  lon: '45'
}
db.create(node, function (_, theNode) {
  var o = {
    type: 'observation',
    observedId: theNode.id,
    lat: '23',
    lon: '45'
  }
  db.create(o, function () {
    obs.query([[-200,200],[-200,200]], function (err, observations) {
      console.log('query', observations)
    })
    obs.observations(res.id, function (err, observations) {
      console.log('get', observations)
    })
  })
})

outputs

query [
  {
    type: 'observation',
    observedId: '...',
    lat: '100',
    lon: '45',
    timestamp: '...',
    id: '...',
    version: '...'
  }
]
get [
  {
    type: 'observation',
    observedId: '...',
    lat: '100',
    lon: '45',
    timestamp: '...',
    id: '...',
    version: '...'
  }
]

API

var osmObservations = require('hyperdb-osm-observations')

var obs = osmObservations(db)

Create a new observations instance from a hyperdb db.

obs.create(elm, cb)

Create a new observation. The object elm must include the following properties:

  • observedId (string): the ID of the OSM element being observed.
  • lat (string): the latitude coordinate of the observation.
  • lon (string): the longitude coordinate of the observation.

cb is called as cb(error, observationElement).

var rs = obs.query(bbox[, cb])

Query the database for all observations in the bounding box bbox.

If cb is given it will be called with all results; otherwise the readable stream rs is returned and will emit results as they become available.

Note that this only returns observation elements. You can use something like pull-many to combine this with the hyperdb-osm#query:

var pullify = require('stream-to-pull-stream')
var pull = require('pull-stream')
var many = require('pull-many')

...

pull(
  pull.many([
    pullify.source(obs.query(bbox)),
    pullify.source(osm.query(bbox))
  ]),
  pull.drain(function (elm) {
    console.log('got element', elm.version)
  })
)

var rs = obs.observations(id[, cb])

Retrieve all observations linked to the OSM element with id id.

If cb is given it will be called with all results; otherwise the readable stream rs is returned and will emit results as they become available.

Install

With npm installed, run

$ npm install hyperdb-osm-observations

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published