# geojson-precision

> Remove meaningless precision from GeoJSON

Latest version **1.0.0** (published 2019-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install geojson-precision
pnpm add geojson-precision
yarn add geojson-precision
bun add geojson-precision
```

Provides the command `geojson-precision`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-01-23 |
| First published | 2014-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/geojson-precision) |
| Module format | CommonJS |
| Node | >=6.4.0 |
| Dependencies | 1 |
| Unpacked size | 24.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | John J Czaplewski |
| Maintainers | jczaplew |
| Keywords | geojson, precision, geojson precision |

## Links

- npm: https://www.npmjs.com/package/geojson-precision
- Repository: https://github.com/jczaplew/geojson-precision
- Issues: https://github.com/jczaplew/geojson-precision/issues
- npm.io page: https://npm.io/package/geojson-precision

## Dependencies (1)

- [commander](https://npm.io/package/commander.md) 2.19.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-01-23
- 0.4.0 — 2015-06-22
- 0.3.0 — 2015-06-22
- 0.2.3 — 2014-10-28
- 0.2.2 — 2014-10-22
- 0.2.1 — 2014-10-19
- 0.2.0 — 2014-10-19
- 0.1.0 — 2014-10-03

## README

# geojson-precision
Remove meaningless precision from your GeoJSON. If your coordinates go out to 7+ digits, you are [probably misrepresenting your data](http://gis.stackexchange.com/a/8674/14196). Most scenarios in which GeoJSON is useful (i.e. web-related applications) do not require survey-grade precision, and a higher value is placed on a compact file size. Trimming the precision of coordinates can greatly reduce file size, while removing the appearance of fake high precision.


## Install
````
npm install [-g] geojson-precision
````


## API


### .parse(*geojson*, *precision*)

````geojson```` is a valid GeoJSON object, and can be of type ````Point````, ````LineString````, ````Polygon````, ````MultiPoint````, ````MultiPolygon````, ````MultiLineString````, ````GeometryCollection````, ````Feature````, or ````FeatureCollection````. If you are unsure whether or not your GeoJSON object is valid, you can run it through a linter such as [geojsonhint](https://github.com/mapbox/geojsonhint).

````precision```` is a positive integer. If your specified ````precision```` value is greater than the precision of the input geometry, the output precision will be the same as the input. For example, if your input coordinates are ````[10.0, 20.0]````, and you specify a ````precision```` of ````5````, the output will be the same as the input.


##### Example use:

````javascript
const gp = require("geojson-precision");

let trimmed = gp.parse({
        "type": "Point",
        "coordinates": [
          18.984375,
          57.32652122521709
        ]
      }, 3);

````

````trimmed```` will now look like this:

````javascript
{
    "type": "Point",
    "coordinates": [
       18.984,
       57.326
    ]
}
````

 ````.parse()```` can also be used directly, for example:

 ````javascript
const gp = require("geojson-precision");

let trimmed = gp({ ... }, 3);

````


## CLI
Geojson-precision can also be used via the command line when installed globally (using ````-g````).

### Parameters
######  precision (-p)
A positive integer specifying coordinate precision

######  extras precision (-e)
A positive integer specifying extra coordinate precision for things like the z value when the coordinate is [longitude, latitude, elevation].

###### input
An input GeoJSON file

###### output
An output GeoJSON file

##### Example use
````
geojson-precision -p 4 input.json output.json
````




## Inspiration
Concepts, ideas, etc borrowed to various degrees from:

  - [wellknown](https://github.com/mapbox/wellknown/pull/18)
  - [LilJSON](https://github.com/migurski/LilJSON)


## License
MIT

---
_Source: https://npm.io/package/geojson-precision · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
