mapnik

Submodules

Module contents

Mapnik Python module.

Boost Python bindings to the Mapnik C++ shared library.

Several things happen when you do:

>>> import mapnik
  1. Mapnik C++ objects are imported via the ‘__init__.py’ from the ‘_mapnik.so’ shared object (_mapnik.pyd on win) which references libmapnik.so (linux), libmapnik.dylib (mac), or mapnik.dll (win32).

  2. The paths to the input plugins and font directories are imported from the ‘paths.py’ file which was constructed and installed during SCons installation.

  3. All available input plugins and TrueType fonts are automatically registered.

  4. Boost Python metaclass injectors are used in the ‘__init__.py’ to extend several objects adding extra convenience when accessed via Python.

mapnik.bootstrap_env()[source]

If an optional settings file exists, inherit its environment settings before loading the mapnik library.

This feature is intended for customized packages of mapnik.

The settings file should be a python file with an ‘env’ variable that declares a dictionary of key:value pairs to push into the global process environment, if not already set, like:

env = {‘ICU_DATA’:’/usr/local/share/icu/’}

mapnik.Filter(*args, **kwargs)[source]
class mapnik.Envelope(*args, **kwargs)[source]

Bases: mapnik._Box2d

class mapnik._Coord[source]

Bases: mapnik._Coord, mapnik._Coord

Represents a point with two coordinates (either lon/lat or x/y).

Following operators are defined for Coord:

Addition and subtraction of Coord objects:

>>> Coord(10, 10) + Coord(20, 20)
Coord(30.0, 30.0)
>>> Coord(10, 10) - Coord(20, 20)
Coord(-10.0, -10.0)

Addition, subtraction, multiplication and division between a Coord and a float:

>>> Coord(10, 10) + 1
Coord(11.0, 11.0)
>>> Coord(10, 10) - 1
Coord(-9.0, -9.0)
>>> Coord(10, 10) * 2
Coord(20.0, 20.0)
>>> Coord(10, 10) / 2
Coord(5.0, 5.0)

Equality of coords (as pairwise equality of components): >>> Coord(10, 10) is Coord(10, 10) False >>> Coord(10, 10) == Coord(10, 10) True

forward(projection)[source]

Projects the point from the geographic coordinate space into the cartesian space. The x component is considered to be longitude, the y component the latitude.

Returns the easting (x) and northing (y) as a coordinate pair.

Example: Project the geographic coordinates of the

city center of Stuttgart into the local map projection (GK Zone 3/DHDN, EPSG 31467)

>>> p = Projection('+init=epsg:31467')
>>> Coord(9.1, 48.7).forward(p)
Coord(3507360.12813,5395719.2749)
inverse(projection)[source]

Projects the point from the cartesian space into the geographic space. The x component is considered to be the easting, the y component to be the northing.

Returns the longitude (x) and latitude (y) as a coordinate pair.

Example: Project the cartesian coordinates of the

city center of Stuttgart in the local map projection (GK Zone 3/DHDN, EPSG 31467) into geographic coordinates:

>>> p = Projection('+init=epsg:31467')
>>> Coord(3507360.12813,5395719.2749).inverse(p)
Coord(9.1, 48.7)
class mapnik._Box2d[source]

Bases: mapnik._Box2d, mapnik._Box2d

Represents a spatial envelope (i.e. bounding box).

Following operators are defined for Box2d:

Addition: e1 + e2 is equivalent to e1.expand_to_include(e2) but yields a new envelope instead of modifying e1

Subtraction: Currently e1 - e2 returns e1.

Multiplication and division with floats: Multiplication and division change the width and height of the envelope by the given factor without modifying its center..

That is, e1 * x is equivalent to:

e1.width(x * e1.width()) e1.height(x * e1.height()),

except that a new envelope is created instead of modifying e1.

e1 / x is equivalent to e1 * (1.0/x).

Equality: two envelopes are equal if their corner points are equal.

forward(projection)[source]

Projects the envelope from the geographic space into the cartesian space by projecting its corner points.

See also

Coord.forward(self, projection)

inverse(projection)[source]

Projects the envelope from the cartesian space into the geographic space by projecting its corner points.

