Beispiel #1
0
def test_shieldsymbolizer_init():
    s = mapnik2.ShieldSymbolizer(
        mapnik2.Expression('[Field Name]'), 'DejaVu Sans Bold', 6,
        mapnik2.Color('#000000'),
        mapnik2.PathExpression('../data/images/dummy.png'))
    eq_(s.anchor, (
        0.0,
        0.5,
    ))
    eq_(s.displacement, (0.0, 0.0))
    eq_(s.allow_overlap, False)
    eq_(s.avoid_edges, False)
    eq_(s.character_spacing, 0)
    eq_(str(s.name), str(mapnik2.Expression('[Field Name]')))
    eq_(s.face_name, 'DejaVu Sans Bold')
    eq_(s.allow_overlap, False)
    eq_(s.fill, mapnik2.Color('#000000'))
    eq_(s.force_odd_labels, False)
    eq_(s.halo_fill, mapnik2.Color('rgb(255,255,255)'))
    eq_(s.halo_radius, 0)
    eq_(s.label_placement, mapnik2.label_placement.POINT_PLACEMENT)
    eq_(s.minimum_distance, 0.0)
    eq_(s.text_ratio, 0)
    eq_(s.text_size, 6)
    eq_(s.wrap_width, 0)
    eq_(s.vertical_alignment, mapnik2.vertical_alignment.MIDDLE)
    eq_(s.label_spacing, 0)
    eq_(s.label_position_tolerance, 0)
    # 22.5 * M_PI/180.0 initialized by default
    assert_almost_equal(s.max_char_angle_delta, 0.39269908169872414)

    eq_(s.wrap_character, ' ')
    eq_(s.text_transform, mapnik2.text_transform.NONE)
    eq_(s.line_spacing, 0)
    eq_(s.character_spacing, 0)

    # r1341
    eq_(s.wrap_before, False)
    eq_(s.horizontal_alignment, mapnik2.horizontal_alignment.MIDDLE)
    eq_(s.justify_alignment, mapnik2.justify_alignment.MIDDLE)
    eq_(s.opacity, 1.0)

    # r2300
    eq_(s.minimum_padding, 0.0)

    # was mixed with s.opacity
    eq_(s.text_opacity, 1.0)

    eq_(s.shield_displacement, (0.0, 0.0))
    # TODO - the pattern in bindings seems to be to get/set
    # strings for PathExpressions... should we pass objects?
    eq_(s.filename, '../data/images/dummy.png')

    eq_(s.transform, 'matrix(1, 0, 0, 1, 0, 0)')

    raise Todo(
        "FontSet pickling support needed: http://trac.mapnik2.org/ticket/348")
    eq_(s.fontset, '')
Beispiel #2
0
def test_pointsymbolizer_pickle():
    raise Todo("point_symbolizer pickling currently disabled")
    p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/dummy.png"))
    p2 = pickle.loads(pickle.dumps(p,pickle.HIGHEST_PROTOCOL))
    # image type, width, and height only used in contructor...
    eq_(p.filename, p2.filename)
    eq_(p.allow_overlap, p2.allow_overlap)
    eq_(p.opacity, p2.opacity)
    eq_(p.ignore_placement, p2.ignore_placement)
    eq_(p.placement, p2.placement)
