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
    which references libmapnik.so (linux), libmapnik.dylib (mac), or libmapnik.dll (win).
    
 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 wrap/extend several
    objects adding extra convenience when accessed via Python.

Note: besides those objects modified by boost metaclass injection all class objects
are only accessible by various documentation viewers via the 'mapnik._mapnik' module.

Submodules

Classes
  Coord
  Envelope
A spatial envelope (i.e.
  Feature
  Projection
Functions
 
get_types(num)
 
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.
 
Osm(**keywords)
Create a Osm Datasource.
 
Kismet(**keywords)
Create a Kismet Datasource.
 
mapnik_version_string()
Return the Mapnik version as a string.
 
CreateDatasource(...)
CreateDatasource( (dict)arg1) -> Datasource :
 
Describe(...)
Describe( (Datasource)arg1) -> str :
 
Filter(...)
Filter( (str)arg1) -> Filter :
 
forward_(...)
forward_( (Coord)arg1, (Projection)arg2) -> Coord :
bool :
has_cairo()
Get cairo library status
 
inverse_(...)
inverse_( (Coord)arg1, (Projection)arg2) -> Coord :
 
load_map(...)
load_map( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :
 
load_map_from_string(...)
load_map_from_string( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :
int :
mapnik_version()
Get the Mapnik version number
 
render(...)
render( (Map)arg1, (Image)arg2, (int)arg3, (int)arg4) -> None :
 
render_tile_to_file(...)
render_tile_to_file( (Map)arg1, (int)arg2, (int)arg3, (int)arg4, (int)arg5, (str)arg6, (str)arg7) -> None :
 
render_to_file(...)
render_to_file( (Map)arg1, (str)arg2, (str)arg3) -> None :
 
save_map(...)
save_map( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :
 
scale_denominator(...)
scale_denominator( (Map)arg1, (bool)arg2) -> float :
Variables
  RTLD_NOW = 2
  RTLD_GLOBAL = 8
  flags = 2
  fonts = ['/usr/local/lib/mapnik/fonts/DejaVuSans-Bold.ttf', '/...
Function Details

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

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)

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)
  row_limit -- integer limit of rows to return (default 0)
  cursor_size -- integer size of cursor to fetch (default 0)
  geometry_field -- specify geometry field (default first entry in geometry_columns)
  multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)

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

Optional keyword arguments:
  base -- path prefix (default None)

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

>>> 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)
  multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)

>>> 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 -- layer to use within datasource

Optional keyword arguments:
  base -- path prefix (default None)
  encoding -- file encoding (default 'utf-8')
  multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)

>>> 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)
  multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)
  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

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

CreateDatasource(...)

 

CreateDatasource( (dict)arg1) -> Datasource :

    C++ signature :
        boost::shared_ptr<mapnik::datasource> CreateDatasource(boost::python::dict)

Describe(...)

 

Describe( (Datasource)arg1) -> str :

    C++ signature :
        std::string Describe(boost::shared_ptr<mapnik::datasource>)

Filter(...)

 

Filter( (str)arg1) -> Filter :

    C++ signature :
        boost::shared_ptr<mapnik::filter<mapnik::feature<mapnik::geometry<mapnik::vertex<double, 2> >, boost::shared_ptr<mapnik::raster> > > > Filter(std::string)

forward_(...)

 

forward_( (Coord)arg1, (Projection)arg2) -> Coord :

    C++ signature :
        mapnik::coord<double, 2> forward_(mapnik::coord<double, 2>,mapnik::projection)

forward_( (Envelope)arg1, (Projection)arg2) -> Envelope :

    C++ signature :
        mapnik::Envelope<double> forward_(mapnik::Envelope<double>,mapnik::projection)

has_cairo()

 
    Get cairo library status

    C++ signature :
        bool has_cairo()

Returns: bool :

inverse_(...)

 

inverse_( (Coord)arg1, (Projection)arg2) -> Coord :

    C++ signature :
        mapnik::coord<double, 2> inverse_(mapnik::coord<double, 2>,mapnik::projection)

inverse_( (Envelope)arg1, (Projection)arg2) -> Envelope :

    C++ signature :
        mapnik::Envelope<double> inverse_(mapnik::Envelope<double>,mapnik::projection)