See also

Coord.inverse(self, projection).

mapnik.Datasource(**keywords)[source]

Wrapper around CreateDatasource.

Create a Mapnik Datasource using a dictionary of parameters.

Keywords must include:

type=’plugin_name’ # e.g. type=’gdal’

See the convenience factory methods of each input plugin for details on additional required keyword arguments.

mapnik.Shapefile(**keywords)[source]

Create a Shapefile Datasource.

Required keyword arguments:

file – path to shapefile without extension

Optional keyword arguments:

base – path prefix (default None) encoding – file encoding (default ‘utf-8’)

>>> from mapnik import Shapefile, Layer
>>> shp = Shapefile(base='/home/mapnik/data',file='world_borders')
>>> lyr = Layer('Shapefile Layer')
>>> lyr.datasource = shp
mapnik.CSV(**keywords)[source]

Create a CSV Datasource.

Required keyword arguments:

file – path to csv

Optional keyword arguments:
inline – inline CSV string (if provided ‘file’ argument will be ignored

and non-needed)

base – path prefix (default None) encoding – file encoding (default ‘utf-8’) row_limit – integer limit of rows to return (default: 0) strict – throw an error if an invalid row is encountered escape – The escape character to use for parsing data quote – The quote character to use for parsing data separator – The separator character to use for parsing data headers – A comma separated list of header names that can be set to add headers

to data that lacks them

filesize_max – The maximum filesize in MB that will be accepted

