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

minify-geojson

v1.4.4

Published

Minify (compress) a GeoJSON by replacing the attribute keys with a shorter representation (typically, its first letter). You can also reduce the number of decimals for coordinates, and whitelist and blacklist certain properties.

Downloads

319

Readme

minify-geojson

Codacy Badge

A small tool to minify (compress) a GeoJSON file by:

  • Removing non-significant whitespace
  • Reducing the number of decimals used for coordinates: option -c 5 to keep 5 decimals
  • Minify the length of the keys by mapping each key name to a single or double letter combination: option -k converts long property keys such as my_long_property_name to a or ab. Warning: If you already have property keys like a or b, it may map them to the wrong name.
  • Blacklist keys, i.e. remove these keys from the output
  • Whitelist keys, i.e. only keep these keys in the output
  • Filter features, i.e. only keep those features whose properties satisfy certain conditions.

The tool works in two modes: for files that require reprojection or topojson output, it will read in all data at once. In case your GeoJSON file is too large for node.js to handle, this may fail. That's why it normally uses a streaming mode, so also large files can be processed easily (after which you can try reprojecting it again).

Installation

To run it standalone:

npm i -g minify-geojson

After which the minify-geojson command should be available.

Alternatively, you can fork/download/clone the repository, and execute:

npm install
npm link
npm run watch

Any changes in the Typescript code will be compiled, and since you've linked the project, you can use the minify-geojson command from the command line too.

Manual

Minify GeoJSON

  Minify (compress) each input GeoJSON or ESRI shapefile by replacing the
  attribute keys with a shorter representation (typically, its first letter).
  You can also reduce the number of decimals for coordinates and properties,
  whitelist and blacklist or filter certain properties. Output can be GeoJSON
  or TopoJSON. If you wish to reproject to WGS84, you can supply the EPSG code
  (which will be resolved via
  http://www.spatialreference.org/ref/epsg/YOURCODE/proj4/).

Options

  -k, --keys Boolean                  Minify property keys, e.g. id remains id, telephone
                                      becomes t, address a etc.
  -i, --includeKeyMap Boolean         Add the key map to the GeoJSON file. Requires the -k
                                      flag too.
  -t, --topo Boolean                  Output format is TopoJSON instead of GeoJSON.
  -r, --reproject String              Reproject to WGS84 by supplying the input EPSG
                                      coordinate system, e.g. -r EPSG:28992.
  -f, --filter String                 Comma separted list of property filters, which will
                                      KEEP those features when the property filter returns
                                      true, e.g. filter "WATER = NO" will filter out
                                      feature\'s where { "WATER": "NO" }.
  -b, --blacklist String              Comma separated list of properties that should be
                                      removed (others will be kept). Note that keys will not
                                      be minified unless the -k flag is used too.
  -w, --whitelist String              Comma separated list of properties that should be kept
                                      (others will be removed). Note that keys will not be
                                      minified unless the -k flag is used too.
  -c, --coordinates Positive number   Only keep the first n digits of each coordinate.
  -d, --decimals Positive number      Only keep the first n digits of each decimal property.
  -s, --src File names                Source files to process: default option, you do not need to
                                      supply the -s flag.
  -v, --verbose Boolean               Output is verbose.

Examples

  01. Shrink property keys and output to        $ minify-geojson -k original.geojson
  original.min.geojson
  02. A verbose version                         $ minify-geojson -kv original.geojson
  03. Prune the blacklisted properties          $ minify-geojson -b "property1, property2"
                                                original.geojson
  04. Keep the whitelisted properties           $ minify-geojson -w "property1, property2"
                                                original.geojson
  05. Removes superfluous decimals (keep        $ minify-geojson -c 5 original.geojson
  first 5)
  06. Add the key mapping to the output         $ minify-geojson -ki original.geojson
  07. Convert output to topojson (-i and -c     $ minify-geojson -kt original.geojson
  are not used)
  08. Reproject shape file in RD (EPSG:28992)   $ minify-geojson -ktv -r 28992 original.shp
  to TopoJSON
  09. Filter based on properties                $ minify-geojson -ktv -r 28992 -f "WATER =
                                                NO, CITY=Amsterdam" -b "WATER, CITY"
                                                original.shp
  10. Full example                              $ minify-geojson -ktiv -w "property1,
                                                property2" -c 5 original.geojson