mapnik

src/node_mapnik.cpp

Mapnik is the core of cartographic design and processing.

Properties

mapnik.Color(value, green, blue, blue, premultiplied)

src/mapnik_color.cpp

Parameters

Throws

  • TypeError:

    if a rgb component is outside of the 0-255 range

Examples

var c = new mapnik.Color('green');
var c = new mapnik.Color(0, 128, 0, 255);
// premultiplied
var c = new mapnik.Color(0, 128, 0, 255, true);

Instance members

#get_premultiplied

Get whether this color is premultiplied

get_premultiplied

src/mapnik_color.cpp

Get whether this color is premultiplied

Returns

boolean :

premultiplied

#hex

Get this color represented as a hexademical string

hex

src/mapnik_color.cpp

Get this color represented as a hexademical string

Returns

string :

hex representation

Examples

var c = new mapnik.Color('green');
            c.hex();
            // '#008000'
#set_premultiplied(premultiplied)

Set whether this color should be premultiplied

set_premultiplied(premultiplied)

src/mapnik_color.cpp

Set whether this color should be premultiplied

Parameters

Throws

Examples

var c = new mapnik.Color('green');
            c.set_premultiplied(true);
#toString

Get this color's representation as a string

toString

src/mapnik_color.cpp

Get this color's representation as a string

Returns

string :

color as a string

Examples

var green = new mapnik.Color('green');
            green.toString()
            // 'rgb(0,128,0)'

mapnik.Datasource

src/mapnik_datasource.cpp

A Datasource object. This is the connector from Mapnik to any kind of file, network, or database source of geographical data.

Instance members

#describe

Describe the datasource's contents and type.

describe

src/mapnik_datasource.cpp

Describe the datasource's contents and type.

Returns

Object :

description: an object with type, fields, encoding, geometry_type, and proj4 code

mapnik.Feature

src/mapnik_feature.cpp

A single geographic feature, with geometry and properties. This is typically derived from data by a datasource, but can be manually created.

Static members

.fromJSON(geojson)

fromJSON(geojson)

src/mapnik_feature.cpp

Parameters

  • string geojson :

    string

    Create a feature from a GeoJSON representation.

Instance members

#attributes

Get the feature's attributes as an object.

attributes

src/mapnik_feature.cpp

Get the feature's attributes as an object.

Returns

Object :

attributes

#geometry

Get the feature's attributes as a Mapnik geometry.

geometry

src/mapnik_feature.cpp

Get the feature's attributes as a Mapnik geometry.

Returns

mapnik.Geometry :

geometry

#id

id

src/mapnik_feature.cpp

Returns

number :

id the feature's internal id

#toJSON

Generate and return a GeoJSON representation of this feature

toJSON

src/mapnik_feature.cpp

Generate and return a GeoJSON representation of this feature

Returns

string :

geojson Feature object in stringified GeoJSON

mapnik.Featureset

src/mapnik_featureset.cpp

An iterator of mapnik.Feature objects.

Instance members

#next

Return the next Feature in this featureset if it exists, or null if it does not.

next

src/mapnik_featureset.cpp

Return the next Feature in this featureset if it exists, or null if it does not.

Returns

mapnik.Feature or :

next feature

mapnik.Geometry

src/mapnik_geometry.cpp

Geometry: a representation of geographical features in terms of shape alone. This class provides many useful functions for conversion to and from formats.

You'll never create a mapnik.Geometry instance manually: it is always part of a mapnik.Feature instance, which is often a part of a mapnik.Featureset instance.

Instance members

#toJSON([options], callback)

Convert this geometry into a GeoJSON representation, asynchronously.

toJSON([options], callback)

src/mapnik_geometry.cpp

Convert this geometry into a GeoJSON representation, asynchronously.

Parameters

  • [Object] options (default {}) :

    . The only supported object is transform, which should be a valid mapnik.ProjTransform object.

  • Function callback :

    called with (err, result)

#toJSONSync

Convert this geometry into a GeoJSON representation, synchronously.

toJSONSync

src/mapnik_geometry.cpp

Convert this geometry into a GeoJSON representation, synchronously.

Returns

string :

GeoJSON, string-encoded representation of this geometry.

#toWKB

Get the geometry's representation as Well-Known Binary

toWKB

src/mapnik_geometry.cpp

Get the geometry's representation as Well-Known Binary

Returns

string :

wkb representation of this geometry

#toWKT

Get the geometry's representation as Well-Known Text

toWKT

src/mapnik_geometry.cpp

