How to use the mapnik.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 spatialdev / PGRestAPI / endpoints / tiles / index.js View on Github external
if (fullpath) {

      var geojson_settings = {
        type: 'geojson',
        file: fullpath
      };

      //We're all good. Make the picture.
      try {
        //create map and layer
        var map = new mapnik.Map(parseInt(args.width), parseInt(args.height), geographic.proj4);
        //width, height
        var layer = new mapnik.Layer("geojson", ((_self.epsg && (_self.epsg == 3857 || _self.epsg == 3587)) ? mercator.proj4 : geographic.proj4));
        //check to see if 3857.  If not, assume WGS84
        var geojson_ds = new mapnik.Datasource(geojson_settings);

        var bboxArray = [bbox.xmin, bbox.ymax, bbox.xmax, bbox.ymin];

        layer.datasource = geojson_ds;
        layer.styles = ["geojson", 'default'];

        map.bufferSize = 64;

        var stylepath = __dirname + '/cartocss/' + _defaultMSS;

        map.load(path.join(stylepath), {
          strict: true
        }, function (err, map) {

          console.log(map.toXML());
          // Debug settings
github AmericanRedCross / GeoForce / Chubbs / endpoints / mapnik / index.js View on Github external
if (fullpath) {

            var geojson_settings = {
                type: 'geojson',
                file: fullpath
            };

            //We're all good. Make the picture.
            try {
                //create map and layer
                var map = new mapnik.Map(parseInt(args.width), parseInt(args.height), geographic.proj4);
                //width, height
                var layer = new mapnik.Layer("geojson", ((_self.epsg && (_self.epsg == 3857 || _self.epsg == 3587)) ? mercator.proj4 : geographic.proj4));
                //check to see if 3857.  If not, assume WGS84
                var geojson_ds = new mapnik.Datasource(geojson_settings);

                var bboxArray = [bbox.xmin, bbox.ymax, bbox.xmax, bbox.ymin];

                layer.datasource = geojson_ds;
                layer.styles = ["geojson", 'style'];

                map.bufferSize = 64;

                var stylepath = __dirname + '/cartocss/style.xml';

                map.load(path.join(stylepath), {
                    strict: true
                }, function (err, map) {

                    console.log(map.toXML());
                    // Debug settings
github spatialdev / PGRestAPI / endpoints / tiles / index.js View on Github external
function createInMemoryDatasource(name, path_to_shp) {
  var shapefile = new mapnik.Datasource({
    type: 'shape',
    file: path_to_shp
  });

  // get the featureset that exposes lazy next() iterator
  var featureset = shapefile.featureset();

  var mem_datasource = new mapnik.MemoryDatasource(
    {}
  );

  // build up memory datasource
  while (( feat = featureset.next(true))) {
    var e = feat.extent();
    // center longitude of polygon bbox
    var x = (e[0] + e[2]) / 2;
github mapbox / mapnik-omnivore / lib / datasourceProcessor.js View on Github external
function getLayers(options, callback) {
    var layers_array;
    var error;
    //Expect an error in order to obtain layer names from the OGR Error string...for now
    try {
        var ds = new mapnik.Datasource(options);
    } catch (err) {
        if (err.message && err.message.indexOf('OGR Plugin: missing ') !== -1) {
            var layers = err.message.split('are: ')[1];
            //trim whitespaces before each layer
            layers = layers.replace(/\s*,\s*/g, ',');
            //remove quotes
            var layer_names = layers.split('\'').join('');
            //designate each index of the array by splitting by commas
            layers_array = layer_names.split(',');
        } else error = err;
    }
    if (error === undefined) return callback(null, layers_array);
    else return callback(invalid('Error obtaining layer names'));
}
github mapbox / mapnik-omnivore / lib / datasourceProcessor.js View on Github external
function processRasterDatasource(file, filesize, name, info, filetype, callback) {
    var results;
    var options = {
        type: 'gdal', 
        file: file
    };
    try{
        var ds = new mapnik.Datasource(options);
        results = getCenterAndExtent(ds, info.proj4, filetype);
    } catch(err){
        return callback(invalid(err));
    }
    //calculate source's min/max zoom
    getMinMaxZoomGDAL(info.raster.pixelSize, results.center, info.proj4, function(err, min, max) {
        if (err) return callback(err);
        //Values to input into xml for Mapnik
        return callback(null, {
            extent: results.extent,
            center: results.center,
            raster: info.raster,
            proj: info.proj4,
            minzoom: min,
            maxzoom: max,
            dstype: 'gdal'
github mapbox / mapnik-omnivore / lib / topojson.js View on Github external
function TopoJSON(filepath) {
  this.filepath = filepath;
  this.datasource = new mapnik.Datasource({
    type: 'topojson',
    file: filepath
  });
  this.extent = this.datasource.extent();
  this.center = [
    0.5 * (this.extent[0] + this.extent[2]),
    0.5 * (this.extent[1] + this.extent[3])
  ];
  this.layers = [path.basename(this.filepath, path.extname(this.filepath))];
}
github mapbox / mapbox-studio-classic / lib / source.js View on Github external
data.vector_layers = local && !raster ? data.Layer.reduce(function(vlayers, l) {
            var info = {};
            info.id = l.id;

            if ('description' in l) info.description = l.description;
            info.fields = [];
            var opts = _(l.Datasource).clone();

            if (opts.file && !tm.absolute(opts.file)) opts.base = tm.parse(data.id).dirname;

            var fields = new mapnik.Datasource(opts).describe().fields;
            info.fields = _(fields).reduce(function(memo, type, field) {
                memo[field] = l.fields[field] || type;
                return memo;
            }, {});

            vlayers.push(info);
            return vlayers;
        }, [])
        : data.vector_layers;
github spatialdev / PGRestAPI / endpoints / tiles / index.js View on Github external
var startTime = Date.now();

      var args = common.getArguments(req);

      //If user passes in where clause or fields, then build the query here and set it with the table property of postgis_setting
      if (args.fields || args.where) {
        //Validate where - TODO

        //If a where clause was passed in, and we're using a postgis datasource, allow it
        if (_self.settings.mapnik_datasource.type.toLowerCase() == 'postgis') {
          _self.settings.mapnik_datasource.table = (args.fields ? '(SELECT ' + _self.settings.routeProperties.geom_field + (args.fields ? ',' + args.fields : '') + ' from "' + _self.settings.routeProperties.table + '"' + (args.where ? ' WHERE ' + args.where : '') + ') as "' + _self.settings.routeProperties.table + '"' : '"' + _self.settings.routeProperties.table + '"');
        }
      }

      //Make the mapnik datasource.  We wait until now in case the table definition changes if a where clause is passed in above.
      _self.mapnikDatasource = (_self.settings.mapnik_datasource.describe ? _self.settings.mapnik_datasource : new mapnik.Datasource(_self.settings.mapnik_datasource));


      try {
        //create map
        var map = new mapnik.Map(256, 256, mercator.proj4);

        var layer = new mapnik.Layer(_self.settings.routeProperties.name, ((_self.epsg && (_self.epsg == 3857 || _self.epsg == 3587)) ? mercator.proj4 : geographic.proj4));

        var label_point_layer;
        if(args.labelpoints && _self.settings.mapnik_datasource.type.toLowerCase() == 'postgis') {
          //If user specifies label points to be created, then create another layer in this vector tile that stores the centroid to use as a label point.

          //The only difference in the datasource is the table parameter, which is either a table name, or a sub query that allows you specify a WHERE clause.
          _self.settings.mapnik_datasource.table = (args.fields ? '(SELECT ' + ('ST_PointOnSurface(' + _self.settings.routeProperties.geom_field + ') as geom' ) + (args.fields ? ',' + args.fields : '')  + ' from "' + _self.settings.routeProperties.table + '"' + (args.where ? ' WHERE ' + args.where : '') + ') as "' + _self.settings.routeProperties.table + "_label" + '"' : '"' + _self.settings.routeProperties.table + '"');

          //Make a new Mapnik datasource object
github spatialdev / PGRestAPI / endpoints / mapnik / index.js View on Github external
function (app, routeSettings, performanceObject) {

    this.app = app;
    this.settings = routeSettings;
    this.performanceObject = performanceObject
    this.mapnikDatasource = (this.settings.mapnik_datasource.describe ? this.settings.mapnik_datasource : new mapnik.Datasource(this.settings.mapnik_datasource));
    this();
},
function () {