NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

2
1

I want to generate SVG maps in Python using Mapnik 3.0.13 (built from source). I'm using version 3.0.13 of the Python bindings as well, built with PYCAIRO. My code:

f = open('/tmp/test.svg', 'w')
surface = cairo.SVGSurface(f.name, map.width, map.height)
mapnik.render(map, surface)
surface.finish()

The output SVG file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="4961pt" height="3508pt" viewBox="0 0 4961 3508" version="1.1">
<defs>
<image id="image3198" width="20671" height="14617" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAUL8A ...

Followed by ~200 MB of base64-encoded PNG garbage.

I tried recompiling my library and bindings to use the native svg_renderer instead of Cairo, but got the same result.

How do I get a "real" SVG? This is just a PNG file wrapped inside an SVG (in an extremely inefficient way).

asked 01 Sep '17, 17:44

derkartograf's gravatar image

derkartograf
81114
accept rate: 100%

edited 01 Sep '17, 17:51

I have the same issue. PDF export works properly though (outputs a vector PDF)

(05 Sep '17, 10:48) knowname

See https://github.com/mapnik/python-mapnik/issues/137 - this appears to be a Mapnik issue.

(05 Sep '17, 11:08) Richard ♦

I created a Mapnik issue for this: https://github.com/mapnik/mapnik/issues/3749

Turns out this happens when your style uses compositing operations like comp-op="multiply". These lead to rasterization of the map.

Removing all comp-op filters produces a "real" SVG. Alternatively, PDF output works as mentioned by @knowname above.

permanent link

answered 05 Sep '17, 11:15

derkartograf's gravatar image

derkartograf
81114
accept rate: 100%

I've accepted your answer here - hope that's OK!

(05 Sep '17, 13:01) SomeoneElse ♦

The problem has been found to be something with SVG version support. You can build Mapnik with this patch applied:

https://github.com/mapnik/mapnik/pull/4029#issue-251451960

or just use python-cairo with a code like:

surface.restrict_to_version(cairo.SVG_VERSION_1_2)

See also https://help.openstreetmap.org/questions/65497/is-there-any-change-in-svg-exports/67940

permanent link

answered 11 Feb '19, 23:41

kocio's gravatar image

kocio
2.1k12341
accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×341
×78
×47

question asked: 01 Sep '17, 17:44

question was seen: 4,195 times

last updated: 11 Feb '19, 23:41

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum