def test_raster_warping():
    lyrSrs = "+init=epsg:32630"
    mapSrs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
    lyr = mapnik2.Layer('dataraster', lyrSrs)
    if 'gdal' in mapnik2.DatasourceCache.instance().plugin_names():
        lyr.datasource = mapnik2.Gdal(
            file = '../data/raster/dataraster.tif',
            band = 1,
            )
        sym = mapnik2.RasterSymbolizer()
        sym.colorizer = mapnik2.RasterColorizer(mapnik2.COLORIZER_DISCRETE, mapnik2.Color(255,255,0))
        rule = mapnik2.Rule()
        rule.symbols.append(sym)
        style = mapnik2.Style()
        style.rules.append(rule)
        _map = mapnik2.Map(256,256, mapSrs)
        _map.append_style('foo', style)
        lyr.styles.append('foo')
        _map.layers.append(lyr)
        prj_trans = mapnik2.ProjTransform(mapnik2.Projection(mapSrs),
                                          mapnik2.Projection(lyrSrs)) 
        _map.zoom_to_box(prj_trans.backward(lyr.envelope()))
    
        im = mapnik2.Image(_map.width,_map.height)
        mapnik2.render(_map, im)
        # save a png somewhere so we can see it
        save_data('test_raster_warping.png', im.tostring('png'))
        imdata = im.tostring()
        assert contains_word('\xff\xff\x00\xff', imdata)
Esempio n. 2
0
def test_renders_with_agg():
    sym = mapnik2.GlyphSymbolizer("DejaVu Sans Condensed",
                                  mapnik2.Expression("'í'"))
    sym.allow_overlap = True
    sym.angle = mapnik2.Expression("[azimuth]+90") #+90 so the top of the glyph points upwards
    sym.size = mapnik2.Expression("[value]")
    sym.color = mapnik2.Expression("'#ff0000'")

    _map = create_map_and_append_symbolyzer(sym)
    if _map:
        im = mapnik2.Image(_map.width,_map.height)
        mapnik2.render(_map, im)
        save_data('agg_glyph_symbolizer.png', im.tostring('png'))
        assert contains_word('\xff\x00\x00\xff', im.tostring())
def test_dataraster_coloring():
    srs = '+init=epsg:32630'
    lyr = mapnik2.Layer('dataraster')
    if 'gdal' in mapnik2.DatasourceCache.instance().plugin_names():
        lyr.datasource = mapnik2.Gdal(
            file = '../data/raster/dataraster.tif',
            band = 1,
            )
        lyr.srs = srs
        _map = mapnik2.Map(256,256, srs)
        style = mapnik2.Style()
        rule = mapnik2.Rule()
        sym = mapnik2.RasterSymbolizer()
        # Assigning a colorizer to the RasterSymbolizer tells the later
        # that it should use it to colorize the raw data raster
        sym.colorizer = mapnik2.RasterColorizer(mapnik2.COLORIZER_DISCRETE, mapnik2.Color("transparent"))
        
        for value, color in [
            (  0, "#0044cc"),
            ( 10, "#00cc00"),
            ( 20, "#ffff00"),
            ( 30, "#ff7f00"),
            ( 40, "#ff0000"),
            ( 50, "#ff007f"),
            ( 60, "#ff00ff"),
            ( 70, "#cc00cc"),
            ( 80, "#990099"),
            ( 90, "#660066"),
            ( 200, "transparent"),
        ]:
            sym.colorizer.add_stop(value, mapnik2.Color(color))
        rule.symbols.append(sym)
        style.rules.append(rule)
        _map.append_style('foo', style)
        lyr.styles.append('foo')
        _map.layers.append(lyr)
        _map.zoom_to_box(lyr.envelope())
    
        im = mapnik2.Image(_map.width,_map.height)
        mapnik2.render(_map, im)
        # save a png somewhere so we can see it
        save_data('test_dataraster_coloring.png', im.tostring('png'))
        imdata = im.tostring()
        # we have some values in the [20,30) interval so check that they're colored
        assert contains_word('\xff\xff\x00\xff', imdata)
Esempio n. 4
0
def test_renders_with_cairo():
    if not mapnik2.has_pycairo():
        return
    sym = mapnik2.GlyphSymbolizer("DejaVu Sans Condensed",
                                  mapnik2.Expression("'í'"))
    sym.allow_overlap = True
    sym.angle = mapnik2.Expression("[azimuth]+90") #+90 so the top of the glyph points upwards
    sym.size = mapnik2.Expression("[value]")
    sym.color = mapnik2.Expression("'#ff0000'")
    _map = create_map_and_append_symbolyzer(sym)
    if _map:
        from cStringIO import StringIO
        import cairo
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 256, 256)
        mapnik2.render(_map, surface)
        im = mapnik2.Image.from_cairo(surface)
        save_data('cairo_glyph_symbolizer.png', im.tostring('png'))
        assert contains_word('\xff\x00\x00\xff', im.tostring())
def test_raster_with_alpha_blends_correctly_with_background():
    WIDTH = 500
    HEIGHT = 500

    map = mapnik2.Map(WIDTH, HEIGHT)
    WHITE = mapnik2.Color(255, 255, 255)
    map.background = WHITE

    style = mapnik2.Style()
    rule = mapnik2.Rule()
    symbolizer = mapnik2.RasterSymbolizer()
    #XXX: This fixes it, see http://trac.mapnik.org/ticket/759#comment:3
    #     (and remove comment when this test passes)
    #symbolizer.scaling="bilinear_old"

    rule.symbols.append(symbolizer)
    style.rules.append(rule)

    map.append_style('raster_style', style)

    map_layer = mapnik2.Layer('test_layer')
    filepath = '../data/raster/white-alpha.png'
    if 'gdal' in mapnik2.DatasourceCache.instance().plugin_names():
        map_layer.datasource = mapnik2.Gdal(file=filepath)
        map_layer.styles.append('raster_style')
        map.layers.append(map_layer)
    
        map.zoom_all()
    
        mim = mapnik2.Image(WIDTH, HEIGHT)
    
        mapnik2.render(map, mim)
        save_data('test_raster_with_alpha_blends_correctly_with_background.png',
                  mim.tostring('png'))
        imdata = mim.tostring()
        # All white is expected
        assert contains_word('\xff\xff\xff\xff', imdata)