From 6297c72f0221c31e59b41bd2d01dd9c0d4b4a7f4 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 30 May 2014 11:03:31 +0100 Subject: [PATCH] preserve old MemoryDatasource interface in Python --- bindings/python/mapnik/__init__.py | 10 ++++++++++ bindings/python/mapnik/printing.py | 17 ++++++++--------- bindings/python/mapnik_datasource.cpp | 3 ++- tests/cpp_tests/fontset_runtime_test.cpp | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index f98f1b60c..fea4590ed 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -627,6 +627,16 @@ def Python(**keywords): keywords['type'] = 'python' 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): """A base class for a Python data source. diff --git a/bindings/python/mapnik/printing.py b/bindings/python/mapnik/printing.py index 8c15d8a8c..a354c4999 100644 --- a/bindings/python/mapnik/printing.py +++ b/bindings/python/mapnik/printing.py @@ -17,7 +17,7 @@ see the documentation of mapnik.printing.PDFPrinter() for options """ 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 os import tempfile @@ -306,12 +306,12 @@ class PDFPrinter: """Main class for creating PDF print outs, basically contruct an instance with appropriate options and then call render_map with your mapnik map """ - def __init__(self, - pagesize=pagesizes["a4"], - margin=0.005, + def __init__(self, + pagesize=pagesizes["a4"], + margin=0.005, box=None, percent_box=None, - scale=default_scale, + scale=default_scale, resolution=resolutions.dpi72, preserve_aspect=True, centering=centering.constrained, @@ -321,7 +321,7 @@ class PDFPrinter: pagesize: tuple of page size in meters, see predefined sizes in pagessizes dict (default a4) 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 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. @@ -485,7 +485,7 @@ class PDFPrinter: def _get_context(self): if HAS_PANGOCAIRO_MODULE: - return + return elif HAS_PYCAIRO_MODULE: return cairo.Context(self._s) return None @@ -779,7 +779,7 @@ class PDFPrinter: prev = value value+=page_div_size fill = [1-z for z in fill] - label_value += div_size + label_value += div_size if self._is_latlon and label_value > 180: label_value -= 360 text = "%d" % label_value @@ -1025,4 +1025,3 @@ class PDFPrinter: if y > h: h = y return (w,h) - diff --git a/bindings/python/mapnik_datasource.cpp b/bindings/python/mapnik_datasource.cpp index 2b601819e..bfa7fdcb3 100644 --- a/bindings/python/mapnik_datasource.cpp +++ b/bindings/python/mapnik_datasource.cpp @@ -41,6 +41,7 @@ using mapnik::datasource; using mapnik::memory_datasource; using mapnik::layer_descriptor; using mapnik::attribute_descriptor; +using mapnik::parameters; namespace { @@ -191,7 +192,7 @@ void export_datasource() class_, std::shared_ptr, - boost::noncopyable>("MemoryDatasource", no_init) + boost::noncopyable>("MemoryDatasourceBase", init()) .def("add_feature",&memory_datasource::push, "Adds a Feature:\n" ">>> ms = MemoryDatasource()\n" diff --git a/tests/cpp_tests/fontset_runtime_test.cpp b/tests/cpp_tests/fontset_runtime_test.cpp index 1defd033a..69082b2a1 100644 --- a/tests/cpp_tests/fontset_runtime_test.cpp +++ b/tests/cpp_tests/fontset_runtime_test.cpp @@ -61,7 +61,7 @@ int main(int argc, char** argv) mapnik::layer lyr("layer"); lyr.set_datasource(ds); lyr.add_style("style"); - m.add_layer(std::move(lyr)); + m.add_layer(lyr); mapnik::feature_type_style the_style; mapnik::rule r; mapnik::text_symbolizer text_sym;