>>> from mapnik import CSV
>>> csv = CSV(file='test.csv')
>>> from mapnik import CSV
>>> csv = CSV(inline='''wkt,Name

“POINT (120.15 48.47)”,”Winthrop, WA”’’’)

mapnik.GeoJSON(**keywords)[source]

Create a GeoJSON Datasource.

Required keyword arguments:

file – path to json

Optional keyword arguments:

encoding – file encoding (default ‘utf-8’) base – path prefix (default None)

>>> from mapnik import GeoJSON
>>> geojson = GeoJSON(file='test.json')
mapnik.PostGIS(**keywords)[source]

Create a PostGIS Datasource.

Required keyword arguments:

dbname – database name to connect to table – table name or subselect query

*Note: if using subselects for the ‘table’ value consider also

passing the ‘geometry_field’ and ‘srid’ and ‘extent_from_subquery’ options and/or specifying the ‘geometry_table’ option.

Optional db connection keyword arguments:

user – database user to connect as (default: see postgres docs) password – password for database user (default: see postgres docs) host – postgres hostname (default: see postgres docs) port – postgres port (default: see postgres docs) initial_size – integer size of connection pool (default: 1) max_size – integer max of connection pool (default: 10) persist_connection – keep connection open (default: True)

Optional table-level keyword arguments:

extent – manually specified data extent (comma delimited string, default: None) estimate_extent – boolean, direct PostGIS to use the faster, less accurate

estimate_extent over extent (default: False)

extent_from_subquery – boolean, direct Mapnik to query Postgis for the extent

of the raw ‘table’ value (default: uses ‘geometry_table’)

geometry_table – specify geometry table to use to look up metadata

(default: automatically parsed from ‘table’ value)

geometry_field – specify geometry field to use (default: first entry in

geometry_columns)

srid – specify srid to use (default: auto-detected from geometry_field) row_limit – integer limit of rows to return (default: 0) cursor_size – integer size of binary cursor to use (default: 0, no binary

cursor is used)

>>> from mapnik import PostGIS, Layer
>>> params = dict(
        dbname=env['MAPNIK_NAME'],table='osm',user='postgres',password='gis')
>>> params['estimate_extent'] = False
>>> params['extent'] = '-20037508,-19929239,20037508,19929239'
>>> postgis = PostGIS(**params)
>>> lyr = Layer('PostGIS Layer')
>>> lyr.datasource = postgis
mapnik.PgRaster(**keywords)[source]

Create a PgRaster Datasource.

Required keyword arguments:

dbname – database name to connect to table – table name or subselect query

*Note: if using subselects for the ‘table’ value consider also

passing the ‘raster_field’ and ‘srid’ and ‘extent_from_subquery’ options and/or specifying the ‘raster_table’ option.

Optional db connection keyword arguments:

user – database user to connect as (default: see postgres docs) password – password for database user (default: see postgres docs) host – postgres hostname (default: see postgres docs) port – postgres port (default: see postgres docs) initial_size – integer size of connection pool (default: 1) max_size – integer max of connection pool (default: 10) persist_connection – keep connection open (default: True)

Optional table-level keyword arguments:

extent – manually specified data extent (comma delimited string, default: None) estimate_extent – boolean, direct PostGIS to use the faster, less accurate

estimate_extent over extent (default: False)

extent_from_subquery – boolean, direct Mapnik to query Postgis for the extent of

the raw ‘table’ value (default: uses ‘geometry_table’)

raster_table – specify geometry table to use to look up metadata

(default: automatically parsed from ‘table’ value)

raster_field – specify geometry field to use (default: first entry in raster_columns) srid – specify srid to use (default: auto-detected from geometry_field) row_limit – integer limit of rows to return (default: 0) cursor_size – integer size of binary cursor to use (default: 0, no binary cursor is used) use_overviews – boolean, use overviews when available (default: false) prescale_rasters – boolean, scale rasters on the db side (default: false) clip_rasters – boolean, clip rasters on the db side (default: false) band – integer, if non-zero interprets the given band (1-based offset) as a data raster (default: 0)

>>> from mapnik import PgRaster, Layer
>>> params = dict(dbname='mapnik',table='osm',user='postgres',password='gis')
>>> params['estimate_extent'] = False
>>> params['extent'] = '-20037508,-19929239,20037508,19929239'
>>> pgraster = PgRaster(**params)
>>> lyr = Layer('PgRaster Layer')
>>> lyr.datasource = pgraster
mapnik.Raster(**keywords)[source]

Create a Raster (Tiff) Datasource.

Required keyword arguments:

file – path to stripped or tiled tiff lox – lowest (min) x/longitude of tiff extent loy – lowest (min) y/latitude of tiff extent hix – highest (max) x/longitude of tiff extent hiy – highest (max) y/latitude of tiff extent

Hint: lox,loy,hix,hiy make a Mapnik Box2d

Optional keyword arguments:

base – path prefix (default None) multi – whether the image is in tiles on disk (default False)

Multi-tiled keyword arguments:

x_width – virtual image number of tiles in X direction (required) y_width – virtual image number of tiles in Y direction (required) tile_size – if an image is in tiles, how large are the tiles (default 256) tile_stride – if an image is in tiles, what’s the increment between rows/cols (default 1)

>>> from mapnik import Raster, Layer
>>> raster = Raster(base='/home/mapnik/data',file='elevation.tif',lox=-122.8,loy=48.5,hix=-122.7,hiy=48.6)
>>> lyr = Layer('Tiff Layer')
>>> lyr.datasource = raster
mapnik.Gdal(**keywords)[source]

Create a GDAL Raster Datasource.

Required keyword arguments:

file – path to GDAL supported dataset

Optional keyword arguments:

base – path prefix (default None) shared – boolean, open GdalDataset in shared mode (default: False) bbox – tuple (minx, miny, maxx, maxy). If specified, overrides the bbox detected by GDAL.

>>> from mapnik import Gdal, Layer
>>> dataset = Gdal(base='/home/mapnik/data',file='elevation.tif')
>>> lyr = Layer('GDAL Layer from TIFF file')
>>> lyr.datasource = dataset
mapnik.Occi(**keywords)[source]

Create a Oracle Spatial (10g) Vector Datasource.

Required keyword arguments:

user – database user to connect as password – password for database user host – oracle host to connect to (does not refer to SID in tsnames.ora) table – table name or subselect query

Optional keyword arguments:

initial_size – integer size of connection pool (default 1) max_size – integer max of connection pool (default 10) extent – manually specified data extent (comma delimited string, default None) estimate_extent – boolean, direct Oracle to use the faster, less accurate estimate_extent() over extent() (default False) encoding – file encoding (default ‘utf-8’) geometry_field – specify geometry field (default ‘GEOLOC’) use_spatial_index – boolean, force the use of the spatial index (default True)

>>> from mapnik import Occi, Layer
>>> params = dict(host='myoracle',user='scott',password='tiger',table='test')
>>> params['estimate_extent'] = False
>>> params['extent'] = '-20037508,-19929239,20037508,19929239'
>>> oracle = Occi(**params)
>>> lyr = Layer('Oracle Spatial Layer')
>>> lyr.datasource = oracle
mapnik.Ogr(**keywords)[source]

Create a OGR Vector Datasource.

Required keyword arguments:

file – path to OGR supported dataset layer – name of layer to use within datasource (optional if layer_by_index or layer_by_sql is used)

Optional keyword arguments:

layer_by_index – choose layer by index number instead of by layer name or sql. layer_by_sql – choose layer by sql query number instead of by layer name or index. base – path prefix (default None) encoding – file encoding (default ‘utf-8’)

>>> from mapnik import Ogr, Layer
>>> datasource = Ogr(base='/home/mapnik/data',file='rivers.geojson',layer='OGRGeoJSON')
>>> lyr = Layer('OGR Layer from GeoJSON file')
>>> lyr.datasource = datasource
mapnik.SQLite(**keywords)[source]

Create a SQLite Datasource.

Required keyword arguments:

file – path to SQLite database file table – table name or subselect query

Optional keyword arguments:

base – path prefix (default None) encoding – file encoding (default ‘utf-8’) extent – manually specified data extent (comma delimited string, default None) metadata – name of auxiliary table containing record for table with xmin, ymin, xmax, ymax, and f_table_name geometry_field – name of geometry field (default ‘the_geom’) key_field – name of primary key field (default ‘OGC_FID’) row_offset – specify a custom integer row offset (default 0) row_limit – specify a custom integer row limit (default 0) wkb_format – specify a wkb type of ‘spatialite’ (default None) use_spatial_index – boolean, instruct sqlite plugin to use Rtree spatial index (default True)

>>> from mapnik import SQLite, Layer
>>> sqlite = SQLite(base='/home/mapnik/data',file='osm.db',table='osm',extent='-20037508,-19929239,20037508,19929239')
>>> lyr = Layer('SQLite Layer')
>>> lyr.datasource = sqlite
mapnik.Rasterlite(**keywords)[source]

Create a Rasterlite Datasource.

Required keyword arguments:

file – path to Rasterlite database file table – table name or subselect query

Optional keyword arguments:

base – path prefix (default None) extent – manually specified data extent (comma delimited string, default None)

>>> from mapnik import Rasterlite, Layer
>>> rasterlite = Rasterlite(base='/home/mapnik/data',file='osm.db',table='osm',extent='-20037508,-19929239,20037508,19929239')
>>> lyr = Layer('Rasterlite Layer')
>>> lyr.datasource = rasterlite
mapnik.Osm(**keywords)[source]

Create a Osm Datasource.

Required keyword arguments:

file – path to OSM file

Optional keyword arguments:

encoding – file encoding (default ‘utf-8’) url – url to fetch data (default None) bbox – data bounding box for fetching data (default None)

>>> from mapnik import Osm, Layer
>>> datasource = Osm(file='test.osm')
>>> lyr = Layer('Osm Layer')
>>> lyr.datasource = datasource
mapnik.Python(**keywords)[source]

Create a Python Datasource.

>>> from mapnik import Python, PythonDatasource
>>> datasource = Python('PythonDataSource')
>>> lyr = Layer('Python datasource')
>>> lyr.datasource = datasource
mapnik.MemoryDatasource(**keywords)[source]

Create a Memory Datasource.

Optional keyword arguments:

(TODO)

class mapnik.PythonDatasource(envelope=None, geometry_type=None, data_type=None)[source]

Bases: object

A base class for a Python data source.

Optional arguments:

envelope – a mapnik.Box2d (minx, miny, maxx, maxy) envelope of the data source, default (-180,-90,180,90) geometry_type – one of the DataGeometryType enumeration values, default Point data_type – one of the DataType enumerations, default Vector

features(query)[source]

Return an iterable which yields instances of Feature for features within the passed query.

Required arguments:

query – a Query instance specifying the region for which features should be returned

features_at_point(point)[source]

Rarely used. Return an iterable which yields instances of Feature for the specified point.

classmethod wkb_features(keys, features)[source]

A convenience function to wrap an iterator yielding pairs of WKB format geometry and dictionaries of key-value pairs into mapnik features. Return this from PythonDatasource.features() passing it a sequence of keys to appear in the output and an iterator yielding features.

For example. One might have a features() method in a derived class like the following:

def features(self, query):

# … create WKB features feat1 and feat2

return mapnik.PythonDatasource.wkb_features(

keys = ( ‘name’, ‘author’ ), features = [

(feat1, { ‘name’: ‘feat1’, ‘author’: ‘alice’ }), (feat2, { ‘name’: ‘feat2’, ‘author’: ‘bob’ }),

]

)

classmethod wkt_features(keys, features)[source]

A convenience function to wrap an iterator yielding pairs of WKT format geometry and dictionaries of key-value pairs into mapnik features. Return this from PythonDatasource.features() passing it a sequence of keys to appear in the output and an iterator yielding features.

For example. One might have a features() method in a derived class like the following:

def features(self, query):

# … create WKT features feat1 and feat2

return mapnik.PythonDatasource.wkt_features(

keys = ( ‘name’, ‘author’ ), features = [

(feat1, { ‘name’: ‘feat1’, ‘author’: ‘alice’ }), (feat2, { ‘name’: ‘feat2’, ‘author’: ‘bob’ }),

]

)

class mapnik.Box2d

Bases: Boost.Python.instance

Represents a spatial envelope (i.e. bounding box).

Following operators are defined for Box2d:

Addition: e1 + e2 is equivalent to e1.expand_to_include(e2) but yields a new envelope instead of modifying e1

Subtraction: Currently e1 - e2 returns e1.

Multiplication and division with floats: Multiplication and division change the width and height of the envelope by the given factor without modifying its center..

That is, e1 * x is equivalent to:

e1.width(x * e1.width()) e1.height(x * e1.height()),

except that a new envelope is created instead of modifying e1.

e1 / x is equivalent to e1 * (1.0/x).

Equality: two envelopes are equal if their corner points are equal.

center((Box2d)arg1) Coord :

Returns the coordinates of the center of the bounding box.

Example: >>> e = Box2d(0, 0, 100, 100) >>> e.center() Coord(50, 50)

C++ signature :

mapnik::coord<double, 2> center(mapnik::box2d<double> {lvalue})

center( (Box2d)arg1, (float)x, (float)y) -> None :

Moves the envelope so that the given coordinates become its new center. The width and the height are preserved.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> e.center(60, 60)
>>> e.center()
Coord(60.0,60.0)
>>> (e.width(), e.height())
(100.0, 100.0)
>>> e
Box2d(10.0, 10.0, 110.0, 110.0)
C++ signature :

void center(mapnik::box2d<double> {lvalue},double,double)

center( (Box2d)arg1, (Coord)Coord) -> None :

Moves the envelope so that the given coordinates become its new center. The width and the height are preserved.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> e.center(Coord60, 60)
>>> e.center()
Coord(60.0,60.0)
>>> (e.width(), e.height())
(100.0, 100.0)
>>> e
Box2d(10.0, 10.0, 110.0, 110.0)
C++ signature :

void center(mapnik::box2d<double> {lvalue},mapnik::coord<double, 2>)

clip((Box2d)arg1, (Box2d)other) None :

Clip the envelope based on the bounds of another envelope.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> c = Box2d(-50, -50, 50, 50)
>>> e.clip(c)
>>> e
Box2d(0.0,0.0,50.0,50.0
C++ signature :

void clip(mapnik::box2d<double> {lvalue},mapnik::box2d<double>)

contains((Box2d)arg1, (float)x, (float)y) bool :
Returns True iff this envelope contains the point

given by x and y.

C++ signature :

bool contains(mapnik::box2d<double> {lvalue},double,double)

contains( (Box2d)arg1, (Coord)p) -> bool :

Equivalent to contains(p.x, p.y)

C++ signature :

bool contains(mapnik::box2d<double> {lvalue},mapnik::coord<double, 2>)

contains( (Box2d)arg1, (Box2d)other) -> bool :
Equivalent to:

contains(other.minx, other.miny) and contains(other.maxx, other.maxy)

C++ signature :

bool contains(mapnik::box2d<double> {lvalue},mapnik::box2d<double>)

expand_to_include((Box2d)arg1, (float)x, (float)y) None :

Expands this envelope to include the point given by x and y.

Example:

C++ signature :

void expand_to_include(mapnik::box2d<double> {lvalue},double,double)

expand_to_include( (Box2d)arg1, (Coord)p) -> None :

Equivalent to expand_to_include(p.x, p.y)

C++ signature :

void expand_to_include(mapnik::box2d<double> {lvalue},mapnik::coord<double, 2>)

expand_to_include( (Box2d)arg1, (Box2d)other) -> None :
Equivalent to:

expand_to_include(other.minx, other.miny) expand_to_include(other.maxx, other.maxy)

C++ signature :

void expand_to_include(mapnik::box2d<double> {lvalue},mapnik::box2d<double>)

forward(projection)

Projects the envelope from the geographic space into the cartesian space by projecting its corner points.

See also

Coord.forward(self, projection)

static from_string((str)arg1) Box2d :
C++ signature :

mapnik::box2d<double> from_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

height((Box2d)arg1, (float)new_height) None :

Sets the height to new_height of the envelope preserving its center.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> e.height(120)
>>> e.center()
Coord(50.0,50.0)
>>> e
Box2d(0.0, -10.0, 100.0, 110.0)
C++ signature :

void height(mapnik::box2d<double> {lvalue},double)

height( (Box2d)arg1) -> float :

Returns the height of this envelope.

C++ signature :

double height(mapnik::box2d<double> {lvalue})

intersect((Box2d)arg1, (Box2d)other) Box2d :

Returns the overlap of this envelope and the other envelope as a new envelope.

Example: >>> e1 = Box2d(0, 0, 100, 100) >>> e2 = Box2d(50, 50, 150, 150) >>> e1.intersect(e2) Box2d(50.0, 50.0, 100.0, 100.0)

C++ signature :

mapnik::box2d<double> intersect(mapnik::box2d<double> {lvalue},mapnik::box2d<double>)

intersects((Box2d)arg1, (float)x, (float)y) bool :
Returns True iff this envelope intersects the point

given by x and y.

Note: For points, intersection is equivalent to containment, i.e. the following holds:

e.contains(x, y) == e.intersects(x, y)

C++ signature :

bool intersects(mapnik::box2d<double> {lvalue},double,double)

intersects( (Box2d)arg1, (Coord)p) -> bool :

Equivalent to contains(p.x, p.y)

C++ signature :

bool intersects(mapnik::box2d<double> {lvalue},mapnik::coord<double, 2>)

intersects( (Box2d)arg1, (Box2d)other) -> bool :

Returns True iff this envelope intersects the other envelope, This relationship is symmetric. Example: >>> e1 = Box2d(0, 0, 100, 100) >>> e2 = Box2d(50, 50, 150, 150) >>> e1.intersects(e2) True >>> e1.contains(e2) False

C++ signature :

bool intersects(mapnik::box2d<double> {lvalue},mapnik::box2d<double>)

inverse(projection)

Projects the envelope from the cartesian space into the geographic space by projecting its corner points.

See also

Coord.inverse(self, projection).

property maxx

X coordinate for the upper right corner

property maxy

Y coordinate for the upper right corner

property minx

X coordinate for the lower left corner

property miny

Y coordinate for the lower left corner

pad((Box2d)arg1, (float)padding) None :

Pad the envelope based on a padding value.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> e.pad(10)
>>> e
Box2d(-10.0,-10.0,110.0,110.0
C++ signature :

void pad(mapnik::box2d<double> {lvalue},double)

valid((Box2d)arg1) bool :
C++ signature :

bool valid(mapnik::box2d<double> {lvalue})

width((Box2d)arg1, (float)new_width) None :

Sets the width to new_width of the envelope preserving its center.

Example:

>>> e = Box2d(0, 0, 100, 100)
>>> e.width(120)
>>> e.center()
Coord(50.0,50.0)
>>> e
Box2d(-10.0, 0.0, 110.0, 100.0)
C++ signature :

void width(mapnik::box2d<double> {lvalue},double)

width( (Box2d)arg1) -> float :

Returns the width of this envelope.

C++ signature :

double width(mapnik::box2d<double> {lvalue})

class mapnik.Color

Bases: Boost.Python.instance

property a

Gets or sets the alpha component. The value is between 0 and 255.

property b

Gets or sets the blue component. The value is between 0 and 255.

demultiply((Color)arg1) bool :
C++ signature :

bool demultiply(mapnik::color {lvalue})

property g

Gets or sets the green component. The value is between 0 and 255.

get_premultiplied((Color)arg1) bool :
C++ signature :

bool get_premultiplied(mapnik::color {lvalue})

packed((Color)arg1) int :
C++ signature :

unsigned int packed(mapnik::color {lvalue})

premultiply((Color)arg1) bool :
C++ signature :

bool premultiply(mapnik::color {lvalue})

property r

Gets or sets the red component. The value is between 0 and 255.

set_premultiplied((Color)arg1, (bool)arg2) None :
C++ signature :

void set_premultiplied(mapnik::color {lvalue},bool)

to_hex_string((Color)arg1) str :

Returns the hexadecimal representation of this color.

Example: >>> c = Color(‘blue’) >>> c.to_hex_string() ‘#0000ff’

C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > to_hex_string(mapnik::color {lvalue})

class mapnik.Coord

Bases: Boost.Python.instance

Represents a point with two coordinates (either lon/lat or x/y).

Following operators are defined for Coord:

Addition and subtraction of Coord objects:

>>> Coord(10, 10) + Coord(20, 20)
Coord(30.0, 30.0)
>>> Coord(10, 10) - Coord(20, 20)
Coord(-10.0, -10.0)

Addition, subtraction, multiplication and division between a Coord and a float:

>>> Coord(10, 10) + 1
Coord(11.0, 11.0)
>>> Coord(10, 10) - 1
Coord(-9.0, -9.0)
>>> Coord(10, 10) * 2
Coord(20.0, 20.0)
>>> Coord(10, 10) / 2
Coord(5.0, 5.0)

Equality of coords (as pairwise equality of components): >>> Coord(10, 10) is Coord(10, 10) False >>> Coord(10, 10) == Coord(10, 10) True

forward(projection)

Projects the point from the geographic coordinate space into the cartesian space. The x component is considered to be longitude, the y component the latitude.

Returns the easting (x) and northing (y) as a coordinate pair.

Example: Project the geographic coordinates of the

city center of Stuttgart into the local map projection (GK Zone 3/DHDN, EPSG 31467)

>>> p = Projection('+init=epsg:31467')
>>> Coord(9.1, 48.7).forward(p)
Coord(3507360.12813,5395719.2749)
inverse(projection)

Projects the point from the cartesian space into the geographic space. The x component is considered to be the easting, the y component to be the northing.

Returns the longitude (x) and latitude (y) as a coordinate pair.

Example: Project the cartesian coordinates of the

city center of Stuttgart in the local map projection (GK Zone 3/DHDN, EPSG 31467) into geographic coordinates:

>>> p = Projection('+init=epsg:31467')
>>> Coord(3507360.12813,5395719.2749).inverse(p)
Coord(9.1, 48.7)
property x

Gets or sets the x/lon coordinate of the point.

property y

Gets or sets the y/lat coordinate of the point.

class mapnik.Feature

Bases: Boost.Python.instance

property attributes
context((Feature)arg1) Context :
C++ signature :

std::shared_ptr<mapnik::context<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned long, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, unsigned long> > > > > context(mapnik::feature_impl {lvalue})

envelope((Feature)arg1) Box2d :
C++ signature :

mapnik::box2d<double> envelope(mapnik::feature_impl {lvalue})

static from_geojson((str)arg1, (Context)arg2) Feature :
C++ signature :

std::shared_ptr<mapnik::feature_impl> from_geojson(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >,std::shared_ptr<mapnik::context<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned long, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, unsigned long> > > > >)

property geometry
has_key((Feature)arg1, (str)arg2) bool :
C++ signature :

bool has_key(mapnik::feature_impl {lvalue},std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

id((Feature)arg1) int :
C++ signature :

long id(mapnik::feature_impl {lvalue})

to_geojson((Feature)arg1) str :
C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > to_geojson(mapnik::feature_impl)

class mapnik.Geometry

Bases: Boost.Python.instance

centroid((Geometry)arg1) Point :
C++ signature :

mapnik::geometry::point<double> centroid(mapnik::geometry::geometry<double>)

correct((Geometry)arg1) None :
C++ signature :

void correct(mapnik::geometry::geometry<double> {lvalue})

envelope((Geometry)arg1) Box2d :
C++ signature :

mapnik::box2d<double> envelope(mapnik::geometry::geometry<double>)

static from_geojson((str)arg1) Geometry :
C++ signature :

std::shared_ptr<mapnik::geometry::geometry<double> > from_geojson(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

static from_wkb((str)arg1) Geometry :
C++ signature :

std::shared_ptr<mapnik::geometry::geometry<double> > from_wkb(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

static from_wkt((str)arg1) Geometry :
C++ signature :

std::shared_ptr<mapnik::geometry::geometry<double> > from_wkt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)

is_empty((Geometry)arg1) bool :
C++ signature :

bool is_empty(mapnik::geometry::geometry<double>)

is_simple((Geometry)arg1) bool :
C++ signature :

bool is_simple(mapnik::geometry::geometry<double>)

is_valid((Geometry)arg1) bool :
C++ signature :

bool is_valid(mapnik::geometry::geometry<double>)

to_geojson((Geometry)arg1) str :
C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > to_geojson(mapnik::geometry::geometry<double>)

to_wkb((Geometry)arg1, (wkbByteOrder)arg2) object :
C++ signature :

_object* to_wkb(mapnik::geometry::geometry<double>,mapnik::wkbByteOrder)

to_wkt((Geometry)arg1) str :
C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > to_wkt(mapnik::geometry::geometry<double>)

type((Geometry)arg1) GeometryType :
C++ signature :

mapnik::geometry::geometry_types type(mapnik::geometry::geometry<double>)

class mapnik.Projection

Bases: Boost.Python.instance

Represents a map projection.

expanded((Projection)arg1) str :

normalize PROJ.4 definition by expanding +init= syntax

C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > expanded(mapnik::projection {lvalue})

forward(obj)

Projects the given object (Box2d or Coord) from the geographic space into the cartesian space.

See also

Box2d.forward(self, projection), Coord.forward(self, projection).

property geographic

This property is True if the projection is a geographic projection (i.e. it uses lon/lat coordinates)

inverse(obj)

Projects the given object (Box2d or Coord) from the cartesian space into the geographic space.

See also

Box2d.inverse(self, projection), Coord.inverse(self, projection).

params((Projection)arg1) str :

Returns the PROJ.4 string for this projection.

C++ signature :

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > params(mapnik::projection {lvalue})

class mapnik.SymbolizerBase

Bases: Boost.Python.instance

property filename
class mapnik.TextSymbolizer

Bases: mapnik._SymbolizerBase

property allow_overlap
property avoid_edges
property character_spacing
property displacement
property face_name
property fill
property fontset
property halo_fill
property halo_radius
property horizontal_alignment
property justify_alignment
property label_placement
property label_position_tolerance
property label_spacing
property line_spacing
property maximum_angle_char_delta
property minimum_distance
property minimum_padding
property minimum_path_length
property name
property orientation
symbol()
property text_opacity
property text_ratio
property text_size
property text_transform
property vertical_alignment
property wrap_before
property wrap_width
mapnik.mapnik_version_from_string(version_string)[source]

Return the Mapnik version from a string.

mapnik.register_plugins(path=None)[source]

Register plugins located by specified path

mapnik.register_fonts(path=None, valid_extensions=['.ttf', '.otf', '.ttc', '.pfa', '.pfb', '.ttc', '.dfont', '.woff'])[source]

Recursively register fonts using path argument as base directory