Get the geometry's representation as Well-Known Text

Returns

string :

wkt representation of this geometry

mapnik.Grid(width, height, [options])

src/mapnik_grid.cpp

Generator for UTFGrid representations of data.

Parameters

  • number width :
  • number height :
  • [Object] options (default {}) :

    optional argument, which can have a 'key' property

Properties

mapnik.Image(width, height, options)

src/mapnik_image.cpp

Parameters

  • number width :
  • number height :
  • Object options :

    valid options are premultiplied, painted, type and initialize.

Throws

  • TypeError:

    if any argument is the wrong type, like if width or height is not numeric.

Examples

var im = new mapnik.Image(256, 256, {
  premultiplied: true,
  type: mapnik.imageType.gray8
});

Static members

.fromBufferSync(width, height, buffer)

Create an image of the existing buffer. BUFFER MUST LIVE AS LONG AS THE IMAGE. It is recommended that you do not use this method! Be warned!

fromBufferSync(width, height, buffer)

src/mapnik_image.cpp

Create an image of the existing buffer. BUFFER MUST LIVE AS LONG AS THE IMAGE. It is recommended that you do not use this method! Be warned!

Parameters

Returns

mapnik.Image :

image object

.fromBytes(buffer, callback)

Create a new image from a buffer

fromBytes(buffer, callback)

src/mapnik_image.cpp

Create a new image from a buffer

Parameters

.fromSVG(filename, callback)

Create a new image from an SVG file

fromSVG(filename, callback)

src/mapnik_image.cpp

Create a new image from an SVG file

Parameters

.fromSVGBytes(filename, callback)

Create a new image from an SVG file

fromSVGBytes(filename, callback)

src/mapnik_image.cpp

Create a new image from an SVG file

Parameters

Instance members

#clear(callback)

Make this image transparent, removing all image data from it.

clear(callback)

src/mapnik_image.cpp

Make this image transparent, removing all image data from it.

Parameters

#clearSync

Make this image transparent.

clearSync

src/mapnik_image.cpp

Make this image transparent.

Examples

var im = new mapnik.Image(5,5);
            im.fillSync(1);
            assert.equal(im.getPixel(0, 0), 1);
            im.clearSync();
            assert.equal(im.getPixel(0, 0), 0);
#compare(other, [options])

Compare two images visually. This is useful for algorithms and tests that confirm whether a certain image has changed significantly.

compare(other, [options])

src/mapnik_image.cpp

Compare two images visually. This is useful for algorithms and tests that confirm whether a certain image has changed significantly.

Parameters

  • mapnik.Image other :

    another image instance

  • [Object] options (default {threshold:16,alpha:true}) :

Returns

number :

quantified visual difference between these two images

#composite(other, callback)

Overlay this image with another image, creating a layered composite as a new image

composite(other, callback)

src/mapnik_image.cpp

Overlay this image with another image, creating a layered composite as a new image

Parameters

#copy(type, [options], callback)

Copy this image data so that changes can be made to a clone of it.

copy(type, [options], callback)

src/mapnik_image.cpp

Copy this image data so that changes can be made to a clone of it.

Parameters

#copySync(type, [options])

Copy this image data so that changes can be made to a clone of it.

copySync(type, [options])

src/mapnik_image.cpp

Copy this image data so that changes can be made to a clone of it.

Parameters

Returns

mapnik.Image :

copy

#demultiply(callback)

Demultiply the pixels in this image, asynchronously. The opposite of premultiplying

demultiply(callback)

src/mapnik_image.cpp

Demultiply the pixels in this image, asynchronously. The opposite of premultiplying

Parameters

#demultiplySync

Demultiply the pixels in this image. The opposite of premultiplying

demultiplySync

src/mapnik_image.cpp

Demultiply the pixels in this image. The opposite of premultiplying

#encode([format], callback)

Encode this image into a buffer of encoded data

encode([format], callback)

src/mapnik_image.cpp

Encode this image into a buffer of encoded data

Parameters

Returns

Buffer :

encoded image data

Examples

var fs = require('fs');
            myImage.encode('png', function(err, encoded) {
              fs.writeFileSync('myimage.png', encoded);
            });
#encodeSync([format])

Encode this image into a buffer of encoded data

encodeSync([format])

src/mapnik_image.cpp

Encode this image into a buffer of encoded data

Parameters

  • [string] format (default png) :

    image format

Returns

Buffer :

encoded image data

Examples

var fs = require('fs');
            fs.writeFileSync('myimage.png', myImage.encodeSync('png'));
