Package mapnik

Package mapnik

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.

Submodules

Classes
  Envelope
  PythonDatasource
A base class for a Python data source.
  Box2d
Represents a spatial envelope (i.e.
  Color
  Coord
Represents a point with two coordinates (either lon/lat or x/y).
  ProcessedText
  Projection
Represents a map projection.
  Symbolizers
  TextSymbolizer
Functions
 
bootstrap_env()
If an optional settings file exists, inherit its environment settings before loading the mapnik library.
 
Filter(*args, **kwargs)
 
Datasource(**keywords)
Wrapper around CreateDatasource.
 
Shapefile(**keywords)
Create a Shapefile Datasource.
 
PostGIS(**keywords)
Create a PostGIS Datasource.
 
Raster(**keywords)
Create a Raster (Tiff) Datasource.
 
Gdal(**keywords)
Create a GDAL Raster Datasource.
 
Occi(**keywords)
Create a Oracle Spatial (10g) Vector Datasource.
 
Ogr(**keywords)
Create a OGR Vector Datasource.
 
SQLite(**keywords)
Create a SQLite Datasource.
 
Rasterlite(**keywords)
Create a Rasterlite Datasource.
 
Osm(**keywords)
Create a Osm Datasource.
 
Kismet(**keywords)
Create a Kismet Datasource.
 
Geos(**keywords)
Create a GEOS Vector Datasource.
 
Python(**keywords)
Create a Python Datasource.
 
mapnik_version_from_string(version_string)
Return the Mapnik version from a string.
 
register_plugins(path='/usr/local/lib/mapnik/input')
Register plugins located by specified path
 
register_fonts(path='/usr/local/lib/mapnik/fonts', valid_extensions=['.ttf', '.otf', '.ttc', '.pfa', '.pfb', '.ttc', '.dfont'])
Recursively register fonts using path argument as base directory
Variables
  COLORIZER_DISCRETE = mapnik._mapnik.ColorizerMode.COLORIZER_DI...
  COLORIZER_EXACT = mapnik._mapnik.ColorizerMode.COLORIZER_EXACT
  COLORIZER_INHERIT = mapnik._mapnik.ColorizerMode.COLORIZER_INH...
  COLORIZER_LINEAR = mapnik._mapnik.ColorizerMode.COLORIZER_LINEAR
  __package__ = 'mapnik'
Function Details

bootstrap_env()

 

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/'}

Datasource(**keywords)

 
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.

Shapefile(**keywords)

 
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

PostGIS(**keywords)

 
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 -- portgres 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='mapnik',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

Raster(**keywords)

 
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

Gdal(**keywords)

 
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

Occi(**keywords)

 
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

Ogr(**keywords)

 
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

SQLite(**keywords)

 
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 auxillary 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

Rasterlite(**keywords)

 
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

Osm(**keywords)

 
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

Kismet(**keywords)

 
Create a Kismet Datasource.

Required keyword arguments:
  host -- kismet hostname
  port -- kismet port

Optional keyword arguments:
  encoding -- file encoding (default 'utf-8')
  extent -- manually specified data extent (comma delimited string, default None)

>>> from mapnik import Kismet, Layer
>>> datasource = Kismet(host='localhost',port=2501,extent='-179,-85,179,85') 
>>> lyr = Layer('Kismet Server Layer')
>>> lyr.datasource = datasource

Geos(**keywords)

 
Create a GEOS Vector Datasource.

Required keyword arguments:
  wkt -- inline WKT text of the geometry

Optional keyword arguments:
  extent -- manually specified data extent (comma delimited string, default None)

>>> from mapnik import Geos, Layer
>>> datasource = Geos(wkt='MULTIPOINT(100 100, 50 50, 0 0)') 
>>> lyr = Layer('GEOS Layer from WKT string')
>>> lyr.datasource = datasource

Python(**keywords)

 

Create a Python Datasource.

>>> from mapnik import Python, PythonDatasource
>>> datasource = Python('PythonDataSource')
>>> lyr = Layer('Python datasource')
>>> lyr.datasource = datasource

Variables Details

COLORIZER_DISCRETE

Value:
mapnik._mapnik.ColorizerMode.COLORIZER_DISCRETE

COLORIZER_INHERIT

Value:
mapnik._mapnik.ColorizerMode.COLORIZER_INHERIT