def test_shieldsymbolizer_modify(): s = mapnik.ShieldSymbolizer( mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../data/images/dummy.png')) # transform expression s.transform = "rotate(30+[a]) scale(2*[sx] [sy])" eq_(s.transform, "rotate((30+[a])) scale(2*[sx], [sy])")
def test_shieldsymbolizer_init(): s = mapnik.ShieldSymbolizer( mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.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(mapnik.Expression('[Field Name]'))) eq_(s.face_name, 'DejaVu Sans Bold') eq_(s.allow_overlap, False) eq_(s.fill, mapnik.Color('#000000')) eq_(s.force_odd_labels, False) eq_(s.halo_fill, mapnik.Color('rgb(255,255,255)')) eq_(s.halo_radius, 0) eq_(s.label_placement, mapnik.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, mapnik.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, mapnik.text_transform.NONE) eq_(s.line_spacing, 0) eq_(s.character_spacing, 0) # r1341 eq_(s.wrap_before, False) eq_(s.horizontal_alignment, mapnik.horizontal_alignment.MIDDLE) eq_(s.justify_alignment, mapnik.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.mapnik.org/ticket/348") eq_(s.fontset, '')
def test_shield_symbolizer_init(): s = mapnik.ShieldSymbolizer( mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../data/images/dummy.png')) eq_(s.comp_op, mapnik.CompositeOp.src_over) eq_(s.clip, True) 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]'))) name field is no longer supported eq_(s.face_name, 'DejaVu Sans Bold') eq_(s.allow_overlap, False) eq_(s.fill, mapnik.Color('#000000')) eq_(s.force_odd_labels, False) eq_(s.halo_fill, mapnik.Color('rgb(255,255,255)')) eq_(s.halo_radius, 0) eq_(s.label_placement, mapnik.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, mapnik.vertical_alignment.AUTO) 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, mapnik.text_transform.NONE) eq_(s.line_spacing, 0) eq_(s.character_spacing, 0) # r1341 eq_(s.wrap_before, False) eq_(s.horizontal_alignment, mapnik.horizontal_alignment.AUTO) eq_(s.justify_alignment, mapnik.justify_alignment.AUTO) 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') # 11c34b1: default transform list is empty, not identity matrix eq_(s.transform, '') eq_(s.fontset, None)
def shield(): symbolizer = mapnik.ShieldSymbolizer(mapnik.Expression('[ref]'), 'DejaVu Sans Book', 8, mapnik.Color('black'), mapnik.PathExpression(BASE_PATH + '../shields/motorway_shield4.png')) # symbolizer.filename = file # symbolizer.allow_overlap = True # if color is not None: # symbolizer.fill = color # if transform is not None: # symbolizer.transform = transform symbolizer.min_distance = 300 return symbolizer
def test_shield_symbolizer_modify(): s = mapnik.ShieldSymbolizer(mapnik.Expression('[Field Name]'), 'DejaVu Sans Bold', 6, mapnik.Color('#000000'), mapnik.PathExpression('../data/images/dummy.png')) # transform expression def check_transform(expr, expect_str=None): s.transform = expr eq_(s.transform, expr if expect_str is None else expect_str) check_transform("matrix(1 2 3 4 5 6)", "matrix(1, 2, 3, 4, 5, 6)") check_transform("matrix(1, 2, 3, 4, 5, 6 +7)", "matrix(1, 2, 3, 4, 5, (6+7))") check_transform("rotate([a])") check_transform("rotate([a] -2)", "rotate(([a]-2))") check_transform("rotate([a] -2 -3)", "rotate([a], -2, -3)") check_transform("rotate([a] -2 -3 -4)", "rotate(((([a]-2)-3)-4))") check_transform("rotate([a] -2, 3, 4)", "rotate(([a]-2), 3, 4)") check_transform("translate([tx]) rotate([a])") check_transform("scale([sx], [sy]/2)")
def to_mapnik(self): sym = mapnik.ShieldSymbolizer( self.name, self.face_name, self.size or 10, mapnik.Color(str(self.color)) if self.color else mapnik.Color('black'), self.file, self.type, self.width, self.height) sym.character_spacing = self.character_spacing or sym.character_spacing sym.line_spacing = self.line_spacing or sym.line_spacing sym.spacing = self.spacing or sym.line_spacing sym.minimum_distance = self.minimum_distance or sym.minimum_distance if self.fontset: sym.fontset = self.fontset.value return sym
def generateMap(tableName, minX, minY, maxX, maxY, mapWidth, mapHeight, hiliteExpr=None, points=None): extent = "{},{},{},{}".format(minX, minY, maxX, maxY) layer = mapnik.Layer("Layer") layer.datasource = mapnik.PostGIS(dbname="distal", table=tableName, user="******", password="******", extent=extent, geometry_field="outline", srid=4326) map = mapnik.Map(mapWidth, mapHeight, '+proj=longlat +datum=WGS84') map.background = mapnik.Color("#8080a0") style = mapnik.Style() rule = mapnik.Rule() if hiliteExpr != None: rule.filter = mapnik.Filter(hiliteExpr) rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color("#408000"))) rule.symbols.append( mapnik.LineSymbolizer(mapnik.Stroke(mapnik.Color("#000000"), 0.1))) style.rules.append(rule) rule = mapnik.Rule() rule.set_else(True) rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color("#a0a0a0"))) rule.symbols.append( mapnik.LineSymbolizer(mapnik.Stroke(mapnik.Color("#404040"), 0.1))) style.rules.append(rule) map.append_style("Map Style", style) layer.styles.append("Map Style") map.layers.append(layer) if points != None: memoryDatasource = mapnik.MemoryDatasource() context = mapnik.Context() context.push("name") next_id = 1 for long, lat, name in points: wkt = "POINT (%0.8f %0.8f)" % (long, lat) feature = mapnik.Feature(context, next_id) feature['name'] = name feature.add_geometries_from_wkt(wkt) next_id = next_id + 1 memoryDatasource.add_feature(feature) layer = mapnik.Layer("Points") layer.datasource = memoryDatasource style = mapnik.Style() rule = mapnik.Rule() pointImgFile = os.path.join(os.path.dirname(__file__), "point.png") shield = mapnik.ShieldSymbolizer(mapnik.Expression('[name]'), "DejaVu Sans Bold", 10, mapnik.Color("#000000"), mapnik.PathExpression(pointImgFile)) shield.displacement = (0, 7) shield.unlock_image = True rule.symbols.append(shield) style.rules.append(rule) map.append_style("Point Style", style) layer.styles.append("Point Style") map.layers.append(layer) map.zoom_to_box(mapnik.Envelope(minX, minY, maxX, maxY)) scriptDir = os.path.dirname(__file__) cacheDir = os.path.join(scriptDir, "..", "mapCache") if not os.path.exists(cacheDir): os.mkdir(cacheDir) fd, filename = tempfile.mkstemp(".png", dir=cacheDir) os.close(fd) mapnik.render_to_file(map, filename, "png") return "../mapCache/" + os.path.basename(filename)