openstreetmap/operations

Export feature sometimes produces large PDF files

Closed this issue · 5 comments

URL

No response

How to reproduce the issue?

No response

Screenshot(s) or anything else?

When using "Share" on the right side of the OSM website, it's possible to export the visible area as PDF file. The generated PDF files are sometimes much larger than necessary, likely, because they sometimes include gigantic relations (e.g. bus routes). See discussion in the german OSM forum for an example - the tiny red dot in the image there is the export region.

I tried to hunt this bug down and reached an end when the submittion is redirected to https://render.openstreetmap.org/cgi-bin/export in export_controller.rb. I couldn't figure out, where the source code of this cgi is. I guess not even in this repo, but maybe I just overlooked something.

I would appreciate if someone could point me to the source code, so I can continue the "hunting". :-)

Firstly as you have identified this has nothing to do with code in this repository, so this is the wrong place for this ticket and I will move it to a more appropriate location.

The source code for that CGI isn't going to help you in any case because it's just a wrapper around mapnik that asks mapnik to render that area in a given format.

To answer your question https://github.com/openstreetmap/chef/blob/master/cookbooks/tile/templates/default/export.erb is the script but as I say it's not going to help.

Practically speaking there simply isn't going to be any solution to your problem, and certainly not an easy one - large complicated areas naturally involve huge amounts of data that will overwhelm non-specialised vector renderers like PDF or SVG in most cases.

If you want to spend time on trying to improve mapnik's PDF output then https://github.com/mapnik/mapnik/ is the place to look but I think you'll find it extremely challenging.

Practically speaking there simply isn't going to be any solution to your problem, and certainly not an easy one - large complicated areas naturally involve huge amounts of data that will overwhelm non-specialised vector renderers like PDF or SVG in most cases.

Part of the problem here is (as I understand it) that geometries are not clipped to the requested bounding box. So the output can contain vast geometries if a small part overlaps (e.g. the output contains an entire lake, which might be tens of thousands of points).

Clipping the geometries to the requested bbox might be feasible with the existing mapnik bindings.

The exact code is https://github.com/openstreetmap/chef/blob/237d93489bca6fbae88dd2a9f63fedca0aba0a36/cookbooks/tile/templates/default/export.erb#L173 which just does:

file = tempfile.NamedTemporaryFile(prefix = "export")
surface = cairo.PDFSurface(file.name, map.width, map.height)
mapnik.render(map, surface)
surface.finish()

which just creates a PDF surface of the given size and asks mapnik to render to it.

I think any change would have to be in how mapnik interacts with cairo to do the rendering, and it's a very long time since I wrote that!

but I think you'll find it extremely challenging.

I like challenges. :-)

Having said this: Unfortunately Mapnik is mainly written in C++, a language I had problems with in the past. So I'm not sure if I'm able to improve anything...

While it might be difficult to reduce the size of lakes (or other areas), I think for linear features like bus-routes, this should be fairly easy: Remove every line segment with both ends on the same side of the bounding box and keep all else... I'll have a look!

Many thanks for your comments.