How to use the mapnik.register_datasource function in mapnik

To help you get started, we’ve selected a few mapnik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / mapnik / mapnik-tests.ts View on Github external
const im: mapnik.Image = new mapnik.Image(256, 256);
  map.render(im, function xxx(err: Error, im: mapnik.Image) {
    if (err) throw err;
    im.encode('png', function xxxx(err: Error, buffer: Buffer) {
      if (err) throw err;
      fs.writeFile('map.png', buffer, function xxxxx(err: Error | null) {
        if (err) throw err;
        console.log('saved map image to map.png');
      });
    });
  });
});

// new mapnik.Image.open("xxx").save("xx");

mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins, 'shape.input'));
const ds: mapnik.Datasource = new mapnik.Datasource({type: 'shape', file: 'test/data/world_merc.shp'});
const featureset: mapnik.Featureset = ds.featureset();
const geojson: any = {
  type: "FeatureCollection",
  features: [
  ]
};
let feat: mapnik.FeaturesetNext = featureset.next();
while (feat) {
  geojson.features.push(JSON.parse(feat.toJSON()));
  feat = featureset.next();
}
fs.writeFileSync("output.geojson", JSON.stringify(geojson, null, 2));
github koopjs / koop-core / lib / Tiles.js View on Github external
var mapnik = require('mapnik'),  
  mapnikPool = require('mapnik-pool')(mapnik),
  mercator = new(require('sphericalmercator'))(),
  nfs = require('node-fs'),
  request = require('request'),
  path = require('path'),
  fs = require('fs');

mapnik.register_default_input_plugins();

// register geojson as a datasource in mapnik
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'geojson.input'));

// create a space to hold pools of maps for repeat referencing
mapnik.pools = {};

var Tiles = function( koop ){

  this.mapnikHeader = '<map>';

  this.mapnikFooter = '</map>';

  this.buildTableQuery = function( table, fields ){
    var select = "(Select geom, ";
    var list = [];
    fields.forEach(function(field, i){
      list.push("feature-&gt;'properties'-&gt;&gt;'"+field.name+"' as "+field.name);
    });
github mapbox / vector-tile-js / fixtures.js View on Github external
var mapnik = require('mapnik');
var path = require('path');
var fs = require('fs');

mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins, 'geojson.input'));

var fixtures = {
    "zero-point": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "MultiPoint",
                    "coordinates": []
                },
                "properties": {}
            }
        ]
    },
    "zero-line": {
github stepankuzmin / tilelive-postgis / src / index.js View on Github external
const path = require('path');
const mapnik = require('mapnik');
const mapnikPool = require('mapnik-pool')(mapnik);
const parse = require('./parse');

const postgisInput = path.resolve(mapnik.settings.paths.input_plugins, 'postgis.input');
mapnik.register_datasource(postgisInput);

const srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over';

const PostgisSource = function PostgisSource(uri, callback) {
  const options = parse(uri);

  const { layerName } = options;
  delete options.layerName;

  const datasource = new mapnik.Datasource(options);
  const layer = new mapnik.Layer(layerName);
  layer.datasource = datasource;

  const map = new mapnik.Map(256, 256, srs);
  map.add_layer(layer);