Git Product home page Git Product logo

labs-geojson2mvt's Introduction

geojson2mvt

Cuts a file pyramid of static vector tiles (.mvt) from a geojson file

Why

We are using mapboxGL in The Capital Planning Platform, and needed an alternative to downloading large static data files for local rendering on the map. We didn't want to put them into a service that would require $ and maintenance, so static vector tiles seemed like a useful alternative for data that will not change very often.

How to Use

Install npm install geojson2mvt

geojson2mvt takes a config object with the GeoJSONs to encode and other options, and builds the pyramid in the specified output directory

var fs = require('fs');
var geojson2mvt = require('geojson2mvt');

var options = {
  layers: {
    layer0: JSON.parse(fs.readFileSync('bus_routes.geojson', "utf8")),
    layer1: JSON.parse(fs.readFileSync('stops.geojson', "utf8"))
  },
  rootDir: 'tiles',
  bbox : [40.426042,-74.599228,40.884448,-73.409958], //[south,west,north,east]
  zoom : {
    min : 8,
    max : 18,
  }
};
// build the static tile pyramid
geojson2mvt(options);

Check out /example for a test project that you can try locally

Options

layers - Object<string,Object> (required) - GeoJSONs to create a vector tileset from. Keys are the layer names that will be used to access data from the respective GeoJSON when displaying data from the MVT.

rootDir - string (required) - the filepath of the directory that will be the root of the file pyramid. It will be created if it doesn't exist.

bbox - array (required) - array of lat/lon bounds like [s,w,n,e]

zoom - object (required) - object with min and max properties for the desired zoom levels in the tile pyramid

Backwards compatibility

Instead of providing a single config object, you can provide two arguments: a geoJson and config object without a layers property, but instead with a layerName property for the name for the imported geoJson in the MVT.

labs-geojson2mvt's People

Contributors

ahocevar avatar allthesignals avatar andycochran avatar hanbyul-here avatar jameslmilner avatar maptastik avatar oznogon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

labs-geojson2mvt's Issues

Multiple layers

Would you be open to accepting a pull request that changes the API slightly to support multiple layers? Something like

var fs = require('fs');
var geojson2mvt = require('geojson2mvt');
 
const busRoutes = './bus_routes.geojson';
const busStops = './bus_stops.geojson';
 
var options = {
  rootDir: 'tiles',
  bbox : [40.426042,-74.599228,40.884448,-73.409958], //[south,west,north,east]
  zoom : {
    min : 8,
    max : 18,
  },
  layers: {
    'layer0': JSON.parse(fs.readFileSync(busRoutes, "utf8")),
    'layer1': JSON.parse(fs.readFileSync(busStops, "utf8"))
  },
};
 
// build the static tile pyramid
geojson2mvt(options);

I could also make this in a backwards compatible way, if desired.

Generating mvt for big geojson files

Reading big files in node

I would like to generate mvt pyramids with your package for really big geojson file(2GB). It is not possible with fs.readFileSync, because of file size. How can I deal with this problem?
Is it possible to generate piramides for many geojson files? Or maybe I should use streams?

Is it use case for multiple layers? Should I cut geojson on many smaller?

Memory leak?

Running geojson2mvt on a large region tends to crash with the javascript heap size limit being reached. I think something is leaking memory in there. Plot shows heapsize vs tile number. You can see the Garbage collection working but its not grabbing everything.

heap

Not sure if this is an issue in geojson2mvt or one of the required libraries but investigating.

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.