load_map(...)

 

load_map( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :

    C++ signature :
        void load_map(mapnik::Map {lvalue},std::string [,bool])

load_map_from_string(...)

 

load_map_from_string( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :

    C++ signature :
        void load_map_from_string(mapnik::Map {lvalue},std::string [,bool])

mapnik_version()

 
    Get the Mapnik version number

    C++ signature :
        unsigned int mapnik_version()

Returns: int :

render(...)

 

render( (Map)arg1, (Image)arg2, (int)arg3, (int)arg4) -> None :
    
    Render Map to an AGG Image32 using offsets
    
    Usage:
    >>> from mapnik import Map, Image, render, load_map
    >>> m = Map(256,256)
    >>> load_map(m,'mapfile.xml')
    >>> im = Image(m.width,m.height)
    >>> render(m,im,1,1)
    
    

    C++ signature :
        void render(mapnik::Map,mapnik::Image32 {lvalue},unsigned int,unsigned int)

render( (Map)arg1, (Image)arg2) -> None :
    
    Render Map to an AGG Image32
    
    Usage:
    >>> from mapnik import Map, Image, render, load_map
    >>> m = Map(256,256)
    >>> load_map(m,'mapfile.xml')
    >>> im = Image(m.width,m.height)
    >>> render(m,im)
    
    

    C++ signature :
        void render(mapnik::Map,mapnik::Image32 {lvalue})

render_tile_to_file(...)

 

render_tile_to_file( (Map)arg1, (int)arg2, (int)arg3, (int)arg4, (int)arg5, (str)arg6, (str)arg7) -> None :
    
    TODO
    
    

    C++ signature :
        void render_tile_to_file(mapnik::Map,unsigned int,unsigned int,unsigned int,unsigned int,std::string,std::string)

render_to_file(...)

 

render_to_file( (Map)arg1, (str)arg2, (str)arg3) -> None :
    
    Render Map to file using explicit image type.
    
    Usage:
    >>> from mapnik import Map, render_to_file, load_map
    >>> m = Map(256,256)
    >>> load_map(m,'mapfile.xml')
    >>> render_to_file(m,'image32bit.png','png')
    
    8 bit (paletted) PNG can be requested with 'png256':
    >>> render_to_file(m,'8bit_image.png','png256')
    
    JPEG quality can be controlled by adding a suffix to
    'jpeg' between 0 and 100 (default is 85):
    >>> render_to_file(m,'top_quality.jpeg','jpeg100')
    >>> render_to_file(m,'medium_quality.jpeg','jpeg50')
    

    C++ signature :
        void render_to_file(mapnik::Map,std::string,std::string)

render_to_file( (Map)arg1, (str)arg2) -> None :
    
    Render Map to file (type taken from file extension)
    
    Usage:
    >>> from mapnik import Map, render_to_file, load_map
    >>> m = Map(256,256)
    >>> render_to_file(m,'image.jpeg')
    
    

    C++ signature :
        void render_to_file(mapnik::Map,std::string)

save_map(...)

 

save_map( (Map)arg1, (str)arg2 [, (bool)arg3]) -> None :

    C++ signature :
        void save_map(mapnik::Map,std::string [,bool])

scale_denominator(...)

 

scale_denominator( (Map)arg1, (bool)arg2) -> float :
    
    Return the Map Scale Denominator.
    Also available as Map.scale_denominator()
    
    Usage:
    
    >>> from mapnik import Map, Projection, scale_denominator, load_map
    >>> m = Map(256,256)
    >>> load_map(m,'mapfile.xml')
    >>> scale_denominator(m,Projection(m.srs).geographic)
    
    

    C++ signature :
        double scale_denominator(mapnik::Map,bool)


Variables Details

fonts

Value:
['/usr/local/lib/mapnik/fonts/DejaVuSans-Bold.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSans-BoldOblique.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSans-ExtraLight.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSans-Oblique.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSans.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSansCondensed-Bold.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSansCondensed-BoldOblique.ttf',
 '/usr/local/lib/mapnik/fonts/DejaVuSansCondensed-Oblique.ttf',
...