#fill(color, callback)

Asynchronously fill this image with a given color.

fill(color, callback)

src/mapnik_image.cpp

Asynchronously fill this image with a given color.

Parameters

Examples

var im = new mapnik.Image(5, 5);
            im.fill(1, function(err, im_res) {
              if (err) throw err;
              assert.equal(im_res.getPixel(0, 0), 1);
            });
#fillSync(color)

Fill this image with a given color

fillSync(color)

src/mapnik_image.cpp

Fill this image with a given color

Parameters

#filter(filter, callback)

Asynchronously filter this image.

filter(filter, callback)

src/mapnik_image.cpp

Asynchronously filter this image.

Parameters

Examples

var im = new mapnik.Image(5, 5);
            im.filter("blur", function(err, im_res) {
              if (err) throw err;
              assert.equal(im_res.getPixel(0, 0), 1);
            });
#filterSync(filter)

Filter this image

filterSync(filter)

src/mapnik_image.cpp

Filter this image

Parameters

#getPixel(x, y, options)

getPixel(x, y, options)

src/mapnik_image.cpp

Parameters

  • number x :

    position within image from top left

  • number y :

    position within image from top left

  • Object options :

    the only valid option is get_color, which should be a boolean.

Returns

number :

color

Examples

var im = new mapnik.Image(256, 256);
            var view = im.view(0, 0, 256, 256);
            var pixel = view.getPixel(0, 0, {get_color:true});
            assert.equal(pixel.r, 0);
            assert.equal(pixel.g, 0);
            assert.equal(pixel.b, 0);
            assert.equal(pixel.a, 0);
#getType

Determine the image type

getType

src/mapnik_image.cpp

Determine the image type

Returns

number :

Number of the image type

#height

Get this image's height

height

src/mapnik_image.cpp

Get this image's height

Returns

number :

height

#isSolidSync

Determine whether the image is solid - whether it has alpha values of greater than one.

isSolidSync

src/mapnik_image.cpp

Determine whether the image is solid - whether it has alpha values of greater than one.

Returns

boolean :

whether the image is solid

Examples

var im = new mapnik.Image(256, 256);
            var view = im.view(0, 0, 256, 256);
            assert.equal(view.isSolidSync(), true);
#premultiplied

Determine whether the given image is premultiplied.

premultiplied

src/mapnik_image.cpp

Determine whether the given image is premultiplied.

Returns

boolean :

premultiplied true if the image is premultiplied

#premultiply(callback)

Premultiply the pixels in this image, asynchronously

premultiply(callback)

src/mapnik_image.cpp

Premultiply the pixels in this image, asynchronously

Parameters

#premultiplySync

Premultiply the pixels in this image

premultiplySync

src/mapnik_image.cpp

Premultiply the pixels in this image

#resize(width, height, [options], callback)

Create a copy this image that is resized

resize(width, height, [options], callback)

src/mapnik_image.cpp

Create a copy this image that is resized

Parameters

#resizeSync(width, height, [options])

Make a resized copy of an image

resizeSync(width, height, [options])

src/mapnik_image.cpp

Make a resized copy of an image

Parameters

Returns

mapnik.Image :

copy

#save(filename, [format], callback)

Encode this image and save it to disk as a file.

save(filename, [format], callback)

src/mapnik_image.cpp

Encode this image and save it to disk as a file.

Parameters

#saveSync(filename, [format])

Encode this image and save it to disk as a file.

saveSync(filename, [format])

src/mapnik_image.cpp

Encode this image and save it to disk as a file.

Parameters

Examples

myImage.saveSync('foo.png');
#setPixel(x, y, numeric)

setPixel(x, y, numeric)

src/mapnik_image.cpp

Parameters

  • number x :

    position within image from top left

  • number y :

    position within image from top left

  • Object or number numeric :

    or object representation of a color

#view(x, y, width, height)

Get a constrained view of this image given x, y, width, height parameters.

view(x, y, width, height)

src/mapnik_image.cpp

Get a constrained view of this image given x, y, width, height parameters.

Parameters

Returns

mapnik.Image :

an image constrained to this new view

#width

Get this image's width

width

src/mapnik_image.cpp

Get this image's width

Returns

number :

width

mapnik.ImageView(left, top, width, height)

src/mapnik_image_view.cpp

This is usually not initialized directly: you'll use the mapnik.Image#view method to instantiate an instance.

Parameters

Throws

  • TypeError:

    if any argument is missing or not numeric

Examples

var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);

