GithubHelp home page GithubHelp logo

glifchits / node-mvt-encoder Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 83 KB

A Node.js utility to encode a vector tile schema into a Mapbox vector tile

License: MIT License

Python 5.78% Shell 2.52% JavaScript 71.33% Protocol Buffer 20.37%
mapbox-vector-tile vector-tiles

node-mvt-encoder's Introduction

node-mvt-encoder

npm Build Status

A Node.js utility to encode a vector tile spec into a Mapbox vector tile.

Installation

npm install mvt-encoder

node-gdal is a dependency of this project. It requires gdal to be installed in your environment:

apt-get update -y && apt-get install -y libproj-dev gdal-bin

Usage

var tileEncode = require('mvt-encoder');
var VectorTile = require('@mapbox/vector-tile').VectorTile

var tileSpec = [{
  name: 'blocks',
  features: [{
    geometry: "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
    properties: {
      hello: "world"
    }
  }]
}];

var encoded = tileEncode(tileSpec);
var decoded = new VectorTile(encoded)

console.log(decoded.layers)
// { blocks: VectorTileLayer {...} }

Tile specification

The tileEncode function exported in this module takes one parameter: a "tile spec". This was inspired by Mapzen's mapbox-vector-tile package.

A "tile spec" is an array of "layer specs".

a "layer spec" is an object with the properties:

  • name: the name of the layer (string)
  • features: an array of objects with the properties:
    • geometry: a WKT representation of a feature geometry. Coordinates are relative to the tile, scaled in the range [0, 4096)
    • properties: an object with arbitrary key/values.

Notes

  • Only tested for Polygon features
  • Does not quantize geometry to the tile grid
  • Outputs Mapbox vector tile conforming to (at best) version 1 of the spec

node-mvt-encoder's People

Contributors

glifchits avatar

Stargazers

 avatar

Watchers

 avatar  avatar

node-mvt-encoder's Issues

Provide more meaningful error messages

Trying to integrate this module into an app I get:

  Error: Unsupported geometry type
      at features.forEach (/app/node_modules/mvt-encoder/tileEncoder.js:139:32)
      at Array.forEach (<anonymous>)
      at encodeFeatures (/app/node_modules/mvt-encoder/tileEncoder.js:138:12)

(provided EWKT from PostGIS, not a WKT)

or

  TypeError: Cannot read property 'count' of undefined
      at encodeGeometry (/app/node_modules/mvt-encoder/tileEncoder.js:74:45)
      at features.forEach (/app/node_modules/mvt-encoder/tileEncoder.js:144:17)
      at Array.forEach (<anonymous>)

(probably because I provided a MULTIPOLYGON)

Test cases to check:

  • Unsupported input geometry (require WKT)
  • Unsupported geometry during encoding (only support POLYGON for now)
  • Coordinates not scaled to tile extent (forgot to translate them)

Publish as NPM package

Do some clean up to ensure this can be cleanly imported as a module with a simple API

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.