Install with NPM (
npm install --save rtree-ldf).
const Rtree =
Creating a Tree
const tree =dir: './db'openExisting: truecacheSize: 100000maxEntries: 16;
dir: Directory where the tree will be saved on disk
openExisting(Opt.): Open an existing tree located in dir (default: false)
cacheSize(Opt.): Amount of nodes that will can be cached (max 1.000.000, default: 100.000)
maxEntries(Opt.): defines the maximum number of entries in a tree node (default: 9)
Closing a tree
If you want to make sure your tree is completely saved to the disk, make sure to call
tree.close() when you are done.
Insert an item:
const item =minX: 20minY: 40maxX: 30maxY: 50"@id": "gtfs:station"foo: bar;tree;
maxY are required. You can also add extra data properties.
Remove a previously inserted item:
You can also pass a custom
Remove all items:
Load an array of data into the tree.
var result = tree;
Returns an array of data items (points or rectangles) that the given bounding box intersects.
var allItems = treeall;
Returns all items of the tree.
var result = tree;
true if there are any items intersecting the given bounding box, otherwise
Export to JSON
// export data as JSON objectvar treeData = tree;
Export to linked data fragments
The tree will be exported into fragments conform to the TreeOntology. The fragments are formatted in JSON-LD and most will be around 500 kB which should give a fragment size of around 50 kB after compression.
outDir: base directory where the fragments will be exported to
collection: name of the fragment describing the collection. This fragment will be placed in the out directory
manages: type of data the collection manages
treeDir(opt.): directory starting from outDir where the treeFragments will be exported to. The fragments are exported to the outDir by default.
dataDir(opt.): directory starting from outDir where the dataFragments will be exported to. The fragments are exported to the outDir by default.