npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtree-ldf

v0.0.9

Published

Disk based rtree implementation based on rbush mainly built to create fragmented linked data rtrees

Downloads

9

Readme

Rtree LDF

Rtree-ldf is based on rbush, a high-performance JavaScript library for 2D spatial indexing of points and rectangles. It is completely disk based and uses a nosql-database for storage and a lru-cache for improved performance. Please note that this implementation isn't optimal and an implementation in another language such as c++ will be much faster. Performance will also greatly depend on the cache size given to the tree.

Install

Install with NPM (npm install --save rtree-ldf).

Usage

const Rtree = require('rtree-ldf')

Creating a Tree

const tree = new Rtree({
	dir: './db',
	openExisting: true,
	cacheSize: 100000,
	maxEntries: 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.

Adding Data

Insert an item:

const item = {
    minX: 20, 
    minY: 40,
    maxX: 30,
    maxY: 50,
    "@id": "gtfs:station",
    foo: bar
};
tree.insert(item);

minX, minY, maxX and maxY are required. You can also add extra data properties.

Removing Data

Remove a previously inserted item:

tree.remove(item);

You can also pass a custom equals function.

tree.remove(itemCopy, function (a, b) {
    return a.id === b.id;
});

Remove all items:

tree.clear();

Bulk-Inserting Data

Load an array of data into the tree.

tree.load([item1, item2, ...]);

Search

var result = tree.search({
    minX: 40,
    minY: 20,
    maxX: 80,
    maxY: 70
});

Returns an array of data items (points or rectangles) that the given bounding box intersects.

var allItems = tree.all();

Returns all items of the tree.

Collisions

var result = tree.collides({minX: 40, minY: 20, maxX: 80, maxY: 70});

Returns true if there are any items intersecting the given bounding box, otherwise false.

Export to JSON

// export data as JSON object
var treeData = tree.toJSON();

Export to linked data fragments

tree.toFragments({
	outDir: './fragments/', 
	treeDir: 'tree', 
	dataDir: 'data', 
	collection: 'stations' , 
	manages: 'http://vocab.gtfs.org/terms#station'
});

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.