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

pouchdb-geospatial

v0.4.0

Published

PouchDB geospatial query plugin.

Downloads

34

Readme

PouchDB Geospatial

build coverage npm codacy

The PouchDB Geospatial plugin provides spatial querying of GeoJSON objects. The query methods available support the DE-9IM spatial predicates. Any GeoJSON object inserted into the database via the the plugin API is spatially indexed using an R-Tree. Spatial queries are then processed by querying the R-Tree for candidate geometries and the final query results are returned after the candidates are filtered by the appropriate spatial predicate. The spatial indexing is performed by RBush and geospatial predicates are computed with de9im. A sample of how to use the plugin is available at the examples page. The API is described below and at the documentation page.

pouchdb-geospatial example

USAGE

In browser

To use this plugin, include it after pouchdb.js in your HTML page. This plugin has two dependencies not bundled with it that must be included Turf and de9im.

<script src="https://unpkg.com/pouchdb/dist/pouchdb.min.js"></script>
<script src="https://unpkg.com/@turf/turf"></script>
<script src="https://unpkg.com/de9im"></script>
<script src="https://unpkg.com/pouchdb-geospatial"></script>

In Node

To use it in Node, install it

npm install pouchdb-geospatial

then attach it to the PouchDB object:

import PouchDB from 'pouchdb';
import PouchDBGeospatial from 'pouchdb-geospatial';
PouchDB.plugin(PouchDBGeospatial);

Create database

The plugin methods are exposed via an object API. All methods return promises.

const db = new PouchDB('dbname');
const api = db.geospatial();

API

Database methods

The database methods accept the same options and return a promise with the same response returned by their corresponding PouchDB methods: put, post, bulkDocs, and remove.

api.add(geojson, options);
api.load([geojson, ...], options);
api.remove(id);

Indexing methods

The underlying R-Tree can be accessed using the tree attribute. It returns an GeospatialTree which allows a user to directly use it's methods to add, load, remove, and query the tree. However, care should be used when modifying the tree directly since the tree and database can become out-of-sync. The primary use of directly accessing the tree is to reload data from disk after a page reload or application restart. Otherwise, it is preferable to directly use the database methods to add data.

api.tree.add(geojson, id);
api.tree.load([{id, geojson}, ...]);
api.tree.remove({id, geojson});
api.tree.query(geojson);

Query methods

The query methods accept a GeoJSON and return a promise with an array of database document IDs that satisfy the spatial predicate. For example,

api.contains(geojson).then((ids) => {
  // Do something with document ids.
});

The following spatial predicates are available:

contains
coveredby
covers
crosses
disjoint
equals
intersects
overlaps
touches
within

Each predicate takes one GeoJSON argument. The predicate should be interpreted as the database GeoJSON operating on the argument GeoJSON. For example,

api.within(polygon)

should be read as

any database GeoJSON within polygon?

BUILD

To build and test the library locally:

npm install
npm test

After installation, the bundled plugin is at pouchdb-geospatial.min.js.

LICENSE

Copyright (c) 2019 Daniel Pulido mailto:[email protected]

Source code is released under the Apache 2.0 license