How to use the mapnik.Projection 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 kosmtik / kosmtik / src / back / Tile.js View on Github external
var Tile = function (z, x, y, options) {
    options = options || {};
    var DEFAULT_HEIGHT = 256;
    var DEFAULT_WIDTH = 256;
    this.z = +z;
    this.x = +x;
    this.y = +y;
    this.projection = new mapnik.Projection(options.projection || Tile.DEFAULT_OUTPUT_PROJECTION);
    this.scale = options.scale || 1;  // When the tile coverage gets bigger (1024px…) or for metatile.
    this.mapScale = options.mapScale;  // Retina.
    this.height = options.height || options.size || DEFAULT_HEIGHT;
    this.width = options.width || options.size || DEFAULT_WIDTH;
    this.buffer_size = options.buffer_size || 0;
};
github mapbox / mapnik-omnivore / lib / datasourceProcessor.js View on Github external
function getCenterAndExtent(ds, projection) {
    var extent;
    // Convert datasource extent to lon/lat when saving
    var fromProj = new mapnik.Projection(projection);
    var toProj = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
        
    if (fromProj === toProj) {
        try {
            extent = ds.extent();
        } catch (err) {
            return invalid('Error obtaining extent of Mapnik datasource.');
        }
    } else {
        try {
            var trans = new mapnik.ProjTransform(fromProj, toProj);
            //Bounding box
            extent = trans.forward(ds.extent());
        } catch (err) {
            return invalid('Error obtaining extent of Mapnik datasource.');
        }
    }
github mapbox / mapnik-omnivore / lib / datasourceProcessor.js View on Github external
function getCenterAndExtent(ds, projection) {
    var extent;
    // Convert datasource extent to lon/lat when saving
    var fromProj = new mapnik.Projection(projection);
    var toProj = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
        
    if (fromProj === toProj) {
        try {
            extent = ds.extent();
        } catch (err) {
            return invalid('Error obtaining extent of Mapnik datasource.');
        }
    } else {
        try {
            var trans = new mapnik.ProjTransform(fromProj, toProj);
            //Bounding box
            extent = trans.forward(ds.extent());
        } catch (err) {
            return invalid('Error obtaining extent of Mapnik datasource.');
        }
github mapnik / node-mapnik / examples / js_datasource / usgs_quakes.js View on Github external
s += '  ';
s += ' ';
s += ' ';
s += '  ';
s += '  ';
s += ' ';
s += ' ';
s += '  ';
s += '  ';
s += ' ';
s += '';
s += '';

// create map object with base map
var map = new mapnik.Map(800, 600);
var merc = new mapnik.Projection('+init=epsg:3857');
map.loadSync(path.join(__dirname, '../stylesheet.xml'));
map.fromStringSync(s);

// Latest 30 days of earthquakes > 2.5 from USGS (http://earthquake.usgs.gov/earthquakes/catalogs/)
// CSV munged into json using Yahoo pipes
var dl = new get('http://pipes.yahoo.com/pipes/pipe.run?_id=f36216d2581df7ed23615f42ff2af187&_render=json');
dl.asString(function(err,str) {
  // Loop through quake list
  // WARNING - this API will change!
  var quakes = JSON.parse(str).value.items;
  var quake;
  var next = function() {
      while ((quake = quakes.pop())) {
        var merc_coords = merc.forward([+quake.Lon, +quake.Lat]); //reproject wgs84 to mercator
        return { 'x' : merc_coords[0],
                 'y' : merc_coords[1],
github AmericanRedCross / GeoForce / Chubbs / utils / sphericalmercator.js View on Github external
var mapnik = require('mapnik');

var proj4 = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over';
var mercator = new mapnik.Projection(proj4);

/**
 * SphericalMercator constructor: precaches calculations
 * for fast tile lookups
 */
function SphericalMercator() {
    var size = 256;
    this.Bc = [];
    this.Cc = [];
    this.zc = [];
    this.Ac = [];
    this.DEG_TO_RAD = Math.PI / 180;
    this.RAD_TO_DEG = 180 / Math.PI;
    this.size = 256;
    this.levels = 18;
    this.proj4 = proj4;
github kosmtik / kosmtik / src / plugins / base-exporters / PNG.js View on Github external
map.fromString(this.project.render(), {base: this.project.root}, function render (err, map) {
        var projection = new mapnik.Projection(map.srs),
            im = new mapnik.Image(+self.options.width, +self.options.height);
        map.zoomToBox(projection.forward(self.bounds));
        map.render(im, {scale: self.scale}, function toImage (err, im) {
            if (err) throw err;
            im.encode(self.options.format, callback);
        });
    });
};
github mapbox / mapnik-omnivore / lib / raster.js View on Github external
Raster.prototype.getExtent = function(callback) {
  var current = new mapnik.Projection(this.projection);
  var wgs84 = new mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs');
  var extent;
  var transform;

  try {
    extent = this.mapnikDatasource.extent();
  } catch (err) {
    return callback(invalid('Invalid raster: could not read extent'));
  }

  if (current !== wgs84) {
    try {
      transform = new mapnik.ProjTransform(current, wgs84);
      extent = transform.forward(extent);
    } catch (err) {
      return callback(invalid('Invalid raster: Unable to compute bounds. X or Y values exceed limits of provided CRS.'));
github mapbox / tilelive-bridge / index.js View on Github external
if (newdoc.bbox[0] === newdoc.bbox[2]) {
                delete newdoc.bbox;
            }

            var geom = f.geometry();

            if (srs == '+init=epsg:4326') {
                geom.toJSON(function(err,json_string) {
                    newdoc.geometry = JSON.parse(json_string);
                    docs.push(newdoc);
                    i++;
                    immediate(feature);
                });
            } else {
                var from = new mapnik.Projection(srs);
                var to = new mapnik.Projection('+init=epsg:4326');
                var tr = new mapnik.ProjTransform(from,to);
                geom.toJSON({transform:tr},function(err,json_string) {
                    newdoc.geometry = JSON.parse(json_string);
                    docs.push(newdoc);
                    i++;
                    immediate(feature);
                });
            }
        }