{"id":26062232,"url":"https://github.com/dpmcmlxxvi/pouchdb-geospatial","last_synced_at":"2025-04-11T11:09:35.300Z","repository":{"id":34917788,"uuid":"189901808","full_name":"dpmcmlxxvi/pouchdb-geospatial","owner":"dpmcmlxxvi","description":"PouchDB geospatial query plugin.","archived":false,"fork":false,"pushed_at":"2022-11-24T17:38:12.000Z","size":1613,"stargazers_count":19,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T09:24:07.388Z","etag":null,"topics":["database","de-9im","geojson","geospatial","plugin","pouchdb","query","spatial"],"latest_commit_sha":null,"homepage":"https://dpmcmlxxvi.github.io/pouchdb-geospatial/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpmcmlxxvi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-02T22:34:04.000Z","updated_at":"2025-04-07T14:41:34.000Z","dependencies_parsed_at":"2023-01-15T10:22:41.247Z","dependency_job_id":null,"html_url":"https://github.com/dpmcmlxxvi/pouchdb-geospatial","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fpouchdb-geospatial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fpouchdb-geospatial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fpouchdb-geospatial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fpouchdb-geospatial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpmcmlxxvi","download_url":"https://codeload.github.com/dpmcmlxxvi/pouchdb-geospatial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381787,"owners_count":21094527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","de-9im","geojson","geospatial","plugin","pouchdb","query","spatial"],"created_at":"2025-03-08T15:55:08.880Z","updated_at":"2025-04-11T11:09:35.282Z","avatar_url":"https://github.com/dpmcmlxxvi.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# [PouchDB Geospatial][pouchdb-geospatial-github]\n\n[![build](https://github.com/dpmcmlxxvi/pouchdb-geospatial/actions/workflows/build.yml/badge.svg)](https://github.com/dpmcmlxxvi/pouchdb-geospatial/actions)\n[![coverage](https://img.shields.io/coveralls/dpmcmlxxvi/pouchdb-geospatial.svg)](https://coveralls.io/r/dpmcmlxxvi/pouchdb-geospatial?branch=master)\n[![npm](https://badge.fury.io/js/pouchdb-geospatial.svg)](https://badge.fury.io/js/pouchdb-geospatial)\n[![codacy](https://app.codacy.com/project/badge/Grade/c6b4a5a7bf2d4484b777ba29cf08242f)](https://www.codacy.com/gh/dpmcmlxxvi/pouchdb-geospatial/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=dpmcmlxxvi/pouchdb-geospatial\u0026amp;utm_campaign=Badge_Grade)\n\nThe [PouchDB][pouchdb-site] Geospatial plugin provides spatial querying of\n[GeoJSON][geojson-site] objects. GeoJSON objects within a PouchDB database\ncan be queried against an input GeoJSON object to test if they satisfy one\nof the [DE-9IM][de9im-wiki] spatial predicates: `contains`, `coveredby`,\n`covers`, `crosses`, `disjoint`, `equals`, `intersects`, `overlaps`,\n`touches`, `within`.\n\nAny GeoJSON object inserted into the\ndatabase via the the plugin API is spatially indexed using an\n[R-Tree][rtree-wiki]. Spatial queries are then processed by querying the R-Tree\nfor candidate geometries and the final query results are returned after the\ncandidates are filtered by the appropriate spatial predicate. The spatial\nindexing is performed by [RBush][rbush-github] and geospatial predicates\nare computed with [de9im][de9im-github].\n\nA sample of how to use the plugin is available at the\n[examples page][pouchdb-geospatial-examples]. The API is described below and at\nthe [documentation page][pouchdb-geospatial-api].\n\n![pouchdb-geospatial example](https://raw.githubusercontent.com/dpmcmlxxvi/pouchdb-geospatial/master/docs/examples/img/example.png)\n\n## USAGE\n\n### In browser\n\nTo use this plugin, include it after `pouchdb.js` in your HTML page. This plugin\nhas two dependencies not bundled with it that must be included\n[Turf][turf-github] and [de9im][de9im-github].\n\n```html\n\u003cscript src=\"https://unpkg.com/pouchdb/dist/pouchdb.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/@turf/turf\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/de9im\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/pouchdb-geospatial\"\u003e\u003c/script\u003e\n```\n\n### In Node\n\nTo use it in Node, install it\n\n```shell\nnpm install pouchdb-geospatial\n```\n\nthen attach it to the `PouchDB` object:\n \n```javascript\nimport PouchDB from 'pouchdb';\nimport PouchDBGeospatial from 'pouchdb-geospatial';\nPouchDB.plugin(PouchDBGeospatial);\n```\n\n### Create database\n\nThe plugin methods are exposed via an object API. All methods return promises.\n\n```javascript\nconst db = new PouchDB('dbname');\nconst api = db.geospatial();\n```\n\n## API\n\n### Database methods\n\nThe database methods accept the same options and return a promise with the same\nresponse returned by their corresponding `PouchDB` methods: `put`, `post`,\n`bulkDocs`, and `remove`.\n\n```javascript\napi.add(geojson, options);\napi.load([geojson, ...], options);\napi.remove(id);\n```\n\n### Indexing methods\n\nThe underlying R-Tree can be accessed using the `tree` attribute. It returns\nan `GeospatialTree` which allows a user to directly use it's methods to `add`,\n`load`, `remove`, and `query` the tree. However, care should be used when\nmodifying the tree directly since the tree and database can become out-of-sync.\nThe primary use of directly accessing the tree is to reload data from disk after\na page reload or application restart. Otherwise, it is preferable to directly\nuse the database methods to add data.\n\n```javascript\napi.tree.add(geojson, id);\napi.tree.load([{id, geojson}, ...]);\napi.tree.remove({id, geojson});\napi.tree.query(geojson);\n```\n\n### Query methods\n\nThe query methods accept a GeoJSON and return a promise with an array of\ndatabase document IDs that satisfy the spatial predicate. For example,\n\n```javascript\napi.contains(geojson).then((ids) =\u003e {\n  // Do something with document ids.\n});\n```\n\nThe following spatial predicates are available:\n\n```javascript\ncontains\ncoveredby\ncovers\ncrosses\ndisjoint\nequals\nintersects\noverlaps\ntouches\nwithin\n```\n\nEach predicate takes one GeoJSON argument. The predicate should be interpreted\nas the database GeoJSON operating on the argument GeoJSON. For example,\n\n```javascript\napi.within(polygon)\n```\n\nshould be read as\n\n```shell\nany database GeoJSON within polygon?\n```\n\n## BUILD\n\nTo build and test the library locally:\n\n```shell\nnpm install\nnpm test\n```\n\nAfter installation, the bundled plugin is at `pouchdb-geospatial.min.js`.\n\n## LICENSE\n\nCopyright (c) 2019 Daniel Pulido \u003cmailto:dpmcmlxxvi@gmail.com\u003e\n\nSource code is released under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0)\n\n[de9im-github]: https://github.com/dpmcmlxxvi/de9im\n[de9im-wiki]: https://en.wikipedia.org/wiki/DE-9IM\n[geojson-site]: http://geojson.org\n[pouchdb-site]: https://pouchdb.com\n[pouchdb-geospatial-api]: http://dpmcmlxxvi.github.io/pouchdb-geospatial/api\n[pouchdb-geospatial-examples]: http://dpmcmlxxvi.github.io/pouchdb-geospatial/examples\n[pouchdb-geospatial-github]: https://github.com/dpmcmlxxvi/pouchdb-geospatial\n[rbush-github]: https://github.com/mourner/rbush\n[rtree-wiki]: https://en.wikipedia.org/wiki/R-tree\n[turf-github]: https://github.com/Turfjs/turf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpmcmlxxvi%2Fpouchdb-geospatial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpmcmlxxvi%2Fpouchdb-geospatial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpmcmlxxvi%2Fpouchdb-geospatial/lists"}