preserve old MemoryDatasource interface in Python
This commit is contained in:
parent
16fafbad43
commit
6297c72f02
4 changed files with 21 additions and 11 deletions
|
@ -627,6 +627,16 @@ def Python(**keywords):
|
||||||
keywords['type'] = 'python'
|
keywords['type'] = 'python'
|
||||||
return CreateDatasource(keywords)
|
return CreateDatasource(keywords)
|
||||||
|
|
||||||
|
def MemoryDatasource(**keywords):
|
||||||
|
"""Create a Memory Datasource.
|
||||||
|
|
||||||
|
Optional keyword arguments:
|
||||||
|
(TODO)
|
||||||
|
"""
|
||||||
|
params = Parameters()
|
||||||
|
params.append(Parameter('type','memory'))
|
||||||
|
return MemoryDatasourceBase(params)
|
||||||
|
|
||||||
class PythonDatasource(object):
|
class PythonDatasource(object):
|
||||||
"""A base class for a Python data source.
|
"""A base class for a Python data source.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ see the documentation of mapnik.printing.PDFPrinter() for options
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from . import render, Map, Box2d, MemoryDatasource, Layer, Feature, Projection, ProjTransform, Coord, Style, Rule, Geometry2d
|
from . import render, Map, Box2d, Layer, Feature, Projection, ProjTransform, Coord, Style, Rule, Geometry2d
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -306,12 +306,12 @@ class PDFPrinter:
|
||||||
"""Main class for creating PDF print outs, basically contruct an instance
|
"""Main class for creating PDF print outs, basically contruct an instance
|
||||||
with appropriate options and then call render_map with your mapnik map
|
with appropriate options and then call render_map with your mapnik map
|
||||||
"""
|
"""
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
pagesize=pagesizes["a4"],
|
pagesize=pagesizes["a4"],
|
||||||
margin=0.005,
|
margin=0.005,
|
||||||
box=None,
|
box=None,
|
||||||
percent_box=None,
|
percent_box=None,
|
||||||
scale=default_scale,
|
scale=default_scale,
|
||||||
resolution=resolutions.dpi72,
|
resolution=resolutions.dpi72,
|
||||||
preserve_aspect=True,
|
preserve_aspect=True,
|
||||||
centering=centering.constrained,
|
centering=centering.constrained,
|
||||||
|
@ -321,7 +321,7 @@ class PDFPrinter:
|
||||||
|
|
||||||
pagesize: tuple of page size in meters, see predefined sizes in pagessizes dict (default a4)
|
pagesize: tuple of page size in meters, see predefined sizes in pagessizes dict (default a4)
|
||||||
margin: page margin in meters (default 0.01)
|
margin: page margin in meters (default 0.01)
|
||||||
box: box within the page to render the map into (will not render over margin). This should be
|
box: box within the page to render the map into (will not render over margin). This should be
|
||||||
a Mapnik Box2d object. Default is the full page within the margin
|
a Mapnik Box2d object. Default is the full page within the margin
|
||||||
percent_box: as per box, but specified as a percent (0->1) of the full page size. If both box
|
percent_box: as per box, but specified as a percent (0->1) of the full page size. If both box
|
||||||
and percent_box are specified percent_box will be used.
|
and percent_box are specified percent_box will be used.
|
||||||
|
@ -485,7 +485,7 @@ class PDFPrinter:
|
||||||
|
|
||||||
def _get_context(self):
|
def _get_context(self):
|
||||||
if HAS_PANGOCAIRO_MODULE:
|
if HAS_PANGOCAIRO_MODULE:
|
||||||
return
|
return
|
||||||
elif HAS_PYCAIRO_MODULE:
|
elif HAS_PYCAIRO_MODULE:
|
||||||
return cairo.Context(self._s)
|
return cairo.Context(self._s)
|
||||||
return None
|
return None
|
||||||
|
@ -779,7 +779,7 @@ class PDFPrinter:
|
||||||
prev = value
|
prev = value
|
||||||
value+=page_div_size
|
value+=page_div_size
|
||||||
fill = [1-z for z in fill]
|
fill = [1-z for z in fill]
|
||||||
label_value += div_size
|
label_value += div_size
|
||||||
if self._is_latlon and label_value > 180:
|
if self._is_latlon and label_value > 180:
|
||||||
label_value -= 360
|
label_value -= 360
|
||||||
text = "%d" % label_value
|
text = "%d" % label_value
|
||||||
|
@ -1025,4 +1025,3 @@ class PDFPrinter:
|
||||||
if y > h:
|
if y > h:
|
||||||
h = y
|
h = y
|
||||||
return (w,h)
|
return (w,h)
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ using mapnik::datasource;
|
||||||
using mapnik::memory_datasource;
|
using mapnik::memory_datasource;
|
||||||
using mapnik::layer_descriptor;
|
using mapnik::layer_descriptor;
|
||||||
using mapnik::attribute_descriptor;
|
using mapnik::attribute_descriptor;
|
||||||
|
using mapnik::parameters;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -191,7 +192,7 @@ void export_datasource()
|
||||||
|
|
||||||
class_<memory_datasource,
|
class_<memory_datasource,
|
||||||
bases<datasource>, std::shared_ptr<memory_datasource>,
|
bases<datasource>, std::shared_ptr<memory_datasource>,
|
||||||
boost::noncopyable>("MemoryDatasource", no_init)
|
boost::noncopyable>("MemoryDatasourceBase", init<parameters>())
|
||||||
.def("add_feature",&memory_datasource::push,
|
.def("add_feature",&memory_datasource::push,
|
||||||
"Adds a Feature:\n"
|
"Adds a Feature:\n"
|
||||||
">>> ms = MemoryDatasource()\n"
|
">>> ms = MemoryDatasource()\n"
|
||||||
|
|
|
@ -61,7 +61,7 @@ int main(int argc, char** argv)
|
||||||
mapnik::layer lyr("layer");
|
mapnik::layer lyr("layer");
|
||||||
lyr.set_datasource(ds);
|
lyr.set_datasource(ds);
|
||||||
lyr.add_style("style");
|
lyr.add_style("style");
|
||||||
m.add_layer(std::move(lyr));
|
m.add_layer(lyr);
|
||||||
mapnik::feature_type_style the_style;
|
mapnik::feature_type_style the_style;
|
||||||
mapnik::rule r;
|
mapnik::rule r;
|
||||||
mapnik::text_symbolizer text_sym;
|
mapnik::text_symbolizer text_sym;
|
||||||
|
|
Loading…
Add table
Reference in a new issue