de9im
de9im
is a Javascript library that provides spatial predicate
functions defined by the Dimensionally Extended Nine-Intersection Model
(DE-9IM) and works with GeoJSON objects. It can
test if two geometries have one of the following relationships: contains
,
coveredby
, covers
, crosses
, disjoint
, equals
, intersects
,
overlaps
, touches
, within
. It can be used client-side in a browser or
server-side with Node.js.
GETTING STARTED
de9im
depends on the Turf.js library for performing spatial
operations which must be also included for client-side processing since Turf.js
is not bundled with de9im
.
In a browser
In Node
npm install de9imconst de9im = ;
Then call a predicate function on two geometries
const line = 'type': 'LineString' 'coordinates': 0 0 1 1 2 2;const point = 'type': 'Point' 'coordinates': 1 1;de9im;// = truede9im;// = false
USAGE
API
The de9im
object has the following spatial predicate functions available:
containscoveredbycoverscrossesdisjointequalsintersectsoverlapstoucheswithin
Each predicate takes two GeoJSON arguments and an optional boolean argument:
de9im
It returns true, false, or throws an exception if the geometry types provided
are not supported. If the optional argument error
is false then unsupported
geometries return false instead of throwing an exception. Each predicate should
be interpreted as the first argument operating on the second. For example,
de9im
should be read as
line contains point?
Data Types
The arguments for every predicate can be any GeoJSON type: Geometry
,
Feature
, GeometryCollection
, FeatureCollection
. All geometry types are
supported: Point
, LineString
, Polygon
, MultiPoint
, MultiLineString
,
MultiPolygon
. However, only homogenous geometries are supported in
collections. For example, a FeatureCollection can have points but can not mix
points and lines.
Argument Types
Each predicate has a unique combination of first and second argument geometries that it supports.
-
contains
,covers
1st / 2nd Point Line Polygon Point ✔️ ❌ ❌ Line ✔️ ✔️ ❌ Polygon ✔️ ✔️ ✔️ -
coveredby
,within
1st / 2nd Point Line Polygon Point ✔️ ✔️ ✔️ Line ❌ ✔️ ✔️ Polygon ❌ ❌ ✔️ -
crosses
1st / 2nd Point Line Polygon Point ❌ ✔️ ✔️ Line ✔️ ✔️ ✔️ Polygon ✔️ ✔️ ❌ -
disjoint
,intersects
1st / 2nd Point Line Polygon Point ✔️ ✔️ ✔️ Line ✔️ ✔️ ✔️ Polygon ✔️ ✔️ ✔️ -
equals
,overlaps
1st / 2nd Point Line Polygon Point ✔️ ❌ ❌ Line ❌ ✔️ ❌ Polygon ❌ ❌ ✔️ -
touches
1st / 2nd Point Line Polygon Point ❌ ✔️ ✔️ Line ✔️ ✔️ ✔️ Polygon ✔️ ✔️ ✔️
TIPS
The following are some best practices on using de9im
:
-
Data is expected to be in WGS 84 coordinates as per the GeoJSON standard.
-
Data with the GeoJSON
bbox
attribute already defined will process faster. -
Data with complex geometries (e.g., self-intersections, repeated coordinates) may produce invalid results.
-
Data coordinates should be truncated to avoid unrealistically high precision (more than 6 decimal places).
BUILD
To build and test the library locally:
npm installnpm test
LICENSE
Copyright (c) 2019 Daniel Pulido mailto:dpmcmlxxvi@gmail.com
Source code is released under the MIT License.