1

I'm using mapnik 2.2.0 from Python on Ubuntu 16.04. I load OSM data and a layer of points from a csv file. The points in the csv file are in epsg:4326.

Different points appear or disappear depending on the size of the map. The points that don't appear (depending on the map size) are in between points that appear.

For example, in the 1024x1024 map, points 1, 5, and 8 from the list below do not appear, but they do appear in the 640x480 map.

My code and sample points are below.

Any help is appreciated.

Thanks.

dl

points.csv

longitude,latitude

-81.36267786,31.17942128
-81.34324795,31.27446072
-81.47343063,31.24168062
-81.55010796,30.34051442
-81.80767273,30.31021431
-81.37953944,30.19135471
-81.7932574,30.19754696
-81.76737595,30.13418484
-81.84996796,30.08385658
-81.58109463,30.50306859
-81.49115618,30.51390896
-81.5587192,30.63135991
-81.57580261,31.25126381
-81.29788475,29.8236434

#!/usr/bin/env python2

import mapnik


mapfile = '/etc/mapnik-v2.2.0/config/mapnik_osm.xml'

#m = mapnik.Map (640, 480)

#m = mapnik.Map (1280, 960) m = mapnik.Map (1024, 1024)

m.background = mapnik.Color ('rgb (0,0,0,0)')
m.aspect_fix_mode = mapnik.aspect_fix_mode.GROW_CANVAS

mapnik.load_map (m, mapfile)

style = mapnik.Style()
rule1 = mapnik.Rule()
marker_symbolizer = mapnik.MarkersSymbolizer()
marker_symbolizer.allow_overlap = False
marker_symbolizer.opacity = 1.0
rule1.symbols.append(marker_symbolizer)
style.rules.append(rule1)

m.append_style('GPS_tracking_points', style)
layer = mapnik.Layer('coordinates', '+proj=latlong +datum=WGS84')
layer.datasource = mapnik.CSV(file="points.csv", layer_by_index=0)

layer.styles.append('GPS_tracking_points')
m.layers.append(layer)

west, south, east, north = -82.299335015,29.8236434,-80.848517695,31.27446072
bbox = (mapnik.Box2d (west, south, east, north))

merc = mapnik.Projection('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over')
longlat = mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')

transform = mapnik.ProjTransform(longlat,merc)
merc_bbox = transform.forward(bbox)


m.zoom_to_box(merc_bbox)

mapnik.render_to_file(m, "map_example.png")

640x480 1024x1024

user2333312
  • 101
  • 1
  • 9

1 Answers1

1

I've just been dealing with a very similar issue where markers would not render. I noticed a trend in that the ones that did not render conflicted with road name lables. I suspect you may be having a similar issue with other feature lables (for example the point just left of the "jacksonville" text, the larger map renders an airport which proabably conficts).

The solution, for me was to set 'clear_label_cache' to True on the layer object. I.e.:

layer = mapnik.Layer('coordinates', '+proj=latlong +datum=WGS84')
layer.datasource = mapnik.CSV(file="points.csv", layer_by_index=0)
layer.clear_label_cache = True
...

Reference: http://mapnik.org/docs/v2.0.1/api/python/mapnik._mapnik.Layer-class.html#clear_label_cache

Hope this helps!

Regards, Chris

  • Chris, sorry it took so long for me to respond. Adding layer.clear_label_cache = True solved the problem. Thanks! – user2333312 Mar 24 '17 at 13:53
  • This solved the problem for me as well - I was upgrading from 2.2.0 to 3.x and various markers disappeared from my maps – Tom Aug 23 '17 at 20:07