Hi all,  I just started working with Mapnik the other day.  I have taken one
of the demos and modified it in an attempt to iterate through a database of
country names, and then simply change their color to red if they are present
in the table.  the problem is that, although it appears to iterate through
all of the countries, the only one that gets 'labeled red' is the last on in
the loop.  The code is as follows:

 (Select some data from a mysql database....)

    MappingLines = cursorM.fetchall()
    m = mapnik.Map(800,300)
    mapnik.load_map(m,'c:\\IVVSL\\Results\\populationb.xml')

    countries = m.layers[0]
    ds = countries.datasource
    countries.styles.append('selected')
    featureset = ds.all_features()
    PosQuery = []
    for Mline in MappingLines:

        critFilter = ("[NAME] = '%s'")%Mline[1]
        criteria = mapnik.Filter(critFilter)

        queryset = [f for f in featureset if criteria.passes(f)]
        try:
            PosQuery.append(queryset[0])
        except:
            continue

    for feature in PosQuery:
            m.zoom_to_box(feature.envelope())
            m.zoom(1)
            name = str(feature.attributes['NAME'])

            print 'Matched %s...' % name
            feature_filter = mapnik.Filter("[NAME] = '%s'" % name)

            s,r = mapnik.Style(),mapnik.Rule()


r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('darkorange'),3))

r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('yellow'),2))
            r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('red')))

            t = mapnik.TextSymbolizer('NAME', 'DejaVu Sans Book', 10,
mapnik.Color('rgba(0,0,0,.8)') )
            t.avoid_edges = True

            t.halo_fill = mapnik.Color('rgba(255,255,255,.2)')
            t.halo_radius = 2

            r.symbols.append(t)
            r.filter = feature_filter

            s.rules.append(r)
            m.remove_style('selected')
            m.append_style('selected',s)

    im = mapnik.Image(m.width,m.height)
    mapnik.render(m, im)
    file = "c:\\IVVSL\\Results\\IVirMAP.png"
    print 'Rendering %s...' % file
    im.save(file)

I'm guessing that it is redrawing the map at each iteration of the PosQuery
loop, and my previous labels are being obscured, but I don't see which
command is causing it.  I've tried commenting out different lines to see how
it affects it, but it still isn't clear.  Does anybody have any suggestions
as to how to modify this loop to append all of the symbols on the same map.
It seems like it should be an easy issue to resolve, but I've tried many
permutations of this code, and the result always ends up the same.  ie.  if
i have a table with Canada, Hong Kong, and the United States (in that order)
the only country that gets labeled is the United States.  I'd appreciate any
assistance that you can provide to a mapnik noob.  Thanks.

-Roger
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to