mapnik.Map(width, width, projection)

src/mapnik_map.cpp

A map in mapnik is an object that combined data sources and styles in a way that lets you produce styled cartographic output.

Parameters

Examples

var map = new mapnik.Map(25, 25, '+init=epsg:3857');

Instance members

#add_layer(new)

Add a new layer to this map

add_layer(new)

src/mapnik_map.cpp

Add a new layer to this map

Parameters

  • mapnik.Layer new :

    layer

#clear

Remove all layers and styles from this map

clear

src/mapnik_map.cpp

Remove all layers and styles from this map

#clone

Clone this map object, returning a value which can be changed without mutating the original

clone

src/mapnik_map.cpp

Clone this map object, returning a value which can be changed without mutating the original

Returns

mapnik.Map :

clone

#font

Get all of the fonts currently registered as part of this map

font

src/mapnik_map.cpp

Get all of the fonts currently registered as part of this map

#fontDirectory

Get the currently-registered font directory, if any

fontDirectory

src/mapnik_map.cpp

Get the currently-registered font directory, if any

Returns

string or :

fonts

#fontFiles

Get all of the fonts currently registered as part of this map, as a mapping from font to font file

fontFiles

src/mapnik_map.cpp

Get all of the fonts currently registered as part of this map, as a mapping from font to font file

Returns

Object :

fonts

#fromStringSync(stylesheet, [options], callback)

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

fromStringSync(stylesheet, [options], callback)

src/mapnik_map.cpp

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

Parameters

Examples

var fs = require('fs');
            map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'), function(err, res) {
              // details loaded
            });
#fromStringSync(stylesheet, [options])

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

fromStringSync(stylesheet, [options])

src/mapnik_map.cpp

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

Parameters

  • string stylesheet :

    contents

  • [Object] options (default {}) :

Examples

var fs = require('fs');
            map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'));
#get_layer(layer)

Get a layer out of this map, given a name or index

get_layer(layer)

src/mapnik_map.cpp

Get a layer out of this map, given a name or index

Parameters

Returns

mapnik.Layer :

the layer

Throws

  • Error:

    if index is incorrect or layer is not found

#layers

Get all of the currently-added layers in this map

layers

src/mapnik_map.cpp

Get all of the currently-added layers in this map

#load(stylesheet, [options], callback)

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

load(stylesheet, [options], callback)

src/mapnik_map.cpp

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

Parameters

#loadSync(stylesheet, [options])

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

loadSync(stylesheet, [options])

src/mapnik_map.cpp

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

Parameters

Examples

map.loadSync('./style.xml');
#resize(width, height)

Give this map new dimensions

resize(width, height)

src/mapnik_map.cpp

Give this map new dimensions

Parameters

#scale

Get the map's scale factor. This is the ratio between pixels and geographical units like meters.

scale

src/mapnik_map.cpp

Get the map's scale factor. This is the ratio between pixels and geographical units like meters.

Returns

number :

scale

#scaleDenominator

Get the map's scale denominator.

scaleDenominator

src/mapnik_map.cpp

Get the map's scale denominator.

Returns

number :

scale denominator

mapnik.Projection(projection, [options])

src/mapnik_projection.cpp

A geographical projection: this class makes it possible to translate between locations in different projections

Parameters

  • string projection :

    projection as a proj4 definition string

  • [Object] options (default {lazy:false}) :

    whether to lazily instantiate the data backing this projection.

Throws

  • TypeError:

    if the projection string or options argument is the wrong type

  • Error:

    the projection could not be initialized - it was not found in proj4's tables or the string was malformed

Examples

var wgs84 = new mapnik.Projection('+init=epsg:4326');

Instance members

#forward

Project from a position in WGS84 space to a position in this projection.

forward

src/mapnik_projection.cpp

Project from a position in WGS84 space to a position in this projection.

#inverse

Unproject from a position in this projection to the same position in WGS84 space.

inverse

src/mapnik_projection.cpp

Unproject from a position in this projection to the same position in WGS84 space.

mapnik.VectorTile(z, x, y)

src/mapnik_vector_tile.cpp

A generator for the Mapbox Vector Tile specification of compressed and simplified tiled vector data

Parameters

Examples

var vtile = new mapnik.VectorTile(9,112,195);

Instance members

#addData(raw, name)

Add raw data to this tile as a Buffer

addData(raw, name)

src/mapnik_vector_tile.cpp

Add raw data to this tile as a Buffer

Parameters

#addGeoJSON(geojson, name)

Add features to this tile from a GeoJSON string

