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

vt-geojson

v2.1.1

Published

Stream GeoJSON from Mapbox vector tiles.

Downloads

14

Readme

vt-geojson

js-standard-style

Build Status

Extract GeoJSON from Mapbox vector tiles.

Usage

CLI

Install with npm install -g vt-geojson, and then:

vt-geojson /path/to/tiles.mbtiles --bounds minx miny maxx maxy
cat bounding_polygon.geojson | vt-geojson tilejson+http://api.tiles.mapbox.com/v4/YOUR-MAPID?access_token=YOUR_MAPBOX_TOKEN -z 12
vt-geojson someone.blahblah --tile tilex tiley tilez # ('someone.blahblah' is a mapid)

Node

First npm install vt-geojson and then:

var cover = require('tile-cover')
var vtGeoJson = require('vt-geojson')

var polygon = JSON.parse(fs.readFileSync('my-polygon.geojson'))
var source = 'tilejson+http://api.tiles.mapbox.com/v4/YOUR-MAPID?access_token=YOUR_MAPBOX_TOKEN'

// get an array of tiles ([x, y, z]) that we want to pull data from.
var tiles = cover.tiles(polygon.geometry, { min_zoom: 10, max_zoom: 12 })

// stream geojson from the chosen tiles:
vtGeoJson(source, tiles)
  .on('data', function (feature) {
    console.log("it's a GeoJSON feature!", feature.geometry.type, feature.properties)
  })
  .on('end', function () {
    console.log('all done')
  })

Browser

This module should work with browserify. There's a minimal example of using it in the browser here. Try it with:

npm install -g budo
budo example/browser.js

Then go to http://localhost:9966/?mapid=mapbox.mapbox-streets-v6&tile=73/97/8&layers=road&access_token=YOUR_MAPBOX_ACCESS_TOKEN

API

vtgeojson

Stream GeoJSON from a Mapbox Vector Tile source

Parameters

  • uri string the tilelive URI for the vector tile source to use.
  • options object options
    • options.layers Array<string> An array of layer names to read from tiles. If empty, read all layers
    • options.tiles Array The tiles to read from the tilelive source. If empty, use options.bounds instead.
    • options.bounds Array The [minx, miny, maxx, maxy] bounds or a GeoJSON Feature, FeatureCollection, or Geometry defining the region to read from source. Ignored if options.tiles is set. If empty, use the bounds from the input source's metadata.
    • options.minzoom number Defaults to the source metadata minzoom. Ignored if options.tiles is set.
    • options.maxzoom number Defaults to the source metadata minzoom. Ignored if options.tiles is set.
    • options.tilesOnly boolean Output [z, y, x] tile coordinates instead of actually reading tiles. Useful for debugging.
    • options.strict boolean Emit an error and end the stream if a tile is not found or can't be read

Returns ReadableStream<Feature> A stream of GeoJSON Feature objects. Emits warning events with { tile, error } when a tile from the requested set is not found or can't be read.

Contributing

This is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.