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

de9im

v1.3.1

Published

DE-9IM spatial predicate library implemented in Javascript.

Downloads

1,954

Readme

de9im

build coverage npm code Greenkeeper badge

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

<script src="https://unpkg.com/@turf/turf" charset="utf-8"></script>
<script src="https://unpkg.com/de9im" charset="utf-8"></script>

In Node

npm install de9im
const de9im = require('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.contains(line, point);
// = true
de9im.disjoint(line, point);
// = false

USAGE

API

The de9im object has the following spatial predicate functions available:

contains
coveredby
covers
crosses
disjoint
equals
intersects
overlaps
touches
within

Each predicate takes two GeoJSON arguments and an optional boolean argument:

de9im.predicate(geojson1, geojson2, [error=true])

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.contains(line, point)

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 | :heavy_check_mark: | :x: | :x: | | Line | :heavy_check_mark: | :heavy_check_mark: | :x: | | Polygon | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

  • coveredby, within

    | 1st / 2nd | Point | Line | Polygon | |:------------:|:------------------:|:------------------:|:------------------:| | Point | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Line | :x: | :heavy_check_mark: | :heavy_check_mark: | | Polygon | :x: | :x: | :heavy_check_mark: |

  • crosses

    | 1st / 2nd | Point | Line | Polygon | |:------------:|:------------------:|:------------------:|:------------------:| | Point | :x: | :heavy_check_mark: | :heavy_check_mark: | | Line | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Polygon | :heavy_check_mark: | :heavy_check_mark: | :x: |

  • disjoint, intersects

    | 1st / 2nd | Point | Line | Polygon | |:------------:|:------------------:|:------------------:|:------------------:| | Point | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Line | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Polygon | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

  • equals, overlaps

    | 1st / 2nd | Point | Line | Polygon | |:------------:|:------------------:|:------------------:|:------------------:| | Point | :heavy_check_mark: | :x: | :x: | | Line | :x: | :heavy_check_mark: | :x: | | Polygon | :x: | :x: | :heavy_check_mark: |

  • touches

    | 1st / 2nd | Point | Line | Polygon | |:------------:|:------------------:|:------------------:|:------------------:| | Point | :x: | :heavy_check_mark: | :heavy_check_mark: | | Line | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | Polygon | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

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 install
npm test

LICENSE

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

Source code is released under the MIT License.