Esempio n. 1
0
def test_render_points():
    # Test for effectivenes of ticket #402 (borderline points get lost on reprojection)
    raise Todo("See: http://trac.mapnik2.org/ticket/402")

    if not mapnik2.has_pycairo():
        return

    # create and populate point datasource (WGS84 lat-lon coordinates)
    places_ds = mapnik2.PointDatasource()
    places_ds.add_point(142.48, -38.38, "Name", "Westernmost Point")  # westernmost
    places_ds.add_point(143.10, -38.60, "Name", "Southernmost Point")  # southernmost
    # create layer/rule/style
    s = mapnik2.Style()
    r = mapnik2.Rule()
    symb = mapnik2.PointSymbolizer()
    symb.allow_overlap = True
    r.symbols.append(symb)
    s.rules.append(r)
    lyr = mapnik2.Layer("Places", "+proj=latlon +datum=WGS84")
    lyr.datasource = places_ds
    lyr.styles.append("places_labels")
    # latlon bounding box corners
    ul_lonlat = mapnik2.Coord(142.30, -38.20)
    lr_lonlat = mapnik2.Coord(143.40, -38.80)
    # render for different projections
    projs = {
        "latlon": "+proj=latlon +datum=WGS84",
        "merc": "+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs",
        "google": "+proj=merc +ellps=sphere +R=6378137 +a=6378137 +units=m",
        "utm": "+proj=utm +zone=54 +datum=WGS84",
    }
    from cairo import SVGSurface

    for projdescr in projs.iterkeys():
        m = mapnik2.Map(1000, 500, projs[projdescr])
        m.append_style("places_labels", s)
        m.layers.append(lyr)
        p = mapnik2.Projection(projs[projdescr])
        m.zoom_to_box(p.forward(mapnik2.Box2d(ul_lonlat, lr_lonlat)))
        # Render to SVG so that it can be checked how many points are there with string comparison
        import StringIO

        svg_memory_file = StringIO.StringIO()
        surface = SVGSurface(svg_memory_file, m.width, m.height)
        mapnik2.render(m, surface)
        surface.flush()
        surface.finish()
        svg = svg_memory_file.getvalue()
        svg_memory_file.close()
        num_points_present = len(places_ds.all_features())
        num_points_rendered = svg.count("<image ")
        eq_(
            num_points_present,
            num_points_rendered,
            "Not all points were rendered (%d instead of %d) at projection %s"
            % (num_points_rendered, num_points_present, projdescr),
        )
Esempio n. 2
0
def test_render_points():
    # Test for effectivenes of ticket #402 (borderline points get lost on reprojection)
    raise Todo("See: http://trac.mapnik2.org/ticket/402")

    if not mapnik2.has_pycairo(): return

    # create and populate point datasource (WGS84 lat-lon coordinates)
    places_ds = mapnik2.PointDatasource()
    places_ds.add_point(142.48, -38.38, 'Name',
                        'Westernmost Point')  # westernmost
    places_ds.add_point(143.10, -38.60, 'Name',
                        'Southernmost Point')  # southernmost
    # create layer/rule/style
    s = mapnik2.Style()
    r = mapnik2.Rule()
    symb = mapnik2.PointSymbolizer()
    symb.allow_overlap = True
    r.symbols.append(symb)
    s.rules.append(r)
    lyr = mapnik2.Layer('Places', '+proj=latlon +datum=WGS84')
    lyr.datasource = places_ds
    lyr.styles.append('places_labels')
    # latlon bounding box corners
    ul_lonlat = mapnik2.Coord(142.30, -38.20)
    lr_lonlat = mapnik2.Coord(143.40, -38.80)
    # render for different projections
    projs = {
        'latlon': '+proj=latlon +datum=WGS84',
        'merc': '+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs',
        'google': '+proj=merc +ellps=sphere +R=6378137 +a=6378137 +units=m',
        'utm': '+proj=utm +zone=54 +datum=WGS84'
    }
    from cairo import SVGSurface
    for projdescr in projs.iterkeys():
        m = mapnik2.Map(1000, 500, projs[projdescr])
        m.append_style('places_labels', s)
        m.layers.append(lyr)
        p = mapnik2.Projection(projs[projdescr])
        m.zoom_to_box(p.forward(mapnik2.Box2d(ul_lonlat, lr_lonlat)))
        # Render to SVG so that it can be checked how many points are there with string comparison
        import StringIO
        svg_memory_file = StringIO.StringIO()
        surface = SVGSurface(svg_memory_file, m.width, m.height)
        mapnik2.render(m, surface)
        surface.flush()
        surface.finish()
        svg = svg_memory_file.getvalue()
        svg_memory_file.close()
        num_points_present = len(places_ds.all_features())
        num_points_rendered = svg.count('<image ')
        eq_(
            num_points_present, num_points_rendered,
            "Not all points were rendered (%d instead of %d) at projection %s"
            % (num_points_rendered, num_points_present, projdescr))
