mapnik / python-mapnik

Python bindings for mapnik
GNU Lesser General Public License v2.1
160 stars 91 forks source link

Mapnik parsing error for a xml generated by carto #132

Open bogdanul2003 opened 7 years ago

bogdanul2003 commented 7 years ago

I have generated a xml style sheet using carto/project.mml > mapnik.xml

Whe I run a python script in order to render a pbf file I get an error while it parses the mapnik.xml file:

`#!/usr/bin/env python import mapnik from mapnik import *

mapnik.logger.set_severity(mapnik.severity_type.Debug) mapfile = 'mapnik.xml' map_output = 'mymap33.png' m = Map(2048, 2048) load_map(m, mapfile) bbox=(Box2d( 26.08901,44.420234,26.125488,44.435067))

m.zoom_to_box(bbox)

render_to_file(m, map_output)`

The error is this: `Mapnik LOG> 2017-01-20 08:07:18: Unable to process some data while parsing 'mapnik.xml':

talaj commented 7 years ago

What version of Mapnik do you have? maximum-scale-denominator was formerly called maxzoom but was renamed in https://github.com/mapnik/mapnik/commit/219ad1f2ccd2eaa5799dad73236378b127f490d9, see https://github.com/mapnik/mapnik/issues/1447.

bogdanul2003 commented 7 years ago

biliuta@ubuntu:~/Downloads/mapnik-3.x$ mapnik-config -v 3.1.0

I compiled the latest source code from master branch so I should have the version that uses maximum-scale-denominator. The parsing is done by the mapnik library in C++ as far as I can understand. Is this correct or it's done in python ?

talaj commented 7 years ago

The parsing is done by the mapnik library in C++ as far as I can understand. Is this correct or it's done in python ?

Yes, it is done by Mapnik in C++.

You can try to reduce the XML to minimum which still fails and paste it here.

bogdanul2003 commented 7 years ago

` <Layer name="builtup" maximum-scale-denominator="3000000" minimum-scale-denominator="750000" srs="+proj=merc +datum=WGS84 +over">

builtup
<Datasource>
   <Parameter name="file"><![CDATA[data/world_boundaries/builtup_area.shp]]></Parameter>
   <Parameter name="type"><![CDATA[shape]]></Parameter>
</Datasource>

`

The mapnik.xml file has over 35.000 lines but above I've pasted a piece of it that I think fails. It's kind of difficult to paste xml files here because I can't format them correctly. If you want I can upload the xml file somewere and send you a link.

talaj commented 7 years ago

I don't know what's wrong. This piece works for me.

bogdanul2003 commented 7 years ago

Hmmm ... In fact I don't think there is a xml formatting problem. I looked up the error message in the code and it points to find_unused_nodes_recursive() function. Judging by the name of the function and by the way it is used I think mapnik doesn't allow the existence of unused nodes ? And who must use the node maximum-scale-denominator ?

bogdanul2003 commented 7 years ago

Here you can download the xml file: https://expirebox.com/download/21f7378b9a35cb3491b1b958cb859fe6.html

bogdanul2003 commented 7 years ago

After a short break I got back to mapnik. I checked my install environment and it seemed that I installed the python-mapnik from pip repo and not from source so it wasn't using the mapnik library that I compiled from source. Now I've also compiled python-mapnik from source and using gdb I can see that at run time python loads libmapnik.so.3.1.0 library which has the same md5sum as the one built by me.

This got rid of the error message with which I opened this issue.

I guess this issue can be closed but I still have some problems rendering a first map and I would appreciate if you guys can point me in the right direction. The rendered map is always blank.

I compiled my library for debug and used this python script:

#!/usr/bin/env python

import mapnik
from mapnik import *

mapnik.logger.set_severity(mapnik.severity_type.Debug)

mapfile = 'mapnik.xml'
map_output = 'mymap33.png'

m = Map(2048, 2048)
load_map(m, mapfile)
bbox=(Box2d( 26.08901,44.420234,26.125488,44.435067))

m.zoom_to_box(bbox) 
render_to_file(m, map_output)

if I remove those lines:

bbox=(Box2d( 26.08901,44.420234,26.125488,44.435067))
m.zoom_to_box(bbox) 

I get this error:

0.92ms (cpu 0.07ms)         | postgis_connection::execute_query SELECT oid, typname FROM pg_type WHERE oid = 19553
2.51ms (cpu 0.66ms)         | postgis_datasource::bind(get_column_description)
Mapnik LOG> 2017-02-06 07:57:56: postgis_connection: closing connection (close)- 0x2b41790
29.85ms (cpu 1.56ms)        | postgis_datasource::init
Mapnik LOG> 2017-02-06 07:57:56: agg_renderer: Scale=-inf
Mapnik LOG> 2017-02-06 07:57:56: agg_renderer: Start map processing bbox=box2d(INVALID)
Mapnik LOG> 2017-02-06 07:57:56: agg_renderer: End map processing
Mapnik LOG> 2017-02-06 07:57:56: stroker: Destroy stroker=0x39569b0

Can you please tell me why bbox is initialized with an INVALID parameter? If I don't remove those 2 lines all seems to run correctly but the image is still blank. I've attached the debug output with the 2 lines included in the code. out.txt