{"id":26062200,"url":"https://github.com/dpmcmlxxvi/de9im","last_synced_at":"2025-09-20T10:17:15.646Z","repository":{"id":34872861,"uuid":"186052415","full_name":"dpmcmlxxvi/de9im","owner":"dpmcmlxxvi","description":"DE-9IM spatial predicate library implemented in Javascript.","archived":false,"fork":false,"pushed_at":"2022-07-07T03:02:44.000Z","size":1019,"stargazers_count":29,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T07:36:05.239Z","etag":null,"topics":["algorithm","de-9im","geojson","geospatial","gis","javascript","predicates","spatial"],"latest_commit_sha":null,"homepage":"https://dpmcmlxxvi.github.io/de9im","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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-05-10T20:46:35.000Z","updated_at":"2024-11-09T00:45:55.000Z","dependencies_parsed_at":"2022-08-08T02:15:21.257Z","dependency_job_id":null,"html_url":"https://github.com/dpmcmlxxvi/de9im","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fde9im","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fde9im/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fde9im/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpmcmlxxvi%2Fde9im/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpmcmlxxvi","download_url":"https://codeload.github.com/dpmcmlxxvi/de9im/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":["algorithm","de-9im","geojson","geospatial","gis","javascript","predicates","spatial"],"created_at":"2025-03-08T15:54:58.604Z","updated_at":"2025-09-20T10:17:10.587Z","avatar_url":"https://github.com/dpmcmlxxvi.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# [de9im][de9im-site]\n\n[![build](https://github.com/dpmcmlxxvi/de9im/actions/workflows/build.yml/badge.svg)](https://github.com/dpmcmlxxvi/de9im/actions)\n[![coverage](https://img.shields.io/coveralls/dpmcmlxxvi/de9im.svg)](https://coveralls.io/r/dpmcmlxxvi/de9im?branch=master)\n[![npm](https://badge.fury.io/js/de9im.svg)](https://badge.fury.io/js/de9im)\n[![code](https://app.codacy.com/project/badge/Grade/d345359c8f91405da92ed455cd82288d)](https://www.codacy.com/gh/dpmcmlxxvi/de9im/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=dpmcmlxxvi/de9im\u0026amp;utm_campaign=Badge_Grade)\n\n`de9im` is a Javascript library that provides spatial predicate\nfunctions defined by the [Dimensionally Extended Nine-Intersection Model\n(DE-9IM)][de9im-wiki] and works with [GeoJSON][geojson-site] objects. It can\ntest if two geometries have one of the following relationships: `contains`,\n`coveredby`, `covers`, `crosses`, `disjoint`, `equals`,  `intersects`,\n`overlaps`, `touches`, `within`. It can be used client-side in a browser or\nserver-side with [Node.js][node-site].\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://en.wikipedia.org/wiki/DE-9IM#/media/File:TopologicSpatialRelarions2.png\"\u003e\n    \u003cimg alt=\"\" src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/TopologicSpatialRelarions2.png/400px-TopologicSpatialRelarions2.png\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nSee [de9im examples][de9im-examples] for examples of geometries that satisfy\nthe various predicates using `de9im`.\n\nSee [pouchdb-geospatial][pouchdb-geospatial] for an example application that\nuses `de9im` to perform spatial querying of GeoJSON objects in a database.\n\n## GETTING STARTED\n\n`de9im` depends on the [Turf.js][turf-site] library for performing spatial\noperations which must be also included for client-side processing since Turf.js\nis not bundled with `de9im`.\n\n### In a browser\n\n```html\n\u003cscript src=\"https://unpkg.com/@turf/turf\" charset=\"utf-8\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/de9im\" charset=\"utf-8\"\u003e\u003c/script\u003e\n```\n\n### In Node\n\n```javascript\nnpm install de9im\nconst de9im = require('de9im');\n```\n\nThen call a predicate function on two geometries\n\n```javascript\nconst line = {'type': 'LineString', 'coordinates': [[0, 0], [1, 1], [2, 2]]};\nconst point = {'type': 'Point', 'coordinates': [1, 1]};\nde9im.contains(line, point);\n// = true\nde9im.disjoint(line, point);\n// = false\n```\n\n## USAGE\n\n### API\n\nThe `de9im` object has the following spatial predicate functions available:\n\n```javascript\ncontains\ncoveredby\ncovers\ncrosses\ndisjoint\nequals\nintersects\noverlaps\ntouches\nwithin\n```\n\nEach predicate takes two GeoJSON arguments and an optional boolean argument:\n\n```javascript\nde9im.predicate(geojson1, geojson2, [error=true])\n```\n\nIt returns true, false, or throws an exception if the geometry types provided\nare not supported. If the optional argument `error` is false then unsupported\ngeometries return false instead of throwing an exception. Each predicate should\nbe interpreted as the first argument operating on the second. For example,\n\n```javascript\nde9im.contains(line, point)\n```\nshould be read as\n\n```shell\nline contains point?\n```\n\n### Data Types\n\nThe arguments for every predicate can be any GeoJSON type: `Geometry`,\n`Feature`, `GeometryCollection`, `FeatureCollection`. All geometry types are\nsupported: `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`,\n`MultiPolygon`. However, only homogenous geometries are supported in\ncollections. For example, a FeatureCollection can have points but can not mix\npoints and lines.\n\n### Argument Types\n\nEach predicate has a unique combination of first and second argument geometries\nthat it supports.\n\n-   `contains`, `covers`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :heavy_check_mark: | :x:                | :x:                |\n    | Line      | :heavy_check_mark: | :heavy_check_mark: | :x:                |\n    | Polygon   | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n\n-   `coveredby`, `within`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n    | Line      | :x:                | :heavy_check_mark: | :heavy_check_mark: |\n    | Polygon   | :x:                | :x:                | :heavy_check_mark: |\n\n-   `crosses`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :x:                | :heavy_check_mark: | :heavy_check_mark: |\n    | Line      | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n    | Polygon   | :heavy_check_mark: | :heavy_check_mark: | :x:                |\n\n-   `disjoint`, `intersects`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n    | Line      | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n    | Polygon   | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n\n-   `equals`, `overlaps`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :heavy_check_mark: | :x:                | :x:                |\n    | Line      | :x:                | :heavy_check_mark: | :x:                |\n    | Polygon   | :x:                | :x:                | :heavy_check_mark: |\n\n-   `touches`\n\n    | 1st / 2nd | Point              | Line               | Polygon            |\n    |:---------:|:------------------:|:------------------:|:------------------:|\n    | Point     | :x:                | :heavy_check_mark: | :heavy_check_mark: |\n    | Line      | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n    | Polygon   | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n\n## TIPS\n\nThe following are some best practices on using `de9im`:\n\n-   Data is expected to be in [WGS 84][wgs84-wiki] coordinates as per the\n    GeoJSON standard.\n\n-   Data with the GeoJSON `bbox` attribute already defined will process faster.\n\n-   Data with complex geometries (e.g., self-intersections, repeated\n    coordinates) may produce invalid results.\n\n-   Data coordinates should be truncated to avoid unrealistically high precision\n    (more than 6 decimal places).\n\n## ALGORITHM NOTES\n\nThe `de9im` library uses a partition approach to determine if two geometries\nsatisfy a given relation. This approach is different from the standard node/edge\nlabeling used by most DE-9IM implementations. Labeling approaches are only\ndefined for single geometries and not multi-geometries or collections and it is\nnot clear how to extend them to cover those cases.\n\nInstead, `de9im` partitions each input geometry into elementary facets, where\neach facet is either inside or outside the other geometry. For example, to test\ntwo (multi-) polygons, the first (multi-) polygon is triangulated. This\ntriangulation gets intersected with the other (multi-) polygon's triangulation.\nThis intersection gets re-triangulated to create a decomposition of the first\n(multi-) polygon such that each partition triangle (facet) is entirely inside or\noutside the second (multi-) polygon. Finally, the decision of whether the\ngeometries satisfy the given predicate can be reduced to determining if the\nindividual facets satisfy the relation. The same goes for lines using segments\nas the facets instead of triangles. This allows any geometry or collection type\nto be processed.\n\nFinally, while `de9im` has `turf` as a dependency, it does not use its DE-9IM\nfunctions since it has only limited functionality and only covers a small subset\nof all possible geometry and predicate combinations. The goal of `de9im` is to\ncover all possible combinations. The `turf` library is only used for basic\nspatial processing and geometry utility functions.\n\n## BUILD\n\nTo build and test the library locally:\n\n```shell\nnpm install\nnpm test\n```\n\n## BENCHMARK\n\nBenchmark timing results can be found at [bench.md](bench.md).\n\n## LICENSE\n\nCopyright (c) 2019 Daniel Pulido \u003cmailto:dpmcmlxxvi@gmail.com\u003e\n\nSource code is released under the [MIT License](http://opensource.org/licenses/MIT).\n\n[de9im-examples]: https://dpmcmlxxvi.github.io/de9im/\n[de9im-site]: https://github.com/dpmcmlxxvi/de9im\n[de9im-wiki]: https://en.wikipedia.org/wiki/DE-9IM\n[geojson-site]: http://geojson.org/\n[node-site]: http://nodejs.org/\n[pouchdb-geospatial]: https://github.com/dpmcmlxxvi/pouchdb-geospatial\n[turf-site]: https://turfjs.org\n[wgs84-wiki]: https://en.wikipedia.org/wiki/World_Geodetic_System\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpmcmlxxvi%2Fde9im","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpmcmlxxvi%2Fde9im","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpmcmlxxvi%2Fde9im/lists"}