Esempio n. 3
0
def _pycairo_surface(type,sym):
    if mapnik2.has_pycairo():
        import cairo
        test_cairo_file = 'test.%s' % type
        m = mapnik2.Map(256,256)
        mapnik2.load_map(m,'../data/good_maps/%s_symbolizer.xml' % sym)
        surface = getattr(cairo,'%sSurface' % type.upper())(test_cairo_file, m.width,m.height)
        mapnik2.render(m, surface)
        surface.finish()        
        
        if os.path.exists(test_cairo_file):
            os.remove(test_cairo_file)
            return True
        else:
            # Fail, the file wasn't written
            return False
Esempio n. 4
0
def _pycairo_surface(type, sym):
    if mapnik2.has_pycairo():
        import cairo
        test_cairo_file = 'test.%s' % type
        m = mapnik2.Map(256, 256)
        mapnik2.load_map(m, '../data/good_maps/%s_symbolizer.xml' % sym)
        surface = getattr(cairo, '%sSurface' % type.upper())(test_cairo_file,
                                                             m.width, m.height)
        mapnik2.render(m, surface)
        surface.finish()

        if os.path.exists(test_cairo_file):
            os.remove(test_cairo_file)
            return True
        else:
            # Fail, the file wasn't written
            return False
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)

    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())
Esempio n. 6
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)

    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())
Esempio n. 7
0
images_.append('demo256.png')

im.save('demo64_binary_transparency.png', 'png8:c=64:t=1')
images_.append('demo64_binary_transparency.png')

im.save('demo128_colors_hextree_no_alpha.png', 'png8:c=100:m=h:t=0')
images_.append('demo128_colors_hextree_no_alpha.png')

im.save('demo_high.jpg', 'jpeg100')
images_.append('demo_high.jpg')

im.save('demo_low.jpg', 'jpeg50')
images_.append('demo_low.jpg')

# Render cairo examples
if HAS_PYCAIRO_MODULE and mapnik2.has_pycairo():
    
    svg_surface = cairo.SVGSurface('demo.svg', m.width,m.height)
    mapnik2.render(m, svg_surface)
    svg_surface.finish()
    images_.append('demo.svg')

    pdf_surface = cairo.PDFSurface('demo.pdf', m.width,m.height)
    mapnik2.render(m, pdf_surface)
    images_.append('demo.pdf')
    pdf_surface.finish()

    postscript_surface = cairo.PSSurface('demo.ps', m.width,m.height)
    mapnik2.render(m, postscript_surface)
    images_.append('demo.ps')
    postscript_surface.finish()    
Esempio n. 8
0
images_.append('demo256.png')

im.save('demo64_binary_transparency.png', 'png8:c=64:t=1')
images_.append('demo64_binary_transparency.png')

im.save('demo128_colors_hextree_no_alpha.png', 'png8:c=100:m=h:t=0')
images_.append('demo128_colors_hextree_no_alpha.png')

im.save('demo_high.jpg', 'jpeg100')
images_.append('demo_high.jpg')

im.save('demo_low.jpg', 'jpeg50')
images_.append('demo_low.jpg')

# Render cairo examples
if HAS_PYCAIRO_MODULE and mapnik2.has_pycairo():

    svg_surface = cairo.SVGSurface('demo.svg', m.width, m.height)
    mapnik2.render(m, svg_surface)
    svg_surface.finish()
    images_.append('demo.svg')

    pdf_surface = cairo.PDFSurface('demo.pdf', m.width, m.height)
    mapnik2.render(m, pdf_surface)
    images_.append('demo.pdf')
    pdf_surface.finish()

    postscript_surface = cairo.PSSurface('demo.ps', m.width, m.height)
    mapnik2.render(m, postscript_surface)
    images_.append('demo.ps')
    postscript_surface.finish()