Beispiel #3
0
def test_introspect_symbolizers():
    # create a symbolizer
    p = mapnik2.PointSymbolizer(
        mapnik2.PathExpression("../data/images/dummy.png"))
    p.allow_overlap = True
    p.opacity = 0.5

    eq_(p.allow_overlap, True)
    eq_(p.opacity, 0.5)
    eq_(p.filename, '../data/images/dummy.png')

    # make sure the defaults
    # are what we think they are
    eq_(p.allow_overlap, True)
    eq_(p.opacity, 0.5)
    eq_(p.filename, '../data/images/dummy.png')

    # contruct objects to hold it
    r = mapnik2.Rule()
    r.symbols.append(p)
    s = mapnik2.Style()
    s.rules.append(r)
    m = mapnik2.Map(0, 0)
    m.append_style('s', s)

    # try to figure out what is
    # in the map and make sure
    # style is there and the same

    s2 = m.find_style('s')
    rules = s2.rules
    eq_(len(rules), 1)
    r2 = rules[0]
    syms = r2.symbols
    eq_(len(syms), 1)

    ## TODO here, we can do...
    sym = syms[0]
    # this is hackish at best
    p2 = sym.symbol()
    assert isinstance(p2, mapnik2.PointSymbolizer)

    eq_(p2.allow_overlap, True)
    eq_(p2.opacity, 0.5)
    eq_(p2.filename, '../data/images/dummy.png')

    ## but we need to be able to do:
    p2 = syms[0]  # get the actual symbolizer, not the variant object
    # this will throw for now...
    assert isinstance(p2, mapnik2.PointSymbolizer)

    eq_(p2.allow_overlap, True)
    eq_(p2.opacity, 0.5)
    eq_(p2.filename, '../data/images/dummy.png')
Beispiel #4
0
def test_pointsymbolizer_init():
    p = mapnik2.PointSymbolizer() 
    eq_(p.allow_overlap, False)
    eq_(p.opacity,1)
    eq_(p.filename,'')
    eq_(p.ignore_placement,False)
    eq_(p.placement, mapnik2.point_placement.CENTROID)

    p = mapnik2.PointSymbolizer(mapnik2.PathExpression("../data/images/dummy.png"))
    p.allow_overlap = True
    p.opacity = 0.5
    p.ignore_placement = True
    p.placement = mapnik2.point_placement.INTERIOR
    eq_(p.allow_overlap, True)
    eq_(p.opacity, 0.5)
    eq_(p.filename,'../data/images/dummy.png')
    eq_(p.ignore_placement,True)
    eq_(p.placement, mapnik2.point_placement.INTERIOR)
Beispiel #5
0
###

# style object to hold rules
s = mapnik2.Style()

# rule object to hold symbolizers
r = mapnik2.Rule()

# Lines (outlines of polygons and/or simple lines. Line-Color (RGB) line-thickness
#polygon_symbolizer = mapnik2.PolygonSymbolizer(mapnik2.Color('red')) #rgb(5%,5%,5%)
# add the polygon_symbolizer to the rule object
#r.symbols.append(polygon_symbolizer)

# Point Style. Path to marker.png
point_symbolizer = mapnik2.PointSymbolizer(
    mapnik2.PathExpression(point_marker))

# Allow Overlaps and set opacity of marker
point_symbolizer.allow_overlap = True
point_symbolizer.opacity = 0.7

# add the point_symbolizer to the rule object
r.symbols.append(point_symbolizer)

# now add the rule(s) to the style
s.rules.append(r)

# Styles are added to the map
m.append_style('My Style', s)

# Projection from PostGIS-Layer-Data
###
### START Layer 1
###

# style object to hold rules
s = mapnik2.Style() 

# rule object to hold symbolizers
r = mapnik2.Rule() 
r2 = mapnik2.Rule() 

# Lines (outlines of polygons and/or simple lines. Line-Color (RGB) line-thickness
polygon_symbolizer = mapnik2.PolygonSymbolizer(mapnik2.Color('red')) #rgb(5%,5%,5%)

# Point Style. Path to marker.png
point_symbolizer = mapnik2.PointSymbolizer(mapnik2.PathExpression(point_marker) )

# Allow Overlaps and set opacity of marker
point_symbolizer.allow_overlap = True
point_symbolizer.opacity = 0.7


# add the polygon_symbolizer to the rule object
r.symbols.append(polygon_symbolizer) 
r2.symbols.append(point_symbolizer) 



# now add the rule(s) to the style
s.rules.append(r) 
s.rules.append(r2)