Git Product home page Git Product logo

geojson-tidy's Introduction

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.

geojson-tidy's People

Contributors

aaronlidman avatar freenerd avatar lxbarth avatar planemad avatar sbma44 avatar tmcw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.