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

@mapbox/geojson-tidy

v2.0.0

Published

tidy up a geojson input by filtering out noisy point clusters

Downloads

162

Readme

Build Status

geojson-tidy

Create a tidy geojson by resmapling points in the feature based on sampling time and distance. Handy when geometries that have been converted from a noisy GPS/GPX output.

  • Set a minimum sampling time between successive points (Default: 5 seconds)
  • Set a minimum distance between successive points (Default: 10 metres)
  • Set a maximum feature length to split long segments (Default: 100 points)

untitled

install

npm install @mapbox/geojson-tidy

usage

var geojsonTidy = require('@mapbox/geojson-tidy');

var tidyLineString = geojsonTidy.tidy(obj, [options]);

Input

Any geojson file from togeojson is a valid input for geojson-tidy. Only LineString features are processed currently.

The timestamp array for the trackpoints need to be stored stored in features[].properties.coordTimes[]. Timestamps can either be JavaScript numeric Time Values (milliseconds since epoch) or strings in the ISO 8601 format.

Output

The default output is a geojson FeatureCollection with the timestamps stored in the cordTimes[] property. All other properties are stripped out.

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "coordTimes": []
            },
            "geometry": {
                "type": "LineString",
                "coordinates": []
            }
        }
    ]
}

API

geojsonTidy.tidy(obj, [options])

Given a geojson object, return contains a tidy geometry with extra points filtered out based on default settings

options

Allows you to set custom values for the filter

{
    minimumDistance: 10, // Minimum distance between points in metres
    minimumTime: 5,      // Minimum time interval between points in seconds
    maximumPoints: 100   // Maximum points in a feature
}

CLI

./geojson-tidy -h
Usage: geojson-tidy [-d minimum distance between points] [-t minimum sample time between points] [-m maximum number of points in a single line feature] FILE
FILE is any valid geojson file generated by togeojson
geojson-tidy returns a stingified gejosn FeatureCollection
Example: ./geojson-tidy test/walk-1.json -d 10 -t 5 -m 100 > output.json

Algorithm

  1. Read a geojson FeatureCollection
  2. Loop through the features for LineString features
  3. Compare successive coordinates of the feature
  4. If the dinstance between the points or timestamp difference is too small, delete it
  5. Write a tidied geojson FeatureCollection with reduced points

Development

Build with Browserify

To run this project in the browser, you first need to build it with browserify:

git clone [email protected]:mapbox/geojson-tidy.git

cd geojson-tidy

# to run tests
npm install

# to build geojson-tidy
npm run build

geojson-tidy.js and geojson-tidy.min.js are built files generated from geojson-tidy.js by browserify. If you find an issue, it either needs to be fixed in index.js, or in one of the libraries mapbox-mapmatch uses to parse formats.