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

geojson-clipping

v0.3.0

Published

Apply boolean polygon clipping operations (union, intersection, difference, xor) to Polygons & MultiPolygons in your GeoJSON files.

Downloads

6

Readme

geojson-clipping

Apply boolean polygon clipping operations (union, intersection, difference, xor) to Polygons & MultiPolygons in your GeoJSON files.

npm version build status test coverage

Quickstart

$ npm install -g geojson-clipping
$ cat poly1.geojson poly2.geojson | geojson-clipping union > union.geojson

Usage

$ geojson-clipping union        [-o <path>] [<path> ... ]
$ geojson-clipping intersection [-o <path>] [<path> ... ]
$ geojson-clipping xor          [-o <path>] [<path> ... ]
$ geojson-clipping difference   [-o <path>] [<path> ... ] [ -s <path> ]

Input/output streams:

  • stdin: Input GeoJSON objects, whitespace separated, may be piped in via stdin.
  • stdout Output GeoJSON is by default written to stdout.
  • stderr: Any warnings generated are by default written to stderr.

Input

Input GeoJSON objects may be provided via:

  • the positional <path> arguments, each of which may point to any of:
    • a GeoJSON file
    • a file with multiple GeoJSON objects in it, whitespace separated (ex: ndjson)
    • a directory, in which case any files with a .geojson extension found immediately within it will be used as input
  • stdin (objects may optionally be separated by whitespace)
  • the -s / --subject <path> option, for the difference() operation only

The following GeoJSON object types are acceptable input:

  • Polygon
  • MultiPolygon
  • Feature containing Polygon or MultiPolygon
  • FeatureCollection containing an array of acceptable Features

If a GeoJSON object with a different type is encountered (ex: Point) the offending object will be dropped and a warning will be printed to stderr.

Output

The computed GeoJSON is by default written to stdout, but may be redirected using the -o / --output <path> option. The output GeoJSON will have the following properties:

  • it will be a single GeoJSON Feature object with a geometry of type MultiPolygon.
  • the Feature's properties attribute will be set to null.
  • if the geometry of resulting from the operation is the empty set (ex: intersection of non-overlapping polygons) then the coordinates of the MultiPolygon will be [].
  • it will have the qualities guaranteed by polygon-clipping.

Options

-s / --subject <path>

Valid only for difference() operation. Invalid for other operations.

Use the file identified by <path> as input GeoJSON, and consider it to be the subject in the difference() operation. That is to say, all other GeoJSON objects will be subtracted from this GeoJSON object.

If this option is not supplied, the subject will by default be the first GeoJSON object read in from stdin.

-b / --bboxes

Valid only for difference() operation. Invalid for other operations.

Scan input GeoJSON filenames for pre-computed stringified bounding boxes. If no bounding box is found in the filename, then compute a bounding box from the GeoJSON coordinates. Examples of filenames containing bounding boxes:

  • [-10,-10,10,10].json
  • 424242.[-58.5314588,-34.705637,-58.3351249,-34.5265535].geojson

If a the bounding box of a given GeoJSON object does not overlap the bounding box of the subject, that GeoJSON object is dropped from the calculation as it cannot contribute to the end result, resulting in a performance boost. In the case that the bounding box was extracted from the filename, the non-contributing GeoJSON object is dropped without reading the file in from disk.

-o / --output <path>

Write the output GeoJSON object out to a newly-created file located at <path>.

If this option is not supplied, the ouput GeoJSON will be written to stdout.

-i / --id <id>

Add to the output GeoJSON object the Feature id <id>. If <id> can be parsed as a number it will be written into the output GeoJSON as a number, else it will be written out as a string.

If this option is not supplied, the output GeoJSON will not have a Feature id.

-q / --quiet

Suppress any warnings generated.

If this option is not supplied, any warnings generated will be written to stderr.

-h / --help

Display help message and exit.

-v / --version

Display version string and exit.

Examples

Equivalent ways to take the union of three GeoJSON objects:

$ cat poly1.geojson poly2.geojson poly3.geojson | geojson-clipping union > union.geojson
$ geojson-clipping union poly1.geojson poly2.geojson poly3.geojson > union.geojson
$ geojson-clipping union -o union.geojson poly1.geojson poly2.geojson poly3.geojson

Equivalent ways to take the difference (aka subtract) a directory full of GeoJSON objects from another GeoJSON object:

$ cat subject.geojson | geojson-clipping difference ./directory-with-geojson-files > difference.geojson
$ geojson-clipping difference -s subject.geojson -o difference.geojson ./directory-with-geojson-files

Changelog

0.3 (2018-04-01)

  • Performance improvements
  • enhance -b / --bboxes to better support bounding boxes that cross the antimeridian #4

0.2 (2018-03-09)

  • add -i / --id <id> option #3
  • add -b / --bboxes option for difference() operation #2
  • create output directories as needed #1

0.1 (2018-03-07)

  • Initial release