geohub
v1.0.4
Published
GeoJSON extractor for Github repos and gists.
Downloads
34
Readme
geohub
GeoJSON extractor for Github repos and gists.
Extracts and parses GeoJSON files from Github repos and gists using the Github API.
Install
npm install geohub
Usage
geohub = require('geohub')
var user = 'chelm'
var repo = 'grunt-geo'
var path = 'forks'
// Extract GeoJSON from a specific path in a repository
geohub.repo({
user: user, // username
repo: repo, // repository
path: path, // path to file or directory
token: token // github access token
}, function (err, data) {
if (err) throw err
console.log(data)
// => if path is a directory, data is an array of geojson objects
// => if path is a filename (omit .geojson extension), data is a geojson object
})
// Omit the 'path' option to extract all GeoJSON files from a repository
geohub.repo({
user: user, // username
repo: repo, // repository
token: token // github access token
}, function (err, data) {
if (err) throw err
console.log(data)
// => data is an array of geojson objects
})
// You can also extract GeoJSON from a specific branch of a repo
geohub.repo({
user: 'koopjs', // username
repo: 'geohub', // repository
branch: 'do-not-delete', // branch name
path: 'portland-parks', // path to file or directory
token: token // github access token
}, function (err, data) {
if (err) throw err
console.log(data)
// => data is a geojson object
})
// Check a file's SHA (useful for caching)
geohub.repoSha({
user: user, // username
repo: repo, // repository
path: path, // path to file
token: token // github access token
}, function (err, sha) {
if (err) throw err
console.log(sha)
// => SHA string
})
// Extract GeoJSON from a gist
geohub.gist({
id: 6021269, // gist ID
token: token // github access token
}, function (err, data) {
if (err) throw err
console.log(data)
// => data is an array of geojson objects
})
Test
Geohub uses tape for testing. It is recommended to create your own Github access token for use during testing to ensure you will not hit Github API rate limits.
GITHUB_TOKEN=XXXXXX npm test