addGeoJSON(geojson, name)

src/mapnik_vector_tile.cpp

Add features to this tile from a GeoJSON string

Parameters

  • string geojson :

    as a string

  • string name :

    of the layer to be added

#clear(callback)

Remove all data from this vector tile

clear(callback)

src/mapnik_vector_tile.cpp

Remove all data from this vector tile

Parameters

#compositeSync

Composite an array of vector tiles into one vector tile

compositeSync

src/mapnik_vector_tile.cpp

Composite an array of vector tiles into one vector tile

#empty(whether)

Return whether this vector tile is empty - whether it has no layers and no features

empty(whether)

src/mapnik_vector_tile.cpp

Return whether this vector tile is empty - whether it has no layers and no features

Parameters

  • boolean whether :

    the layer is empty

#getData(map, renderable, callback)

Render this vector tile to a surface, like a mapnik.Image

getData(map, renderable, callback)

src/mapnik_vector_tile.cpp

Render this vector tile to a surface, like a mapnik.Image

Parameters

#getDataSync

Get the data in this vector tile as a buffer

getDataSync

src/mapnik_vector_tile.cpp

Get the data in this vector tile as a buffer

Returns

Buffer :

raw data

#height(height)

Get the vector tile's height

height(height)

src/mapnik_vector_tile.cpp

Get the vector tile's height

Parameters

#isSolid(callback)

Test whether this tile is solid - whether it has features

isSolid(callback)

src/mapnik_vector_tile.cpp

Test whether this tile is solid - whether it has features

Parameters

#isSolidSync

Test whether this tile is solid - whether it has features

isSolidSync

src/mapnik_vector_tile.cpp

Test whether this tile is solid - whether it has features

Returns

boolean :

whether the tile is solid

#names

Get the names of all of the layers in this vector tile

names

src/mapnik_vector_tile.cpp

Get the names of all of the layers in this vector tile

#painted(painted)

Get whether the vector tile has been painted

painted(painted)

src/mapnik_vector_tile.cpp

Get whether the vector tile has been painted

Parameters

#query(longitude, latitude, [options], callback)

Query a vector tile by longitude and latitude

query(longitude, latitude, [options], callback)

src/mapnik_vector_tile.cpp

Query a vector tile by longitude and latitude

Parameters

  • number longitude :
  • number latitude :
  • [Object] options (default {tolerance:0}) :

    tolerance: allow results that are not exactly on this longitude, latitude position.

  • Function callback :
#reportGeometrySimplicity(callback)

Count the number of non OGC simple geometries

reportGeometrySimplicity(callback)

src/mapnik_vector_tile.cpp

Count the number of non OGC simple geometries

Parameters

#reportGeometrySimplicitySync

Count the number of geometries that are not OGC simple

reportGeometrySimplicitySync

src/mapnik_vector_tile.cpp

Count the number of geometries that are not OGC simple

Returns

number :

number of features that are not simple

#reportGeometryValidity(callback)

Count the number of non OGC valid geometries

reportGeometryValidity(callback)

src/mapnik_vector_tile.cpp

Count the number of non OGC valid geometries

Parameters

#reportGeometryValiditySync

Count the number of geometries that are not OGC valid

reportGeometryValiditySync

src/mapnik_vector_tile.cpp

Count the number of geometries that are not OGC valid

Returns

number :

number of features that are not valid

#setData(raw, name)

Replace the data in this vector tile with new raw data

setData(raw, name)

src/mapnik_vector_tile.cpp

Replace the data in this vector tile with new raw data

Parameters

#toGeoJSON(callback)

Get a GeoJSON representation of this tile

toGeoJSON(callback)

src/mapnik_vector_tile.cpp

Get a GeoJSON representation of this tile

Parameters

Returns

string :

stringified GeoJSON of all the features in this tile.

#toGeoJSONSync

Get a GeoJSON representation of this tile

toGeoJSONSync

src/mapnik_vector_tile.cpp

Get a GeoJSON representation of this tile

Returns

string :

stringified GeoJSON of all the features in this tile.

#toJSON

Get a JSON representation of this tile

toJSON

src/mapnik_vector_tile.cpp

Get a JSON representation of this tile

Returns

Object :

json representation of this tile with name, extent, and version properties

#width(width)

Get the vector tile's width

width(width)

src/mapnik_vector_tile.cpp

Get the vector tile's width

Parameters

mapnik.blend

src/blend.cpp

Composite multiple images on top of each other, with strong control over how the images are combined, resampled, and blended.