Home

Awesome

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

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.